From 950c942ed832cf91360b15ef816dacace2783871 Mon Sep 17 00:00:00 2001 From: Bilge Date: Fri, 17 Mar 2017 23:08:25 +0000 Subject: [PATCH] Moved provider tag from ProviderResource -> ImportSpecification. Removed AbstractResource. --- src/Porter.php | 12 +++++-- src/Provider/Resource/AbstractResource.php | 35 ------------------- src/Provider/Resource/ProviderResource.php | 7 ---- src/Specification/ImportSpecification.php | 29 +++++++++++++++ test/Integration/Porter/PorterTest.php | 9 ++--- test/MockFactory.php | 8 ----- test/Unit/Porter/ImportSpecificationTest.php | 7 +++- .../Resource/AbstractResourceTest.php | 18 ---------- 8 files changed, 47 insertions(+), 78 deletions(-) delete mode 100644 src/Provider/Resource/AbstractResource.php delete mode 100644 test/Unit/Porter/Provider/Resource/AbstractResourceTest.php diff --git a/src/Porter.php b/src/Porter.php index 961ecfd..feb6767 100644 --- a/src/Porter.php +++ b/src/Porter.php @@ -47,6 +47,7 @@ public function import(ImportSpecification $specification) $records = $this->fetch( $specification->getResource(), + $specification->getProviderTag(), $specification->getCacheAdvice(), $specification->getMaxFetchAttempts(), $specification->getFetchExceptionHandler() @@ -87,9 +88,14 @@ public function importOne(ImportSpecification $specification) return $one; } - private function fetch(ProviderResource $resource, CacheAdvice $cacheAdvice, $fetchAttempts, $fetchExceptionHandler) - { - $provider = $this->getProvider($resource->getProviderClassName(), $resource->getProviderTag()); + private function fetch( + ProviderResource $resource, + $providerTag, + CacheAdvice $cacheAdvice, + $fetchAttempts, + $fetchExceptionHandler + ) { + $provider = $this->getProvider($resource->getProviderClassName(), $providerTag); $this->applyCacheAdvice($provider, $cacheAdvice); diff --git a/src/Provider/Resource/AbstractResource.php b/src/Provider/Resource/AbstractResource.php deleted file mode 100644 index 3f02754..0000000 --- a/src/Provider/Resource/AbstractResource.php +++ /dev/null @@ -1,35 +0,0 @@ -providerTag; - } - - /** - * Sets the provider identifier tag. - * - * @param string $tag Provider tag. - * - * @return $this - */ - public function setProviderTag($tag) - { - $this->providerTag = "$tag"; - - return $this; - } -} diff --git a/src/Provider/Resource/ProviderResource.php b/src/Provider/Resource/ProviderResource.php index 6f9a338..423ba71 100644 --- a/src/Provider/Resource/ProviderResource.php +++ b/src/Provider/Resource/ProviderResource.php @@ -16,13 +16,6 @@ interface ProviderResource */ public function getProviderClassName(); - /** - * Gets the provider identifier tag. - * - * @return string|null Provider tag. - */ - public function getProviderTag(); - /** * Fetches data from the provider using the the specified connector and * presents its data as an enumerable series. diff --git a/src/Specification/ImportSpecification.php b/src/Specification/ImportSpecification.php index 8e4b738..ffe3fce 100644 --- a/src/Specification/ImportSpecification.php +++ b/src/Specification/ImportSpecification.php @@ -18,6 +18,11 @@ class ImportSpecification */ private $resource; + /** + * @var string + */ + private $providerTag; + /** * @var Transformer[] */ @@ -80,6 +85,30 @@ final public function getResource() return $this->resource; } + /** + * Gets the provider identifier tag. + * + * @return string Provider tag. + */ + final public function getProviderTag() + { + return $this->providerTag; + } + + /** + * Sets the provider identifier tag. + * + * @param string $tag Provider tag. + * + * @return $this + */ + final public function setProviderTag($tag) + { + $this->providerTag = "$tag"; + + return $this; + } + /** * @return Transformer[] */ diff --git a/test/Integration/Porter/PorterTest.php b/test/Integration/Porter/PorterTest.php index 3c1a1e6..bdf3df4 100644 --- a/test/Integration/Porter/PorterTest.php +++ b/test/Integration/Porter/PorterTest.php @@ -202,12 +202,9 @@ public function testImportTaggedResource() $tag = 'foo' ); - $records = $this->porter->import(MockFactory::mockImportSpecification( - MockFactory::mockResource($provider) - ->shouldReceive('getProviderTag') - ->andReturn($tag) - ->getMock() - )); + $records = $this->porter->import( + (new ImportSpecification(MockFactory::mockResource($provider)))->setProviderTag($tag) + ); self::assertSame($output, $records->current()); } diff --git a/test/MockFactory.php b/test/MockFactory.php index 3a723c3..f7f2a35 100644 --- a/test/MockFactory.php +++ b/test/MockFactory.php @@ -4,18 +4,12 @@ use Mockery\MockInterface; use ScriptFUSION\Porter\Provider\Provider; use ScriptFUSION\Porter\Provider\Resource\ProviderResource; -use ScriptFUSION\Porter\Specification\ImportSpecification; use ScriptFUSION\StaticClass; final class MockFactory { use StaticClass; - public static function mockImportSpecification(ProviderResource $resource = null) - { - return \Mockery::mock(ImportSpecification::class, [$resource ?: \Mockery::mock(ProviderResource::class)]); - } - /** * @param Provider $provider * @@ -26,8 +20,6 @@ public static function mockResource(Provider $provider) return \Mockery::mock(ProviderResource::class) ->shouldReceive('getProviderClassName') ->andReturn(get_class($provider)) - ->shouldReceive('getProviderTag') - ->andReturn(null) ->byDefault() ->getMock(); } diff --git a/test/Unit/Porter/ImportSpecificationTest.php b/test/Unit/Porter/ImportSpecificationTest.php index 14b1ebf..9a5302b 100644 --- a/test/Unit/Porter/ImportSpecificationTest.php +++ b/test/Unit/Porter/ImportSpecificationTest.php @@ -54,6 +54,11 @@ public function testProviderData() self::assertSame($this->resource, $this->specification->getResource()); } + public function testProviderTag() + { + self::assertSame($tag = 'foo', $this->specification->setProviderTag($tag)->getProviderTag()); + } + public function testAddTransformer() { self::assertEmpty($this->specification->getTransformers()); @@ -92,7 +97,7 @@ public function testAddSameTransformer() public function testContext() { - self::assertSame('foo', $this->specification->setContext('foo')->getContext()); + self::assertSame($context = 'foo', $this->specification->setContext($context)->getContext()); } public function testCacheAdvice() diff --git a/test/Unit/Porter/Provider/Resource/AbstractResourceTest.php b/test/Unit/Porter/Provider/Resource/AbstractResourceTest.php deleted file mode 100644 index 24b2132..0000000 --- a/test/Unit/Porter/Provider/Resource/AbstractResourceTest.php +++ /dev/null @@ -1,18 +0,0 @@ -makePartial(); - - self::assertSame($tag = 'foo', $abstractResource->setProviderTag($tag)->getProviderTag()); - } -}