@@ -66,7 +66,6 @@ public function testWithMapReturnsNewMapWithMergedKeys(): void
6666 self ::assertNotSame ($ map2 , $ merged );
6767 }
6868
69- public function testItRemovesKeyViaWithout(): void
7069 public function testWithoutCalledWithNoKeysReturnsSameMap (): void
7170 {
7271 $ map = TypedMap::one (Keys::A, 123 );
@@ -76,6 +75,7 @@ public function testWithoutCalledWithNoKeysReturnsSameMap(): void
7675 self ::assertSame ($ map , $ newMap );
7776 }
7877
78+ public function testWithoutReturnsNewMapWithoutKeys (): void
7979 {
8080 $ map = TypedMap::one (Keys::A, 123 );
8181 $ initialMapCopy = clone $ map ;
@@ -107,6 +107,18 @@ public function testMapCount(): void
107107 self ::assertCount (1 , $ map2 );
108108 }
109109
110+ public function testToPairs (): void
111+ {
112+ $ map = TypedMap::one (Keys::A, 1 )->with (Keys::B, 'a ' );
113+
114+ $ pairs = $ map ->toPairs ();
115+
116+ self ::assertEquals (
117+ [new Pair (Keys::A, 1 ), new Pair (Keys::B, 'a ' )],
118+ $ pairs ,
119+ );
120+ }
121+
110122 public function testOffsetSetThrows (): void
111123 {
112124 $ map = new TypedMap ();
@@ -125,7 +137,7 @@ public function testOffsetUnsetThrows(): void
125137 unset($ map [Keys::A]);
126138 }
127139
128- public function testItDeserializesCorrectly (): void
140+ public function testItUnserializesCorrectly (): void
129141 {
130142 $ map = TypedMap::one (Keys::A, 'a ' )->with (Keys::B, new \stdClass ());
131143
@@ -143,4 +155,22 @@ public function testSerializedRepresentationDoesNotChange(): void
143155 serialize ($ map ),
144156 );
145157 }
158+
159+ public function testUnserializeThrowsIfKeyIsNotUnserializable (): void
160+ {
161+ $ map = new TypedMap ();
162+
163+ $ this ->expectExceptionObject (new \LogicException ("Failed to unserialize key `''` " ));
164+
165+ $ map ->__unserialize (['' => 1 ]);
166+ }
167+
168+ public function testUnserializeChecksKey (): void
169+ {
170+ $ map = new TypedMap ();
171+
172+ $ this ->expectExceptionObject (new \LogicException ("Expected unserialized key to be an instance of `Typhoon \\TypedMap \\Key`, got: `''` " ));
173+
174+ $ map ->__unserialize ([serialize ('' ) => 1 ]);
175+ }
146176}
0 commit comments