Skip to content

Commit

Permalink
Added AbstractResource and accompanying test.
Browse files Browse the repository at this point in the history
Renamed ProviderResource -> Resource.
  • Loading branch information
Bilge committed Aug 11, 2016
1 parent 22a667d commit 2f63f16
Show file tree
Hide file tree
Showing 17 changed files with 93 additions and 37 deletions.
6 changes: 3 additions & 3 deletions src/Porter/Collection/CountableProviderRecords.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace ScriptFUSION\Porter\Collection;

use ScriptFUSION\Porter\Provider\Resource\ProviderResource;
use ScriptFUSION\Porter\Provider\Resource\Resource;

class CountableProviderRecords extends ProviderRecords implements \Countable
{
Expand All @@ -10,9 +10,9 @@ class CountableProviderRecords extends ProviderRecords implements \Countable
/**
* @param \Iterator $providerRecords
* @param int $count
* @param ProviderResource $resource
* @param Resource $resource
*/
public function __construct(\Iterator $providerRecords, $count, ProviderResource $resource)
public function __construct(\Iterator $providerRecords, $count, Resource $resource)
{
parent::__construct($providerRecords, $resource);

Expand Down
6 changes: 3 additions & 3 deletions src/Porter/Collection/ProviderRecords.php
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
<?php
namespace ScriptFUSION\Porter\Collection;

use ScriptFUSION\Porter\Provider\Resource\ProviderResource;
use ScriptFUSION\Porter\Provider\Resource\Resource;

class ProviderRecords extends RecordCollection
{
private $resource;

public function __construct(\Iterator $providerRecords, ProviderResource $resource)
public function __construct(\Iterator $providerRecords, Resource $resource)
{
parent::__construct($providerRecords);

$this->resource = $resource;
}

/**
* @return ProviderResource
* @return Resource
*/
public function getResource()
{
Expand Down
3 changes: 3 additions & 0 deletions src/Porter/Net/Soap/SoapOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@

use ScriptFUSION\Porter\Options\EncapsulatedOptions;

/**
* TODO. Add missing SOAP context option accessors and mutators.
*/
final class SoapOptions extends EncapsulatedOptions
{
public function __construct()
Expand Down
4 changes: 2 additions & 2 deletions src/Porter/Porter.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
use ScriptFUSION\Porter\Provider\ObjectNotCreatedException;
use ScriptFUSION\Porter\Provider\Provider;
use ScriptFUSION\Porter\Provider\ProviderFactory;
use ScriptFUSION\Porter\Provider\Resource\ProviderResource;
use ScriptFUSION\Porter\Provider\Resource\Resource;
use ScriptFUSION\Porter\Specification\ImportSpecification;

class Porter
Expand Down Expand Up @@ -71,7 +71,7 @@ private function createPorterRecords(RecordCollection $records, ImportSpecificat
return new PorterRecords($records, $specification);
}

private function fetch(ProviderResource $resource, CacheAdvice $cacheAdvice = null)
private function fetch(Resource $resource, CacheAdvice $cacheAdvice = null)
{
$provider = $this->getProvider($resource->getProviderClassName(), $resource->getProviderTag());
$this->applyCacheAdvice($provider, $cacheAdvice ?: $this->defaultCacheAdvice);
Expand Down
6 changes: 3 additions & 3 deletions src/Porter/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
use ScriptFUSION\Porter\Cache\CacheToggle;
use ScriptFUSION\Porter\Cache\CacheUnavailableException;
use ScriptFUSION\Porter\Connector\Connector;
use ScriptFUSION\Porter\Provider\Resource\ProviderResource;
use ScriptFUSION\Porter\Provider\Resource\Resource;

abstract class AbstractProvider implements Provider, CacheToggle
{
Expand All @@ -16,13 +16,13 @@ public function __construct(Connector $connector)
}

/**
* @param ProviderResource $resource
* @param Resource $resource
*
* @return \Iterator
*
* @throws ForeignResourceException A foreign resource was received.
*/
public function fetch(ProviderResource $resource)
public function fetch(Resource $resource)
{
if ($resource->getProviderClassName() !== static::class) {
throw new ForeignResourceException(sprintf(
Expand Down
6 changes: 3 additions & 3 deletions src/Porter/Provider/Provider.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
namespace ScriptFUSION\Porter\Provider;

use ScriptFUSION\Porter\Provider\Resource\ProviderResource;
use ScriptFUSION\Porter\Provider\Resource\Resource;

/**
* Provides a method for fetching data from a resource.
Expand All @@ -11,9 +11,9 @@ interface Provider
/**
* Fetches data from the specified resource.
*
* @param ProviderResource $resource Resource.
* @param Resource $resource Resource.
*
* @return \Iterator Enumerable data series.
*/
public function fetch(ProviderResource $resource);
public function fetch(Resource $resource);
}
35 changes: 35 additions & 0 deletions src/Porter/Provider/Resource/AbstractResource.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
namespace ScriptFUSION\Porter\Provider\Resource;

/**
* Partially implements Resource.
*/
abstract class AbstractResource implements Resource
{
/** @var string */
private $providerTag;

/**
* {@inheritdoc}
*
* @return string Provider tag.
*/
public function getProviderTag()
{
return $this->providerTag;
}

/**
* Sets the provider identifier tag.
*
* @param string $tag Provider tag.
*
* @return $this
*/
public function setProviderTag($tag)
{
$this->providerTag = "$tag";

return $this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
/**
* Defines methods for fetching data from a specific provider resource.
*/
interface ProviderResource
interface Resource
{
/**
* Gets the class name of the provider this resource belongs to.
Expand Down
2 changes: 1 addition & 1 deletion src/Porter/Provider/Resource/StaticResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
use ScriptFUSION\Porter\Options\EncapsulatedOptions;
use ScriptFUSION\Porter\Provider\StaticDataProvider;

class StaticResource implements ProviderResource
class StaticResource implements Resource
{
private $data;

Expand Down
8 changes: 4 additions & 4 deletions src/Porter/Specification/ImportSpecification.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

use ScriptFUSION\Mapper\Mapping;
use ScriptFUSION\Porter\Cache\CacheAdvice;
use ScriptFUSION\Porter\Provider\Resource\ProviderResource;
use ScriptFUSION\Porter\Provider\Resource\Resource;

class ImportSpecification
{
/** @var ProviderResource */
/** @var Resource */
private $resource;

/** @var Mapping */
Expand All @@ -22,7 +22,7 @@ class ImportSpecification
/** @var CacheAdvice */
private $cacheAdvice;

public function __construct(ProviderResource $resource)
public function __construct(Resource $resource)
{
$this->resource = $resource;
}
Expand All @@ -35,7 +35,7 @@ public function __clone()
}

/**
* @return ProviderResource
* @return Resource
*/
final public function getResource()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
namespace ScriptFUSIONTest\Integration\Porter\Collection;

use ScriptFUSION\Porter\Collection\CountableProviderRecords;
use ScriptFUSION\Porter\Provider\Resource\ProviderResource;
use ScriptFUSION\Porter\Provider\Resource\Resource;

final class CountableProviderRecordsTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -13,7 +13,7 @@ public function test()
$records = new CountableProviderRecords(
new \ArrayIterator($data),
count($data),
\Mockery::mock(ProviderResource::class)
\Mockery::mock(Resource::class)
);

self::assertCount(count($data), $records);
Expand Down
4 changes: 2 additions & 2 deletions test/Integration/Porter/PorterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use ScriptFUSION\Porter\Collection\ProviderRecords;
use ScriptFUSION\Porter\Porter;
use ScriptFUSION\Porter\Provider\Provider;
use ScriptFUSION\Porter\Provider\Resource\ProviderResource;
use ScriptFUSION\Porter\Provider\Resource\Resource;
use ScriptFUSION\Porter\Provider\StaticDataProvider;
use ScriptFUSION\Porter\ProviderAlreadyRegisteredException;
use ScriptFUSION\Porter\ProviderNotFoundException;
Expand All @@ -34,7 +34,7 @@ final class PorterTest extends \PHPUnit_Framework_TestCase
/** @var Provider|MockInterface */
private $provider;

/** @var ProviderResource */
/** @var Resource */
private $resource;

protected function setUp()
Expand Down
10 changes: 5 additions & 5 deletions test/MockFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,27 +3,27 @@

use Mockery\MockInterface;
use ScriptFUSION\Porter\Provider\Provider;
use ScriptFUSION\Porter\Provider\Resource\ProviderResource;
use ScriptFUSION\Porter\Provider\Resource\Resource;
use ScriptFUSION\Porter\Specification\ImportSpecification;
use ScriptFUSION\StaticClass;

final class MockFactory
{
use StaticClass;

public static function mockImportSpecification(ProviderResource $resource = null)
public static function mockImportSpecification(Resource $resource = null)
{
return \Mockery::mock(ImportSpecification::class, [$resource ?: \Mockery::mock(ProviderResource::class)]);
return \Mockery::mock(ImportSpecification::class, [$resource ?: \Mockery::mock(Resource::class)]);
}

/**
* @param Provider $provider
*
* @return MockInterface|ProviderResource
* @return MockInterface|Resource
*/
public static function mockResource(Provider $provider)
{
return \Mockery::spy(ProviderResource::class)
return \Mockery::spy(Resource::class)
->shouldReceive('getProviderClassName')
->andReturn(get_class($provider))
->getMock();
Expand Down
4 changes: 2 additions & 2 deletions test/Unit/Porter/Collection/ProviderRecordsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
namespace ScriptFUSIONTest\Unit\Porter\Collection;

use ScriptFUSION\Porter\Collection\ProviderRecords;
use ScriptFUSION\Porter\Provider\Resource\ProviderResource;
use ScriptFUSION\Porter\Provider\Resource\Resource;

final class ProviderRecordsTest extends \PHPUnit_Framework_TestCase
{
public function test()
{
$records = new ProviderRecords(
\Mockery::mock(\Iterator::class),
$resource = \Mockery::mock(ProviderResource::class)
$resource = \Mockery::mock(Resource::class)
);

self::assertSame($resource, $records->getResource());
Expand Down
6 changes: 3 additions & 3 deletions test/Unit/Porter/ImportSpecificationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@

use ScriptFUSION\Mapper\Mapping;
use ScriptFUSION\Porter\Cache\CacheAdvice;
use ScriptFUSION\Porter\Provider\Resource\ProviderResource;
use ScriptFUSION\Porter\Provider\Resource\Resource;
use ScriptFUSION\Porter\Specification\ImportSpecification;

final class ImportSpecificationTest extends \PHPUnit_Framework_TestCase
{
/** @var ImportSpecification */
private $specification;

/** @var ProviderResource */
/** @var Resource */
private $resource;

protected function setUp()
{
$this->specification = new ImportSpecification(
$this->resource = \Mockery::mock(ProviderResource::class)
$this->resource = \Mockery::mock(Resource::class)
);
}

Expand Down
6 changes: 3 additions & 3 deletions test/Unit/Porter/Provider/AbstractProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
use ScriptFUSION\Porter\Connector\Connector;
use ScriptFUSION\Porter\Provider\AbstractProvider;
use ScriptFUSION\Porter\Provider\ForeignResourceException;
use ScriptFUSION\Porter\Provider\Resource\ProviderResource;
use ScriptFUSION\Porter\Provider\Resource\Resource;

final class AbstractProviderTest extends \PHPUnit_Framework_TestCase
{
Expand Down Expand Up @@ -45,7 +45,7 @@ public function testFetch()
self::assertSame(
'foo',
$this->provider->fetch(
\Mockery::mock(ProviderResource::class)
\Mockery::mock(Resource::class)
->shouldReceive('fetch')
->with($this->connector)
->andReturn('foo')
Expand All @@ -62,7 +62,7 @@ public function testFetchForeignProvider()
$this->setExpectedException(ForeignResourceException::class);

$this->provider->fetch(
\Mockery::mock(ProviderResource::class)
\Mockery::mock(Resource::class)
->shouldReceive('getProviderClassName')
->andReturn('foo')
->getMock()
Expand Down
18 changes: 18 additions & 0 deletions test/Unit/Porter/Provider/Resource/AbstractResourceTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php
namespace ScriptFUSIONTest\Unit\Porter\Provider\Resource;

use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use ScriptFUSION\Porter\Provider\Resource\AbstractResource;

final class AbstractResourceTest extends \PHPUnit_Framework_TestCase
{
use MockeryPHPUnitIntegration;

public function testTag()
{
/** @var AbstractResource $abstractResource */
$abstractResource = \Mockery::mock(AbstractResource::class)->makePartial();

self::assertSame($tag = 'foo', $abstractResource->setProviderTag($tag)->getProviderTag());
}
}

0 comments on commit 2f63f16

Please sign in to comment.