44namespace ScriptFUSIONTest \Integration ;
55
66use ScriptFUSION \Porter \Cache \CacheUnavailableException ;
7+ use ScriptFUSION \Porter \CloneNotImplementedException ;
78use ScriptFUSION \Porter \Collection \CountablePorterRecords ;
89use ScriptFUSION \Porter \Collection \FilteredRecords ;
910use ScriptFUSION \Porter \Collection \PorterRecords ;
@@ -90,10 +91,28 @@ public function testImportConnectorWithOptions(): void
9091 $ this ->provider ->shouldReceive ('getConnector ' )
9192 ->andReturn (\Mockery::mock (Connector::class, ConnectorOptions::class));
9293
93- $ this ->expectException (\LogicException ::class);
94+ $ this ->expectException (CloneNotImplementedException ::class);
9495 $ this ->porter ->import ($ this ->specification );
9596 }
9697
98+ /**
99+ * Tests that when importing multiple records, records may be rewound when the iterator supports this.
100+ */
101+ public function testRewind (): void
102+ {
103+ $ this ->resource ->shouldReceive ('fetch ' )->andReturn (new \ArrayIterator ([$ i1 = ['foo ' ], $ i2 = ['bar ' ]]));
104+
105+ $ records = $ this ->porter ->import ($ this ->specification );
106+
107+ self ::assertTrue ($ records ->valid ());
108+ self ::assertCount (2 , $ records );
109+ self ::assertSame ($ i1 , $ records ->current ());
110+ $ records ->next ();
111+ self ::assertSame ($ i2 , $ records ->current ());
112+ $ records ->rewind ();
113+ self ::assertSame ($ i1 , $ records ->current ());
114+ }
115+
97116 /**
98117 * Tests that when a Transformer is PorterAware it receives the Porter instance that invoked it.
99118 */
@@ -146,8 +165,10 @@ public function testImportFailure(): void
146165 public function testImportUnregisteredProvider (): void
147166 {
148167 $ this ->expectException (ProviderNotFoundException::class);
168+ $ this ->expectExceptionMessage ($ providerName = 'foo ' );
169+ $ this ->expectExceptionCode (0 );
149170
150- $ this ->porter ->import ($ this ->specification ->setProviderName (' foo ' ));
171+ $ this ->porter ->import ($ this ->specification ->setProviderName ("\" $ providerName \"" ));
151172 }
152173
153174 /**
@@ -158,6 +179,7 @@ public function testImportIncompatibleProvider(): void
158179 $ this ->registerProvider (\Mockery::mock (AsyncProvider::class), $ providerName = 'foo ' );
159180
160181 $ this ->expectException (IncompatibleProviderException::class);
182+ $ this ->expectExceptionMessageRegExp ('[\bProvider\b] ' );
161183 $ this ->porter ->import ($ this ->specification ->setProviderName ($ providerName ));
162184 }
163185
0 commit comments