Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions src/Porter.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ public function import(ImportSpecification $specification)

$records = $this->fetch(
$specification->getResource(),
$specification->getProviderTag(),
$specification->getCacheAdvice(),
$specification->getMaxFetchAttempts(),
$specification->getFetchExceptionHandler()
Expand Down Expand Up @@ -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);

Expand Down
35 changes: 0 additions & 35 deletions src/Provider/Resource/AbstractResource.php

This file was deleted.

7 changes: 0 additions & 7 deletions src/Provider/Resource/ProviderResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
29 changes: 29 additions & 0 deletions src/Specification/ImportSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ class ImportSpecification
*/
private $resource;

/**
* @var string
*/
private $providerTag;

/**
* @var Transformer[]
*/
Expand Down Expand Up @@ -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[]
*/
Expand Down
9 changes: 3 additions & 6 deletions test/Integration/Porter/PorterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
Expand Down
8 changes: 0 additions & 8 deletions test/MockFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand All @@ -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();
}
Expand Down
7 changes: 6 additions & 1 deletion test/Unit/Porter/ImportSpecificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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()
Expand Down
18 changes: 0 additions & 18 deletions test/Unit/Porter/Provider/Resource/AbstractResourceTest.php

This file was deleted.