Skip to content

Commit 749f410

Browse files
committed
Added Provider to ImportConnector.
1 parent 1387955 commit 749f410

File tree

11 files changed

+56
-14
lines changed

11 files changed

+56
-14
lines changed

.github/workflows/CI.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@ jobs:
99
runs-on: ubuntu-latest
1010

1111
strategy:
12+
fail-fast: false
1213
matrix:
1314
php:
1415
- 7.3
1516
- 7.4
1617
- 8.0
18+
- 8.1
1719
dependencies:
1820
- hi
1921
- lo

composer.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
},
2121
"require-dev": {
2222
"amphp/phpunit-util": "^1.1",
23-
"infection/infection": ">=0.18,<1",
23+
"infection/infection": ">=0.18,<0.26",
2424
"justinrainbow/json-schema": "^5.2.10",
2525
"mockery/mockery": "^1.4.2",
2626
"phpunit/php-code-coverage": "^9.2.5",
27-
"phpunit/phpunit": "^9.5",
27+
"phpunit/phpunit": "^9.5.13",
2828
"thecodingmachine/safe": "^1.3.3"
2929
},
3030
"suggest" : {
@@ -46,6 +46,9 @@
4646
"mutation": "infection --configuration=test/infection.json"
4747
},
4848
"config": {
49-
"sort-packages": true
49+
"sort-packages": true,
50+
"allow-plugins": {
51+
"infection/extension-installer": false
52+
}
5053
}
5154
}

