diff --git a/composer.json b/composer.json index ac9a287..d563476 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,6 @@ "scriptfusion/static-class": "^1", "scriptfusion/retry": "^1.1", "scriptfusion/retry-exception-handlers": "^1", - "eloquent/enumeration": "^5", "psr/container": "^1", "psr/cache": "^1" }, diff --git a/src/Cache/Cache.php b/src/Cache/Cache.php deleted file mode 100644 index da2266d..0000000 --- a/src/Cache/Cache.php +++ /dev/null @@ -1,15 +0,0 @@ -connector = $connector; $this->cache = $cache ?: new MemoryCache; $this->cacheKeyGenerator = $cacheKeyGenerator ?: new JsonCacheKeyGenerator; } /** - * @param ConnectionContext $context * @param string $source * @param EncapsulatedOptions|null $options * @@ -43,73 +48,45 @@ public function __construct(CacheItemPoolInterface $cache = null, CacheKeyGenera */ public function fetch(ConnectionContext $context, $source, EncapsulatedOptions $options = null) { - if ($context->shouldCache()) { + if ($context->mustCache()) { $optionsCopy = $options ? $options->copy() : []; ksort($optionsCopy); - $key = $this->validateCacheKey($this->getCacheKeyGenerator()->generateCacheKey($source, $optionsCopy)); + $this->validateCacheKey($key = $this->cacheKeyGenerator->generateCacheKey($source, $optionsCopy)); if ($this->cache->hasItem($key)) { return $this->cache->getItem($key)->get(); } } - $data = $this->fetchFreshData($source, $options); + $data = $this->connector->fetch($context, $source, $options); isset($key) && $this->cache->save($this->cache->getItem($key)->set($data)); return $data; } - abstract public function fetchFreshData($source, EncapsulatedOptions $options = null); - - public function isCacheAvailable() - { - return true; - } - - public function getCache() - { - return $this->cache; - } - - public function setCache(CacheItemPoolInterface $cache) - { - $this->cache = $cache; - } - - public function getCacheKeyGenerator() - { - return $this->cacheKeyGenerator; - } - - public function setCacheKeyGenerator(CacheKeyGenerator $cacheKeyGenerator) - { - $this->cacheKeyGenerator = $cacheKeyGenerator; - } - /** * @param mixed $key * - * @return string + * @return void * * @throws InvalidCacheKeyException Cache key contains invalid data. */ private function validateCacheKey($key) { + // TODO: Remove when PHP 5 support dropped and replace with string hint. if (!is_string($key)) { throw new InvalidCacheKeyException('Cache key must be a string.'); } - if (strpbrk($key, self::RESERVED_CHARACTERS) !== false) { + if (strpbrk($key, CacheKeyGenerator::RESERVED_CHARACTERS) !== false) { throw new InvalidCacheKeyException(sprintf( 'Cache key "%s" contains one or more reserved characters: "%s".', $key, - self::RESERVED_CHARACTERS + CacheKeyGenerator::RESERVED_CHARACTERS )); } - - return $key; } } diff --git a/src/Connector/ConnectionContext.php b/src/Connector/ConnectionContext.php index 232ad64..cc3524e 100644 --- a/src/Connector/ConnectionContext.php +++ b/src/Connector/ConnectionContext.php @@ -1,23 +1,26 @@ cacheAdvice = $cacheAdvice; + $this->mustCache = (bool)$mustCache; $this->fetchExceptionHandler = $fetchExceptionHandler; $this->maxFetchAttempts = (int)$maxFetchAttempts; } + public function mustCache() + { + return $this->mustCache; + } + public function retry(callable $callable) { return \ScriptFUSION\Retry\retry( @@ -29,28 +32,9 @@ function (\Exception $exception) { throw $exception; } + // TODO Clone exception handler to avoid persisting state between calls. call_user_func($this->fetchExceptionHandler, $exception); } ); } - - /** - * Gets a value indicating whether a connector should cache data. - * - * @return bool True if the connector should cache data, otherwise false. - */ - public function shouldCache() - { - return $this->cacheAdvice->anyOf(CacheAdvice::SHOULD_CACHE(), CacheAdvice::MUST_CACHE()); - } - - /** - * Gets a value indicating whether a connector must support caching. - * - * @return bool True if connector must support caching, otherwise false. - */ - public function mustSupportCaching() - { - return $this->cacheAdvice->anyOf(CacheAdvice::MUST_CACHE(), CacheAdvice::MUST_NOT_CACHE()); - } } diff --git a/src/Connector/ConnectionContextFactory.php b/src/Connector/ConnectionContextFactory.php index eaaeb4a..320e01c 100644 --- a/src/Connector/ConnectionContextFactory.php +++ b/src/Connector/ConnectionContextFactory.php @@ -11,7 +11,7 @@ final class ConnectionContextFactory public static function create(ImportSpecification $specification) { return new ConnectionContext( - $specification->getCacheAdvice(), + $specification->mustCache(), $specification->getFetchExceptionHandler(), $specification->getMaxFetchAttempts() ); diff --git a/src/Connector/SuperConnector.php b/src/Connector/ImportConnector.php similarity index 53% rename from src/Connector/SuperConnector.php rename to src/Connector/ImportConnector.php index 24c4a1e..7fb2294 100644 --- a/src/Connector/SuperConnector.php +++ b/src/Connector/ImportConnector.php @@ -1,11 +1,16 @@ mustCache() && !$connector instanceof CachingConnector) { + throw CacheUnavailableException::createUnsupported(); + } + $this->connector = $connector; $this->context = $context; } public function fetch($source, EncapsulatedOptions $options = null) { - $this->validateCacheState(); - return $this->connector->fetch($this->context, $source, $options); } - - private function validateCacheState() - { - if ($this->context->mustSupportCaching()) { - if (!$this->connector instanceof Cache) { - throw CacheUnavailableException::unsupported(); - } - - if (!$this->connector->isCacheAvailable()) { - throw CacheUnavailableException::unavailable(); - } - } - } } diff --git a/src/Porter.php b/src/Porter.php index a87bdb7..e39baca 100644 --- a/src/Porter.php +++ b/src/Porter.php @@ -9,7 +9,7 @@ use ScriptFUSION\Porter\Collection\RecordCollection; use ScriptFUSION\Porter\Connector\ConnectionContext; use ScriptFUSION\Porter\Connector\ConnectionContextFactory; -use ScriptFUSION\Porter\Connector\SuperConnector; +use ScriptFUSION\Porter\Connector\ImportConnector; use ScriptFUSION\Porter\Provider\ForeignResourceException; use ScriptFUSION\Porter\Provider\ObjectNotCreatedException; use ScriptFUSION\Porter\Provider\Provider; @@ -20,17 +20,17 @@ use ScriptFUSION\Porter\Transform\Transformer; /** - * Imports data according to an ImportSpecification. + * Imports data according to an ImportSpecification from a provider in the container of providers or internal factory. */ class Porter { /** - * @var ContainerInterface + * @var ContainerInterface Container of user-defined providers. */ private $providers; /** - * @var ProviderFactory + * @var ProviderFactory Internal factory of first-party providers. */ private $providerFactory; @@ -110,7 +110,7 @@ private function fetch(ProviderResource $resource, $providerName, ConnectionCont } $records = $resource->fetch( - new SuperConnector($provider->getConnector(), $context), + new ImportConnector($provider->getConnector(), $context), $provider instanceof ProviderOptions ? clone $provider->getOptions() : null ); diff --git a/src/Provider/Resource/ProviderResource.php b/src/Provider/Resource/ProviderResource.php index 8d0eea2..a4fcc25 100644 --- a/src/Provider/Resource/ProviderResource.php +++ b/src/Provider/Resource/ProviderResource.php @@ -1,7 +1,7 @@ data; } diff --git a/src/Specification/ImportSpecification.php b/src/Specification/ImportSpecification.php index 09452f9..472f02b 100644 --- a/src/Specification/ImportSpecification.php +++ b/src/Specification/ImportSpecification.php @@ -1,7 +1,6 @@ resource = $resource; $this->clearTransformers(); - $this->defaultCacheAdvice = CacheAdvice::SHOULD_NOT_CACHE(); } public function __clone() @@ -98,13 +91,13 @@ final public function getProviderName() /** * Sets the provider name. * - * @param string $tag Provider name. + * @param string $providerName Provider name. * * @return $this */ - final public function setProviderName($tag) + final public function setProviderName($providerName) { - $this->providerName = "$tag"; + $this->providerName = "$providerName"; return $this; } @@ -189,21 +182,29 @@ final public function setContext($context) } /** - * @return CacheAdvice + * @return bool */ - final public function getCacheAdvice() + final public function mustCache() { - return $this->cacheAdvice ?: $this->defaultCacheAdvice; + return $this->mustCache; + } + + /** + * @return $this + */ + final public function enableCache() + { + $this->mustCache = true; + + return $this; } /** - * @param CacheAdvice $cacheAdvice - * * @return $this */ - final public function setCacheAdvice(CacheAdvice $cacheAdvice) + final public function disableCache() { - $this->cacheAdvice = $cacheAdvice; + $this->mustCache = false; return $this; } @@ -227,6 +228,7 @@ final public function getMaxFetchAttempts() */ final public function setMaxFetchAttempts($attempts) { + // TODO: Consider throwing exception instead of silently constraining bounds. $this->maxFetchAttempts = max(1, $attempts | 0); return $this; diff --git a/test/FixtureFactory.php b/test/FixtureFactory.php index 18aa5a3..0772174 100644 --- a/test/FixtureFactory.php +++ b/test/FixtureFactory.php @@ -1,7 +1,6 @@ connector = \Mockery::mock(CachingConnector::class, [])->makePartial() - ->shouldReceive('fetchFreshData') - ->andReturn('foo', 'bar') - ->getMock(); + $this->connector = new CachingConnector( + $this->wrappedConnector = \Mockery::mock(Connector::class) + ->shouldReceive('fetch') + ->andReturn('foo', 'bar') + ->getMock() + ); - $this->context = FixtureFactory::buildConnectionContext(CacheAdvice::SHOULD_CACHE()); + $this->context = FixtureFactory::buildConnectionContext(true); $this->options = new TestOptions; } + /** + * Tests that when cache is enabled, the same result is returned because the wrapped connector is bypassed. + */ public function testCacheEnabled() { self::assertSame('foo', $this->connector->fetch($this->context, 'baz', $this->options)); self::assertSame('foo', $this->connector->fetch($this->context, 'baz', $this->options)); } + /** + * Tests that when cache is disabled, different results are returned from the wrapped connector. + */ public function testCacheDisabled() { - $context = FixtureFactory::buildConnectionContext(CacheAdvice::SHOULD_NOT_CACHE()); + // The default connection context has caching disabled. + $context = FixtureFactory::buildConnectionContext(); self::assertSame('foo', $this->connector->fetch($context, 'baz', $this->options)); self::assertSame('bar', $this->connector->fetch($context, 'baz', $this->options)); } - public function testCacheAvailable() + /** + * Tests that when sources are the same but options are different, the cache is not reused. + */ + public function testCacheBypassedForDifferentOptions() { - self::assertTrue($this->connector->isCacheAvailable()); + self::assertSame('foo', $this->connector->fetch($this->context, 'baz', $this->options)); + + $this->options->setFoo('bar'); + self::assertSame('bar', $this->connector->fetch($this->context, 'baz', $this->options)); } - public function testGetSetCache() + /** + * Tests that when the same options are specified by two different object instances, the cache is reused. + */ + public function testCacheUsedForDifferentOptionsInstance() { - self::assertInstanceOf(CacheItemPoolInterface::class, $this->connector->getCache()); - self::assertNotSame($cache = new MemoryCache, $this->connector->getCache()); - - $this->connector->setCache($cache); - self::assertSame($cache, $this->connector->getCache()); + self::assertSame('foo', $this->connector->fetch($this->context, 'baz', $this->options)); + self::assertSame('foo', $this->connector->fetch($this->context, 'baz', clone $this->options)); } - public function testGetSetCacheKeyGenerator() + public function testNullAndEmptyOptionsAreEquivalent() { - self::assertInstanceOf(CacheKeyGenerator::class, $this->connector->getCacheKeyGenerator()); - self::assertNotSame($cacheKeyGenerator = new JsonCacheKeyGenerator, $this->connector->getCacheKeyGenerator()); + /** @var EncapsulatedOptions $options */ + $options = \Mockery::mock(EncapsulatedOptions::class)->shouldReceive('copy')->andReturn([])->getMock(); - $this->connector->setCacheKeyGenerator($cacheKeyGenerator); - self::assertSame($cacheKeyGenerator, $this->connector->getCacheKeyGenerator()); + self::assertEmpty($options->copy()); + self::assertSame('foo', $this->connector->fetch($this->context, 'baz', $options)); + self::assertSame('foo', $this->connector->fetch($this->context, 'baz')); } - public function testCacheBypassedForDifferentOptions() + /** + * Tests that the default cache key generator does not output reserved characters even when comprised of options + * containing them. + */ + public function testCacheKeyExcludesReservedCharacters() { - self::assertSame('foo', $this->connector->fetch($this->context, 'baz', $this->options)); + $reservedCharacters = CacheKeyGenerator::RESERVED_CHARACTERS; - $this->options->setFoo('bar'); - self::assertSame('bar', $this->connector->fetch($this->context, 'baz', $this->options)); - } + $connector = $this->createConnector($cache = \Mockery::spy(CacheItemPoolInterface::class)); - public function testCacheUsedForDifferentOptionsInstance() - { - self::assertSame('foo', $this->connector->fetch($this->context, 'baz', $this->options)); - self::assertSame('foo', $this->connector->fetch($this->context, 'baz', clone $this->options)); + $cache->shouldReceive('hasItem') + ->andReturnUsing( + function ($key) use ($reservedCharacters) { + foreach (str_split($reservedCharacters) as $reservedCharacter) { + self::assertNotContains($reservedCharacter, $key); + } + } + )->once() + ->shouldReceive('getItem')->andReturnSelf() + ->shouldReceive('set')->andReturn(\Mockery::mock(CacheItemInterface::class)) + ; + + $connector->fetch($this->context, $reservedCharacters, (new TestOptions)->setFoo($reservedCharacters)); } /** - * Tests that when the cache key generator returns the same hash the same data is fetched, and when it does not, + * Tests that when the cache key generator returns the same key the same data is fetched, and when it does not, * fresh data is fetched. */ public function testCacheKeyGenerator() { - $this->connector->setCacheKeyGenerator( + $connector = $this->createConnector( + null, \Mockery::mock(CacheKeyGenerator::class) ->shouldReceive('generateCacheKey') ->with($source = 'baz', $this->options->copy()) @@ -112,14 +143,18 @@ public function testCacheKeyGenerator() ->getMock() ); - self::assertSame('foo', $this->connector->fetch($this->context, $source, $this->options)); - self::assertSame('foo', $this->connector->fetch($this->context, $source, $this->options)); - self::assertSame('bar', $this->connector->fetch($this->context, $source, $this->options)); + self::assertSame('foo', $connector->fetch($this->context, $source, $this->options)); + self::assertSame('foo', $connector->fetch($this->context, $source, $this->options)); + self::assertSame('bar', $connector->fetch($this->context, $source, $this->options)); } + /** + * TODO: Remove when PHP 5 support dropped. + */ public function testFetchThrowsInvalidCacheKeyExceptionOnNonStringCacheKey() { - $this->connector->setCacheKeyGenerator( + $connector = $this->createConnector( + null, \Mockery::mock(CacheKeyGenerator::class) ->shouldReceive('generateCacheKey') ->andReturn(1) @@ -127,53 +162,25 @@ public function testFetchThrowsInvalidCacheKeyExceptionOnNonStringCacheKey() ); $this->setExpectedException(InvalidCacheKeyException::class, 'Cache key must be a string.'); - $this->connector->fetch($this->context, 'baz', $this->options); + $connector->fetch($this->context, 'baz', $this->options); } public function testFetchThrowsInvalidCacheKeyExceptionOnNonPSR6CompliantCacheKey() { - $this->connector->setCacheKeyGenerator( + $connector = $this->createConnector( + null, \Mockery::mock(CacheKeyGenerator::class) ->shouldReceive('generateCacheKey') - ->andReturn(CachingConnector::RESERVED_CHARACTERS) + ->andReturn(CacheKeyGenerator::RESERVED_CHARACTERS) ->getMock() ); $this->setExpectedException(InvalidCacheKeyException::class, 'contains one or more reserved characters'); - $this->connector->fetch($this->context, 'baz', $this->options); - } - - public function testNullAndEmptyOptionsAreEquivalent() - { - /** @var EncapsulatedOptions $options */ - $options = \Mockery::mock(EncapsulatedOptions::class)->shouldReceive('copy')->andReturn([])->getMock(); - - self::assertEmpty($options->copy()); - self::assertSame('foo', $this->connector->fetch($this->context, 'baz', $options)); - self::assertSame('foo', $this->connector->fetch($this->context, 'baz')); + $connector->fetch($this->context, 'baz', $this->options); } - /** - * Tests that the default cache key generator does not output reserved characters even when comprised of options - * containing them. - */ - public function testCacheKeyExcludesReservedCharacters() + private function createConnector(MockInterface $cache = null, MockInterface $cacheKeyGenerator = null) { - $reservedCharacters = CachingConnector::RESERVED_CHARACTERS; - - $this->connector->setCache($cache = \Mockery::spy(CacheItemPoolInterface::class)); - - $cache->shouldReceive('hasItem') - ->andReturnUsing( - function ($key) use ($reservedCharacters) { - foreach (str_split($reservedCharacters) as $reservedCharacter) { - self::assertNotContains($reservedCharacter, $key); - } - } - )->once() - ->shouldReceive('getItem')->andReturnSelf() - ->shouldReceive('set')->andReturn(\Mockery::mock(CacheItemInterface::class)); - - $this->connector->fetch($this->context, $reservedCharacters, (new TestOptions)->setFoo($reservedCharacters)); + return new CachingConnector($this->wrappedConnector, $cache, $cacheKeyGenerator); } } diff --git a/test/Integration/Porter/PorterTest.php b/test/Integration/Porter/PorterTest.php index 7189818..5d9ad3e 100644 --- a/test/Integration/Porter/PorterTest.php +++ b/test/Integration/Porter/PorterTest.php @@ -4,7 +4,6 @@ use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; use Mockery\MockInterface; use Psr\Container\ContainerInterface; -use ScriptFUSION\Porter\Cache\CacheAdvice; use ScriptFUSION\Porter\Cache\CacheUnavailableException; use ScriptFUSION\Porter\Collection\FilteredRecords; use ScriptFUSION\Porter\Collection\PorterRecords; @@ -12,8 +11,8 @@ use ScriptFUSION\Porter\Collection\RecordCollection; use ScriptFUSION\Porter\Connector\ConnectionContext; use ScriptFUSION\Porter\Connector\Connector; +use ScriptFUSION\Porter\Connector\ImportConnector; use ScriptFUSION\Porter\Connector\RecoverableConnectorException; -use ScriptFUSION\Porter\Connector\SuperConnector; use ScriptFUSION\Porter\ImportException; use ScriptFUSION\Porter\Options\EncapsulatedOptions; use ScriptFUSION\Porter\Porter; @@ -142,7 +141,7 @@ public function testImportOptions() MockFactory::mockResource($provider) ->shouldReceive('fetch') ->with( - \Mockery::type(SuperConnector::class), + \Mockery::type(ImportConnector::class), \Mockery::on(function (EncapsulatedOptions $argument) use ($options) { self::assertNotSame($argument, $options, 'Options not cloned.'); @@ -344,11 +343,14 @@ public function testFilter() self::assertNotSame($previous->getFilter(), $filter, 'Filter was not cloned.'); } + /** + * Tests that when caching is required but a caching facility is unavailable, an exception is thrown. + */ public function testCacheUnavailable() { $this->setExpectedException(CacheUnavailableException::class); - $this->porter->import($this->specification->setCacheAdvice(CacheAdvice::MUST_CACHE())); + $this->porter->import($this->specification->enableCache()); } /** diff --git a/test/MockFactory.php b/test/MockFactory.php index ea53ce6..1400bf6 100644 --- a/test/MockFactory.php +++ b/test/MockFactory.php @@ -3,7 +3,7 @@ use Mockery\MockInterface; use ScriptFUSION\Porter\Connector\Connector; -use ScriptFUSION\Porter\Connector\SuperConnector; +use ScriptFUSION\Porter\Connector\ImportConnector; use ScriptFUSION\Porter\Provider\Provider; use ScriptFUSION\Porter\Provider\ProviderOptions; use ScriptFUSION\Porter\Provider\Resource\ProviderResource; @@ -55,7 +55,7 @@ public static function mockResource(Provider $provider, \Iterator $return = null ->shouldReceive('getProviderClassName') ->andReturn(get_class($provider)) ->shouldReceive('fetch') - ->andReturnUsing(function (SuperConnector $connector) { + ->andReturnUsing(function (ImportConnector $connector) { return new \ArrayIterator([$connector->fetch('foo')]); }) ->byDefault() diff --git a/test/Unit/Porter/Connector/ImportConnectorTest.php b/test/Unit/Porter/Connector/ImportConnectorTest.php new file mode 100644 index 0000000..e62a234 --- /dev/null +++ b/test/Unit/Porter/Connector/ImportConnectorTest.php @@ -0,0 +1,82 @@ +shouldReceive('fetch') + ->with( + $context = FixtureFactory::buildConnectionContext(), + $source = 'bar', + $options = \Mockery::mock(EncapsulatedOptions::class) + )->once() + ->andReturn($output = 'foo') + ->getMock(), + $context + ); + + self::assertSame($output, $connector->fetch($source, $options)); + } + + /** + * Tests that when context specifies no cache required and a normal connector is used, fetch succeeds. + */ + public function testFetchCacheDisabled() + { + $connector = new ImportConnector( + \Mockery::mock(Connector::class) + ->shouldReceive('fetch') + ->andReturn($output = 'foo') + ->getMock(), + FixtureFactory::buildConnectionContext() + ); + + self::assertSame($output, $connector->fetch('bar')); + } + + /** + * Tests that when context specifies cache required and a caching connector is used, fetch succeeds. + */ + public function testFetchCacheEnabled() + { + $connector = new ImportConnector( + \Mockery::mock(CachingConnector::class) + ->shouldReceive('fetch') + ->andReturn($output = 'foo') + ->getMock(), + FixtureFactory::buildConnectionContext(true) + ); + + self::assertSame($output, $connector->fetch('bar')); + } + + /** + * Tests that when context specifies cache required but a non-caching connector is used, an exception is thrown. + */ + public function testFetchCacheEnabledButNotAvailable() + { + $this->setExpectedException(CacheUnavailableException::class); + + new ImportConnector( + \Mockery::mock(Connector::class), + FixtureFactory::buildConnectionContext(true) + ); + } +} diff --git a/test/Unit/Porter/Connector/SuperConnectorTest.php b/test/Unit/Porter/Connector/SuperConnectorTest.php deleted file mode 100644 index c30c339..0000000 --- a/test/Unit/Porter/Connector/SuperConnectorTest.php +++ /dev/null @@ -1,56 +0,0 @@ -superConnector = new SuperConnector( - $this->connector = - \Mockery::spy(Connector::class, Cache::class) - ->shouldReceive('fetch') - ->andReturn('foo') - ->getMock(), - FixtureFactory::buildConnectionContext(CacheAdvice::MUST_CACHE()) - ); - } - - public function testCacheUnavailable() - { - $this->setExpectedException(CacheUnavailableException::class, 'unavailable'); - - $this->superConnector->fetch('foo'); - } - - /** - * Tests that when cache is optional no exception is thrown when connector does not support caching. - */ - public function testCacheOptional() - { - self::assertSame( - 'foo', - (new SuperConnector( - $this->connector, - FixtureFactory::buildConnectionContext(CacheAdvice::SHOULD_CACHE()) - ))->fetch('bar') - ); - } -} diff --git a/test/Unit/Porter/ImportSpecificationTest.php b/test/Unit/Porter/ImportSpecificationTest.php index f944f02..6604d1f 100644 --- a/test/Unit/Porter/ImportSpecificationTest.php +++ b/test/Unit/Porter/ImportSpecificationTest.php @@ -1,13 +1,15 @@ getFetchExceptionHandler()); } - public function testProviderData() + public function testGetResource() { self::assertSame($this->resource, $this->specification->getResource()); } - public function testProviderTag() + public function testProviderName() { - self::assertSame($tag = 'foo', $this->specification->setProviderName($tag)->getProviderName()); + self::assertSame($name = 'foo', $this->specification->setProviderName($name)->getProviderName()); } public function testAddTransformer() @@ -100,12 +102,15 @@ public function testContext() self::assertSame($context = 'foo', $this->specification->setContext($context)->getContext()); } - public function testCacheAdvice() + public function testCache() { - self::assertSame( - $advice = CacheAdvice::MUST_CACHE(), - $this->specification->setCacheAdvice($advice)->getCacheAdvice() - ); + self::assertFalse($this->specification->mustCache()); + + $this->specification->enableCache(); + self::assertTrue($this->specification->mustCache()); + + $this->specification->disableCache(); + self::assertFalse($this->specification->mustCache()); } /** diff --git a/test/Unit/Porter/Provider/Resource/NullResourceTest.php b/test/Unit/Porter/Provider/Resource/NullResourceTest.php index a4992f5..3b3d737 100644 --- a/test/Unit/Porter/Provider/Resource/NullResourceTest.php +++ b/test/Unit/Porter/Provider/Resource/NullResourceTest.php @@ -2,7 +2,7 @@ namespace ScriptFUSIONTest\Unit\Porter\Provider\Resource; use ScriptFUSION\Porter\Connector\Connector; -use ScriptFUSION\Porter\Connector\SuperConnector; +use ScriptFUSION\Porter\Connector\ImportConnector; use ScriptFUSION\Porter\Provider\Resource\NullResource; use ScriptFUSIONTest\FixtureFactory; @@ -12,7 +12,7 @@ public function test() { self::assertFalse( (new NullResource)->fetch( - new SuperConnector(\Mockery::mock(Connector::class), FixtureFactory::buildConnectionContext()) + new ImportConnector(\Mockery::mock(Connector::class), FixtureFactory::buildConnectionContext()) )->valid() ); }