Skip to content

Commit 441b309

Browse files
committed
Added tests for more Porter::fetchAsync() exception states.
1 parent c58f183 commit 441b309

3 files changed

Lines changed: 30 additions & 2 deletions

File tree

test/Integration/Porter/PorterAsyncTest.php

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,16 @@
66
use Amp\Iterator;
77
use Amp\Loop;
88
use Amp\Producer;
9+
use ScriptFUSION\Porter\Connector\AsyncConnector;
10+
use ScriptFUSION\Porter\Connector\ConnectorOptions;
11+
use ScriptFUSION\Porter\ForeignResourceException;
912
use ScriptFUSION\Porter\ImportException;
1013
use ScriptFUSION\Porter\IncompatibleProviderException;
1114
use ScriptFUSION\Porter\Porter;
12-
use ScriptFUSION\Porter\Provider\AsyncProvider;
1315
use ScriptFUSION\Porter\Provider\Provider;
1416
use ScriptFUSION\Porter\Specification\AsyncImportSpecification;
1517
use ScriptFUSION\Porter\Transform\FilterTransformer;
18+
use ScriptFUSIONTest\MockFactory;
1619

1720
/**
1821
* @see Porter
@@ -67,6 +70,30 @@ public function testImportIncompatibleProvider(): \Generator
6770
yield $this->porter->importAsync($this->specification->setProviderName($providerName));
6871
}
6972

73+
/**
74+
* Tests that when a resource's provider class name does not match the provider an exception is thrown.
75+
*/
76+
public function testImportForeignResource(): \Generator
77+
{
78+
// Replace existing provider with a different one.
79+
$this->registerProvider(MockFactory::mockProvider(), \get_class($this->provider));
80+
81+
$this->expectException(ForeignResourceException::class);
82+
yield $this->porter->importAsync($this->specification);
83+
}
84+
85+
/**
86+
* Tests that when importing using a connector that exports options, but no clone method, an exception is thrown.
87+
*/
88+
public function testImportConnectorWithOptions(): void
89+
{
90+
$this->provider->shouldReceive('getAsyncConnector')
91+
->andReturn(\Mockery::mock(AsyncConnector::class, ConnectorOptions::class));
92+
93+
$this->expectException(\LogicException::class);
94+
$this->porter->importAsync($this->specification);
95+
}
96+
7097
/**
7198
* Tests that a stack of async filter transformers are applied correctly.
7299
* The order is deterministic because filters yield immediately.

test/Integration/Porter/PorterSyncTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ public function testImportCustomProviderName(): void
131131
}
132132

133133
/**
134-
* Tests that when a resource does not return an iterator, ImportException is thrown.
134+
* Tests that when a resource does not return an iterator, an exception is thrown.
135135
*/
136136
public function testImportFailure(): void
137137
{

test/MockFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ public static function mockProvider()
4343
->andReturn(new Delayed(0, 'foo'))
4444
->getMock()
4545
)
46+
->byDefault()
4647
->getMock()
4748
;
4849
}

0 commit comments

Comments
 (0)