66use Amp \Iterator ;
77use Amp \Loop ;
88use Amp \Producer ;
9+ use ScriptFUSION \Porter \ImportException ;
910use ScriptFUSION \Porter \Porter ;
1011use ScriptFUSION \Porter \Specification \AsyncImportSpecification ;
1112use ScriptFUSION \Porter \Transform \FilterTransformer ;
@@ -22,6 +23,9 @@ protected function setUp(): void
2223 $ this ->specification = new AsyncImportSpecification ($ this ->resource );
2324 }
2425
26+ /**
27+ * Tests that the full async import path, via connector, resource and provider, fetches a record correctly.
28+ */
2529 public function testImportAsync (): \Generator
2630 {
2731 $ records = $ this ->porter ->importAsync ($ this ->specification );
@@ -30,11 +34,25 @@ public function testImportAsync(): \Generator
3034 self ::assertSame (['foo ' ], $ records ->getCurrent ());
3135 }
3236
37+ /**
38+ * Tests that the full async import path, via connector, resource and provider, fetches one record correctly.
39+ */
3340 public function testImportOneAsync (): \Generator
3441 {
3542 self ::assertSame (['foo ' ], yield $ this ->porter ->importOneAsync ($ this ->specification ));
3643 }
3744
45+ /**
46+ * Tests that when importOne receives multiple records from a resource, an exception is thrown.
47+ */
48+ public function testImportOneOfManyAsync (): \Generator
49+ {
50+ $ this ->resource ->shouldReceive ('fetchAsync ' )->andReturn (Iterator \fromIterable ([['foo ' ], ['bar ' ]]));
51+
52+ $ this ->expectException (ImportException::class);
53+ yield $ this ->porter ->importOneAsync ($ this ->specification );
54+ }
55+
3856 /**
3957 * Tests that a stack of async filter transformers are applied correctly.
4058 * The order is deterministic because filters yield immediately.
0 commit comments