src/Connector/ImportConnector.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@
99
use ScriptFUSION\Porter\Connector\Recoverable\RecoverableException;
1010
use ScriptFUSION\Porter\Connector\Recoverable\RecoverableExceptionHandler;
1111
use ScriptFUSION\Porter\Connector\Recoverable\StatelessRecoverableExceptionHandler;
12+
use ScriptFUSION\Porter\Provider\AsyncProvider;
13+
use ScriptFUSION\Porter\Provider\Provider;
1214
use function Amp\call;
1315
use function Amp\Promise\all;
1416
use function ScriptFUSION\Retry\retry;
@@ -24,6 +26,8 @@
2426
*/
2527
final class ImportConnector implements ConnectorWrapper
2628
{
29+
private $provider;
30+
2731
private $connector;
2832

2933
/**
@@ -45,6 +49,7 @@ final class ImportConnector implements ConnectorWrapper
4549
private $throttle;
4650

4751
/**
52+
* @param Provider|AsyncProvider $provider Provider.
4853
* @param Connector|AsyncConnector $connector Wrapped connector.
4954
* @param RecoverableExceptionHandler $recoverableExceptionHandler User's recoverable exception handler.
5055
* @param int $maxFetchAttempts Maximum fetch attempts.
@@ -53,6 +58,7 @@ final class ImportConnector implements ConnectorWrapper
5358
* for synchronous imports only.
5459
*/
5560
public function __construct(
61+
$provider,
5662
$connector,
5763
RecoverableExceptionHandler $recoverableExceptionHandler,
5864
int $maxFetchAttempts,
@@ -63,6 +69,7 @@ public function __construct(
6369
throw CacheUnavailableException::createUnsupported();
6470
}
6571

72+
$this->provider = $provider;
6673
$this->connector = clone (
6774
$connector instanceof CachingConnector && !$mustCache
6875
// Bypass cache when not required.
@@ -174,6 +181,16 @@ private static function invokeHandler(
174181
return $handler($recoverableException);
175182
}
176183

184+
/**
185+
* Gets the provider owning the resource being imported.
186+
*
187+
* @return AsyncProvider|Provider
188+
*/
189+
public function getProvider()
190+
{
191+
return $this->provider;
192+
}
193+
177194
/**
178195
* Gets the wrapped connector.
179196
*

src/Connector/ImportConnectorFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
namespace ScriptFUSION\Porter\Connector;
55

66
use ScriptFUSION\Async\Throttle\NullThrottle;
7+
use ScriptFUSION\Porter\Provider\AsyncProvider;
8+
use ScriptFUSION\Porter\Provider\Provider;
79
use ScriptFUSION\Porter\Specification\AsyncImportSpecification;
810
use ScriptFUSION\Porter\Specification\Specification;
911
use ScriptFUSION\StaticClass;
@@ -16,12 +18,13 @@ final class ImportConnectorFactory
1618
use StaticClass;
1719

1820
/**
21+
* @param Provider|AsyncProvider $provider
1922
* @param Connector|AsyncConnector $connector
2023
* @param Specification $specification
2124
*
2225
* @return ImportConnector
2326
*/
24-
public static function create($connector, Specification $specification): ImportConnector
27+
public static function create($provider, $connector, Specification $specification): ImportConnector
2528
{
2629
if ($specification instanceof AsyncImportSpecification) {
2730
$throttle = $specification->getThrottle();
@@ -32,6 +35,7 @@ public static function create($connector, Specification $specification): ImportC
3235
}
3336

3437
return new ImportConnector(
38+
$provider,
3539
$connector,
3640
$specification->getRecoverableExceptionHandler(),
3741
$specification->getMaxFetchAttempts(),

src/Porter.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,9 @@ private function fetch(ImportSpecification $specification): PorterRecords
120120
));
121121
}
122122

123-
$records = $resource->fetch(ImportConnectorFactory::create($provider->getConnector(), $specification));
123+
$records = $resource->fetch(
124+
ImportConnectorFactory::create($provider, $provider->getConnector(), $specification)
125+
);
124126

125127
if (!$records instanceof ProviderRecords) {
126128
$records = $this->createProviderRecords($records, $specification->getResource());
@@ -201,7 +203,7 @@ private function fetchAsync(AsyncImportSpecification $specification): AsyncPorte
201203
}
202204

203205
$records = $resource->fetchAsync(
204-
ImportConnectorFactory::create($provider->getAsyncConnector(), $specification)
206+
ImportConnectorFactory::create($provider, $provider->getAsyncConnector(), $specification)
205207
);
206208

207209
if (!$records instanceof AsyncProviderRecords) {

src/Provider/Resource/AsyncResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ interface AsyncResource
1919
public function getProviderClassName(): string;
2020

2121
/**
22-
* Fetches data using the the specified connector and presents its data as an enumerable series.
22+
* Fetches data using the specified connector and presents its data as an enumerable series.
2323
*
2424
* @param ImportConnector $connector Connector.
2525
*

src/Provider/Resource/ProviderResource.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface ProviderResource
1818
public function getProviderClassName(): string;
1919

2020
/**
21-
* Fetches data using the the specified connector and presents it as an iterable series.
21+
* Fetches data using the specified connector and presents it as an iterable series.
2222
*
2323
* @param ImportConnector $connector Connector.
2424
*

test/FixtureFactory.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use ScriptFUSION\Porter\Connector\Connector;
77
use ScriptFUSION\Porter\Connector\ImportConnector;
88
use ScriptFUSION\Porter\Connector\Recoverable\RecoverableExceptionHandler;
9+
use ScriptFUSION\Porter\Provider\Provider;
910
use ScriptFUSION\Porter\Specification\ImportSpecification;
1011
use ScriptFUSION\StaticClass;
1112

@@ -17,9 +18,11 @@ public static function buildImportConnector(
1718
Connector $connector,
1819
RecoverableExceptionHandler $recoverableExceptionHandler = null,
1920
int $maxFetchAttempts = ImportSpecification::DEFAULT_FETCH_ATTEMPTS,
20-
bool $mustCache = false
21+
bool $mustCache = false,
22+
Provider $provider = null
2123
): ImportConnector {
2224
return new ImportConnector(
25+
$provider ?? \Mockery::mock(Provider::class),
2326
$connector,
2427
$recoverableExceptionHandler ?: \Mockery::spy(RecoverableExceptionHandler::class),
2528
$maxFetchAttempts,

test/Functional/ThrottlePrecedenceHierarchyTest.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,11 @@ public function testNonThrottledConnector(): \Generator
5050
$this->specificationThrottle->expects('await')->once()->andReturn(new Success());
5151
$this->connectorThrottle->expects('await')->never();
5252

53-
$connector = ImportConnectorFactory::create($this->provider->getAsyncConnector(), $this->specification);
53+
$connector = ImportConnectorFactory::create(
54+
$this->provider,
55+
$this->provider->getAsyncConnector(),
56+
$this->specification
57+
);
5458

5559
yield $connector->fetchAsync(\Mockery::mock(AsyncDataSource::class));
5660
}
@@ -64,7 +68,11 @@ public function testThrottledConnector(): \Generator
6468
$this->specificationThrottle->expects('await')->never();
6569
$this->connectorThrottle->expects('await')->once()->andReturn(new Success());
6670

67-
$connector = ImportConnectorFactory::create($this->mockThrottledConnector(), $this->specification);
71+
$connector = ImportConnectorFactory::create(
72+
$this->provider,
73+
$this->mockThrottledConnector(),
74+
$this->specification
75+
);
6876

6977
yield $connector->fetchAsync(\Mockery::mock(AsyncDataSource::class));
7078
}
@@ -79,7 +87,11 @@ public function testThrottledConnectorOverride(): \Generator
7987
$this->specificationThrottle->expects('await')->once()->andReturn(new Success());
8088
$this->connectorThrottle->expects('await')->never();
8189

82-
$connector = ImportConnectorFactory::create($this->mockThrottledConnector(), $this->specification);
90+
$connector = ImportConnectorFactory::create(
91+
$this->provider,
92+
$this->mockThrottledConnector(),
93+
$this->specification
94+
);
8395

8496
yield $connector->fetchAsync(\Mockery::mock(AsyncDataSource::class));
8597
}

test/Integration/PorterAsyncTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
use ScriptFUSION\Porter\Collection\AsyncRecordCollection;
1313
use ScriptFUSION\Porter\Collection\CountableAsyncPorterRecords;
1414
use ScriptFUSION\Porter\Collection\CountableAsyncProviderRecords;
15-
use ScriptFUSION\Porter\Collection\PorterRecords;
1615
use ScriptFUSION\Porter\ForeignResourceException;
1716
use ScriptFUSION\Porter\ImportException;
1817
use ScriptFUSION\Porter\IncompatibleProviderException;

0 commit comments

Comments
 (0)