diff --git a/src/Contentful.php b/src/Contentful.php index d9c1442..572585c 100644 --- a/src/Contentful.php +++ b/src/Contentful.php @@ -918,7 +918,7 @@ private function generateCacheKey($spaceKey, $queryType, $isPreview, $disambigua { $key = $spaceKey . '-' . $queryType . (($isPreview) ? '-preview' : ''); if ($disambiguator) { - $key .= ':' . $disambiguator; + $key .= '↦' . $disambiguator; } if (count($parameters) > 0) { //sort parameters by name, then key @@ -932,11 +932,12 @@ private function generateCacheKey($spaceKey, $queryType, $isPreview, $disambigua }; usort($parameters, $paramSort); $key .= '-' . implode(',', array_map(function (ParameterInterface $param) { - return sprintf('(%s)%s:%s', $param->getName(), $param->getKey(), $param->getValue()); + return sprintf('|%s|%s↦%s', $param->getName(), $param->getKey(), $param->getValue()); }, $parameters)); } + $illegalPsr6Characters = '{}()/\@:'; - return $key; + return strtr($key, array_fill_keys(str_split($illegalPsr6Characters), '')); } /** diff --git a/tests/ContentfulTest.php b/tests/ContentfulTest.php index 33264de..9952140 100644 --- a/tests/ContentfulTest.php +++ b/tests/ContentfulTest.php @@ -283,7 +283,7 @@ public function testGetEntriesAsync() public function testCacheMissDoesFetch() { $handlerOption = $this->getSuccessHandlerOption($this->getEntriesData(), '235345lj34h53j4h'); - $expectedCacheKey = 'jskdfjhsdfk-entries-(equal)fields.old:6,(less_than)fields.ghosts[lt]:6'; + $expectedCacheKey = 'jskdfjhsdfk-entries-|equal|fields.old↦6,|less_than|fields.ghosts[lt]↦6'; $cachePool = $this->getMockCachePool(); $cacheItem = $this->getMockCacheItem(); $cachePool @@ -306,7 +306,7 @@ public function testCacheMissDoesFetch() public function testCacheHitUsesCacheAndDoesNotFetch() { $handlerOption = $this->getExplodyHandlerOption(); - $expectedCacheKey = 'jskdfjhsdfk-entries-(equal)fields.old:6,(less_than)fields.ghosts[lt]:6'; + $expectedCacheKey = 'jskdfjhsdfk-entries-|equal|fields.old↦6,|less_than|fields.ghosts[lt]↦6'; $cachePool = $this->getMockCachePool(); $cacheItem = $this->getMockCacheItem(); $cachePool @@ -332,7 +332,7 @@ public function testCacheHitUsesCacheAndDoesNotFetch() public function testUsesFallbackCacheOnRequestFailure() { $handlerOption = $this->getExplodyHandlerOption(); - $expectedCacheKey = 'jskdfjhsdfk-entries-(equal)fields.old:6,(less_than)fields.ghosts[lt]:6'; + $expectedCacheKey = 'jskdfjhsdfk-entries-|equal|fields.old↦6,|less_than|fields.ghosts[lt]↦6'; $frontCacheItem = $this->getMockCacheItem(); $frontCachePool = $this->getMockCachePool(); $frontCachePool @@ -366,7 +366,7 @@ public function testUsesFallbackCacheOnRequestFailure() public function testThrowsResourceUnavailableExceptionIfFailResponseCachedInFallbackCache() { $handlerOption = $this->getExplodyHandlerOption(); - $expectedCacheKey = 'jskdfjhsdfk-entries-(equal)fields.old:6,(less_than)fields.ghosts[lt]:6'; + $expectedCacheKey = 'jskdfjhsdfk-entries-|equal|fields.old↦6,|less_than|fields.ghosts[lt]↦6'; $frontCacheItem = $this->getMockCacheItem(); $frontCachePool = $this->getMockCachePool(); $frontCachePool @@ -398,7 +398,7 @@ public function testThrowsResourceUnavailableExceptionIfFailResponseCachedInFall public function testFailResponseDoesNotSaveIntoFallbackCacheEvenIfCachingFailResponses() { $handlerOption = $this->getExplodyHandlerOption(); - $expectedCacheKey = 'jskdfjhsdfk-entries-(equal)fields.old:6,(less_than)fields.ghosts[lt]:6'; + $expectedCacheKey = 'jskdfjhsdfk-entries-|equal|fields.old↦6,|less_than|fields.ghosts[lt]↦6'; $frontCacheItem = $this->getMockCacheItem(); $frontCachePool = $this->getMockCachePool(); $frontCachePool @@ -424,7 +424,7 @@ public function testFailResponseDoesNotSaveIntoFallbackCacheEvenIfCachingFailRes public function testUsesFallbackCacheOnRequestSuccessfulButInvalid() { $handlerOption = $this->getSuccessHandlerOption($this->getEmptyEntriesData(), '235345lj34h53j4h'); - $expectedCacheKey = 'jskdfjhsdfk-entries-(equal)fields.old:6,(less_than)fields.ghosts[lt]:6'; + $expectedCacheKey = 'jskdfjhsdfk-entries-|equal|fields.old↦6,|less_than|fields.ghosts[lt]↦6'; $frontCacheItem = $this->getMockCacheItem(); $frontCachePool = $this->getMockCachePool(); $frontCachePool @@ -466,7 +466,7 @@ public function testUsesFallbackCacheOnRequestSuccessfulButInvalid() public function testInvalidResponseDoesNotSaveIntoFallbackCacheEvenIfCachingFailResponses() { $handlerOption = $this->getSuccessHandlerOption($this->getEmptyEntriesData(), '235345lj34h53j4h'); - $expectedCacheKey = 'jskdfjhsdfk-entries-(equal)fields.old:6,(less_than)fields.ghosts[lt]:6'; + $expectedCacheKey = 'jskdfjhsdfk-entries-|equal|fields.old↦6,|less_than|fields.ghosts[lt]↦6'; $frontCacheItem = $this->getMockCacheItem(); $frontCachePool = $this->getMockCachePool(); $frontCachePool @@ -543,7 +543,7 @@ public function testQueryIsLoggedIfLoggerTrue() public function testUsePreviewApiForCachedGetEntriesCall() { $handlerOption = $this->getExplodyHandlerOption(); - $expectedCacheKey = 'jskdfjhsdfk-entries-preview-(equal)fields.old:6,(less_than)fields.ghosts[lt]:6'; + $expectedCacheKey = 'jskdfjhsdfk-entries-preview-|equal|fields.old↦6,|less_than|fields.ghosts[lt]↦6'; $cachePool = $this->getMockCachePool(); $cacheItem = $this->getMockCacheItem(); $cachePool @@ -562,8 +562,8 @@ public function testUsePreviewApiForCachedGetEntriesCall() $parameters = [new LessThanFilter(new FieldProperty('ghosts'), 6), new EqualFilter(new FieldProperty('old'), 6)]; $entries = $contentful->getEntries($parameters); $entry = array_values(iterator_to_array($entries))[0]; - $this->assertInstanceOf('Markup\Contentful\EntryInterface', $entry); - $this->assertInstanceOf('Markup\Contentful\EntryInterface', $entry['bestFriend']); + $this->assertInstanceOf(EntryInterface::class, $entry); + $this->assertInstanceOf(EntryInterface::class, $entry['bestFriend']); } public function testGetContentTypes() @@ -620,7 +620,7 @@ public function testGetContentTypeByNameAsync() public function testGetNonExistentResourceWhenCachedThrowsWithoutRequest() { - $expectedCacheKey = 'jskdfjhsdfk-entry:cat'; + $expectedCacheKey = 'jskdfjhsdfk-entry↦cat'; $cachePool = $this->getMockCachePool(); $cacheItem = $this->getMockCacheItem(); $cachePool diff --git a/tests/Decorator/CompositeAssetDecoratorTest.php b/tests/Decorator/CompositeAssetDecoratorTest.php index 82ac031..148a16c 100644 --- a/tests/Decorator/CompositeAssetDecoratorTest.php +++ b/tests/Decorator/CompositeAssetDecoratorTest.php @@ -2,6 +2,8 @@ namespace Markup\Contentful\Tests\Decorator; +use Markup\Contentful\AssetInterface; +use Markup\Contentful\Decorator\AssetDecoratorInterface; use Markup\Contentful\Decorator\CompositeAssetDecorator; use Mockery as m; @@ -19,7 +21,7 @@ protected function tearDown() public function testIsDecorator() { - $this->assertInstanceOf('Markup\Contentful\Decorator\AssetDecoratorInterface', $this->composite); + $this->assertInstanceOf(AssetDecoratorInterface::class, $this->composite); } public function testCompositeDoesNullDecorationByDefault() @@ -54,11 +56,11 @@ public function testCompositeWithTwoDecoratorsDecoratesInLifoOrder() private function getMockAsset() { - return m::mock('Markup\Contentful\AssetInterface')->shouldIgnoreMissing(); + return m::mock(AssetInterface::class)->shouldIgnoreMissing(); } private function getMockDecorator() { - return m::mock('Markup\Contentful\Decorator\AssetDecoratorInterface')->shouldIgnoreMissing(); + return m::mock(AssetDecoratorInterface::class)->shouldIgnoreMissing(); } } diff --git a/tests/Decorator/DecoratedAssetTest.php b/tests/Decorator/DecoratedAssetTest.php index 54de3f5..533e981 100644 --- a/tests/Decorator/DecoratedAssetTest.php +++ b/tests/Decorator/DecoratedAssetTest.php @@ -2,13 +2,14 @@ namespace Markup\Contentful\Tests\Decorator; +use Markup\Contentful\AssetInterface; use Mockery as m; class DecoratedAssetTest extends \PHPUnit_Framework_TestCase { protected function setUp() { - $this->asset = m::mock('Markup\Contentful\AssetInterface'); + $this->asset = m::mock(AssetInterface::class); $this->decorated = new ConcreteDecoratedAsset($this->asset); } diff --git a/tests/Filter/ContentTypeFilterProviderTest.php b/tests/Filter/ContentTypeFilterProviderTest.php index a2c24b1..4c08a86 100644 --- a/tests/Filter/ContentTypeFilterProviderTest.php +++ b/tests/Filter/ContentTypeFilterProviderTest.php @@ -2,6 +2,9 @@ namespace Markup\Contentful\Tests\Filter; +use Markup\Contentful\Contentful; +use Markup\Contentful\ContentTypeInterface; +use Markup\Contentful\Filter\ContentTypeFilter; use Markup\Contentful\Filter\ContentTypeFilterProvider; use Mockery as m; @@ -9,7 +12,7 @@ class ContentTypeFilterProviderTest extends \PHPUnit_Framework_TestCase { protected function setUp() { - $this->contentful = m::mock('Markup\Contentful\Contentful'); + $this->contentful = m::mock(Contentful::class); $this->provider = new ContentTypeFilterProvider($this->contentful); } @@ -20,7 +23,7 @@ protected function tearDown() public function testCreateForExistingContentType() { - $contentType = m::mock('Markup\Contentful\ContentTypeInterface'); + $contentType = m::mock(ContentTypeInterface::class); $id = 42; $contentType ->shouldReceive('getId') @@ -34,7 +37,7 @@ public function testCreateForExistingContentType() ->with($name, m::any()) ->andReturn($contentType); $filter = $this->provider->createForContentTypeName($name); - $this->assertInstanceOf('Markup\Contentful\Filter\ContentTypeFilter', $filter); + $this->assertInstanceOf(ContentTypeFilter::class, $filter); $this->assertEquals($id, $filter->getValue()); } diff --git a/tests/Filter/ContentTypeFilterTest.php b/tests/Filter/ContentTypeFilterTest.php index 6b30975..b7aac69 100644 --- a/tests/Filter/ContentTypeFilterTest.php +++ b/tests/Filter/ContentTypeFilterTest.php @@ -3,6 +3,7 @@ namespace Markup\Contentful\Tests\Filter; use Markup\Contentful\Filter\ContentTypeFilter; +use Markup\Contentful\FilterInterface; class ContentTypeFilterTest extends \PHPUnit_Framework_TestCase { @@ -14,7 +15,7 @@ protected function setUp() public function testIsFilter() { - $this->assertInstanceOf('Markup\Contentful\FilterInterface', $this->filter); + $this->assertInstanceOf(FilterInterface::class, $this->filter); } public function testGetKey() diff --git a/tests/Filter/EqualFilterTest.php b/tests/Filter/EqualFilterTest.php index 1baa784..700c281 100644 --- a/tests/Filter/EqualFilterTest.php +++ b/tests/Filter/EqualFilterTest.php @@ -3,13 +3,31 @@ namespace Markup\Contentful\Tests\Filter; use Markup\Contentful\Filter\EqualFilter; +use Markup\Contentful\Filter\PropertyFilter; +use Markup\Contentful\FilterInterface; +use Markup\Contentful\PropertyInterface; use Mockery as m; class EqualFilterTest extends \PHPUnit_Framework_TestCase { + /** + * @var PropertyInterface|m\MockInterface + */ + private $property; + + /** + * @var string + */ + private $value; + + /** + * @var EqualFilter + */ + private $filter; + protected function setUp() { - $this->property = m::mock('Markup\Contentful\PropertyInterface'); + $this->property = m::mock(PropertyInterface::class); $this->value = 'value'; $this->filter = new EqualFilter($this->property, $this->value); } @@ -21,12 +39,12 @@ protected function tearDown() public function testIsFilter() { - $this->assertInstanceOf('Markup\Contentful\FilterInterface', $this->filter); + $this->assertInstanceOf(FilterInterface::class, $this->filter); } public function testIsPropertyFilter() { - $this->assertInstanceOf('Markup\Contentful\Filter\PropertyFilter', $this->filter); + $this->assertInstanceOf(PropertyFilter::class, $this->filter); } public function testGetKey() diff --git a/tests/Filter/ExcludeFilterTest.php b/tests/Filter/ExcludeFilterTest.php index e2920de..71834cb 100644 --- a/tests/Filter/ExcludeFilterTest.php +++ b/tests/Filter/ExcludeFilterTest.php @@ -3,13 +3,31 @@ namespace Markup\Contentful\Tests\Filter; use Markup\Contentful\Filter\ExcludeFilter; +use Markup\Contentful\Filter\PropertyFilter; +use Markup\Contentful\FilterInterface; +use Markup\Contentful\PropertyInterface; use Mockery as m; class ExcludeFilterTest extends \PHPUnit_Framework_TestCase { + /** + * @var PropertyInterface|m\MockInterface + */ + private $property; + + /** + * @var string[] + */ + private $values; + + /** + * @var ExcludeFilter + */ + private $filter; + protected function setUp() { - $this->property = m::mock('Markup\Contentful\PropertyInterface'); + $this->property = m::mock(PropertyInterface::class); $this->values = ['foo', 'bar']; $this->filter = new ExcludeFilter($this->property, $this->values); } @@ -21,12 +39,12 @@ protected function tearDown() public function testIsFilter() { - $this->assertInstanceOf('Markup\Contentful\FilterInterface', $this->filter); + $this->assertInstanceOf(FilterInterface::class, $this->filter); } public function testIsPropertyFilter() { - $this->assertInstanceOf('Markup\Contentful\Filter\PropertyFilter', $this->filter); + $this->assertInstanceOf(PropertyFilter::class, $this->filter); } public function testGetKey() diff --git a/tests/Filter/ExistsFilterTest.php b/tests/Filter/ExistsFilterTest.php index 67d5a37..9d0a630 100644 --- a/tests/Filter/ExistsFilterTest.php +++ b/tests/Filter/ExistsFilterTest.php @@ -3,13 +3,30 @@ namespace Markup\Contentful\Tests\Filter; use Markup\Contentful\Filter\ExistsFilter; +use Markup\Contentful\FilterInterface; +use Markup\Contentful\PropertyInterface; use Mockery as m; class ExistsFilterTest extends \PHPUnit_Framework_TestCase { + /** + * @var PropertyInterface|m\MockInterface + */ + private $property; + + /** + * @var bool + */ + private $value; + + /** + * @var ExistsFilter + */ + private $filter; + protected function setUp() { - $this->property = m::mock('Markup\Contentful\PropertyInterface'); + $this->property = m::mock(PropertyInterface::class); $this->propertyKey = 'prop'; $this->property ->shouldReceive('getKey') @@ -25,7 +42,7 @@ protected function tearDown() public function testIsFilter() { - $this->assertInstanceOf('Markup\Contentful\FilterInterface', $this->filter); + $this->assertInstanceOf(FilterInterface::class, $this->filter); } public function testGetKey() diff --git a/tests/Filter/MimeTypeGroupFilterTest.php b/tests/Filter/MimeTypeGroupFilterTest.php index ecd3d58..a9573a4 100644 --- a/tests/Filter/MimeTypeGroupFilterTest.php +++ b/tests/Filter/MimeTypeGroupFilterTest.php @@ -3,6 +3,8 @@ namespace Markup\Contentful\Tests\Filter; use Markup\Contentful\Filter\MimeTypeGroupFilter; +use Markup\Contentful\Filter\PropertyFilter; +use Markup\Contentful\FilterInterface; class MimeTypeGroupFilterTest extends \PHPUnit_Framework_TestCase { @@ -14,12 +16,12 @@ protected function setUp() public function testIsFilter() { - $this->assertInstanceOf('Markup\Contentful\FilterInterface', $this->filter); + $this->assertInstanceOf(FilterInterface::class, $this->filter); } public function testIsPropertyFilter() { - $this->assertInstanceOf('Markup\Contentful\Filter\PropertyFilter', $this->filter); + $this->assertInstanceOf(PropertyFilter::class, $this->filter); } public function testGetKey() diff --git a/tests/Filter/NotEqualFilterTest.php b/tests/Filter/NotEqualFilterTest.php index 0dc8bfa..6ed82aa 100644 --- a/tests/Filter/NotEqualFilterTest.php +++ b/tests/Filter/NotEqualFilterTest.php @@ -3,13 +3,16 @@ namespace Markup\Contentful\Tests\Filter; use Markup\Contentful\Filter\NotEqualFilter; +use Markup\Contentful\Filter\PropertyFilter; +use Markup\Contentful\FilterInterface; +use Markup\Contentful\PropertyInterface; use Mockery as m; class NotEqualFilterTest extends \PHPUnit_Framework_TestCase { protected function setUp() { - $this->property = m::mock('Markup\Contentful\PropertyInterface'); + $this->property = m::mock(PropertyInterface::class); $this->value = 'value'; $this->filter = new NotEqualFilter($this->property, $this->value); } @@ -21,12 +24,12 @@ protected function tearDown() public function testIsFilter() { - $this->assertInstanceOf('Markup\Contentful\FilterInterface', $this->filter); + $this->assertInstanceOf(FilterInterface::class, $this->filter); } public function testIsPropertyFilter() { - $this->assertInstanceOf('Markup\Contentful\Filter\PropertyFilter', $this->filter); + $this->assertInstanceOf(PropertyFilter::class, $this->filter); } public function testGetKey() diff --git a/tests/Filter/WithinCircleFilterTest.php b/tests/Filter/WithinCircleFilterTest.php index 0720e92..a15fcc3 100644 --- a/tests/Filter/WithinCircleFilterTest.php +++ b/tests/Filter/WithinCircleFilterTest.php @@ -3,14 +3,16 @@ namespace Markup\Contentful\Tests\Filter; use Markup\Contentful\Filter\WithinCircleFilter; +use Markup\Contentful\FilterInterface; use Markup\Contentful\Location; +use Markup\Contentful\PropertyInterface; use Mockery as m; class WithinCircleFilterTest extends \PHPUnit_Framework_TestCase { protected function setUp() { - $this->property = m::mock('Markup\Contentful\PropertyInterface'); + $this->property = m::mock(PropertyInterface::class); $this->center = new Location(15, 40); $this->radiusInKm = 42; $this->filter = new WithinCircleFilter($this->property, $this->center, $this->radiusInKm); @@ -23,7 +25,7 @@ protected function tearDown() public function testIsFilter() { - $this->assertInstanceOf('Markup\Contentful\FilterInterface', $this->filter); + $this->assertInstanceOf(FilterInterface::class, $this->filter); } public function testGetKey() diff --git a/tests/Filter/WithinRectangleFilterTest.php b/tests/Filter/WithinRectangleFilterTest.php index 89aaf66..4993bb6 100644 --- a/tests/Filter/WithinRectangleFilterTest.php +++ b/tests/Filter/WithinRectangleFilterTest.php @@ -3,7 +3,9 @@ namespace Markup\Contentful\Tests\Filter; use Markup\Contentful\Filter\WithinRectangleFilter; +use Markup\Contentful\FilterInterface; use Markup\Contentful\Location; +use Markup\Contentful\PropertyInterface; use Mockery as m; /** @@ -13,7 +15,7 @@ class WithinRectangleFilterTest extends \PHPUnit_Framework_TestCase { protected function setUp() { - $this->property = m::mock('Markup\Contentful\PropertyInterface'); + $this->property = m::mock(PropertyInterface::class); $this->bottomLeftLocation = new Location(35, 55); $this->topRightLocation = new Location(20, 70); $this->filter = new WithinRectangleFilter($this->property, $this->bottomLeftLocation, $this->topRightLocation); @@ -26,7 +28,7 @@ protected function tearDown() public function testIsFilter() { - $this->assertInstanceOf('Markup\Contentful\FilterInterface', $this->filter); + $this->assertInstanceOf(FilterInterface::class, $this->filter); } public function testGetKey() diff --git a/tests/Log/LogTest.php b/tests/Log/LogTest.php index 89b0b01..1a7ff25 100644 --- a/tests/Log/LogTest.php +++ b/tests/Log/LogTest.php @@ -18,7 +18,7 @@ public function testLog() $description = 'It all happened very quickly'; $duration = 0.032; $log = new Log($description, $duration, $isCacheHit, $type, $resourceType, $api); - $this->assertInstanceOf('Markup\Contentful\Log\LogInterface', $log); + $this->assertInstanceOf(LogInterface::class, $log); $this->assertEquals($type, $log->getType()); $this->assertEquals($isCacheHit, $log->isCacheHit()); $this->assertEquals($description, $log->getDescription()); diff --git a/tests/Log/StandardLoggerTest.php b/tests/Log/StandardLoggerTest.php index 2ce3213..10883e9 100644 --- a/tests/Log/StandardLoggerTest.php +++ b/tests/Log/StandardLoggerTest.php @@ -3,8 +3,10 @@ namespace Markup\Contentful\Tests\Log; use Markup\Contentful\Contentful; +use Markup\Contentful\Log\LoggerInterface; use Markup\Contentful\Log\LogInterface; use Markup\Contentful\Log\StandardLogger; +use Markup\Contentful\Log\TimerInterface; class StandardLoggerTest extends \PHPUnit_Framework_TestCase { @@ -15,7 +17,7 @@ protected function setUp() public function testIsLogger() { - $this->assertInstanceOf('Markup\Contentful\Log\LoggerInterface', $this->logger); + $this->assertInstanceOf(LoggerInterface::class, $this->logger); } public function testLogOneItem() @@ -23,7 +25,7 @@ public function testLogOneItem() $initialLogs = $this->logger->getLogs(); $this->assertCount(0, $initialLogs); $timer = $this->logger->getStartedTimer(); - $this->assertInstanceOf('Markup\Contentful\Log\TimerInterface', $timer); + $this->assertInstanceOf(TimerInterface::class, $timer); $this->assertTrue($timer->isStarted()); $description = 'description goes here'; $isCacheHit = true; @@ -34,7 +36,7 @@ public function testLogOneItem() $finalLogs = $this->logger->getLogs(); $this->assertCount(1, $finalLogs); $log = reset($finalLogs); - $this->assertInstanceOf('Markup\Contentful\Log\LogInterface', $log); + $this->assertInstanceOf(LogInterface::class, $log); $this->assertEquals($type, $log->getType()); $this->assertEquals($description, $log->getDescription()); $this->assertInternalType('float', $log->getDurationInSeconds()); diff --git a/tests/Log/StandardTimerTest.php b/tests/Log/StandardTimerTest.php index c0bdcb4..bf60936 100644 --- a/tests/Log/StandardTimerTest.php +++ b/tests/Log/StandardTimerTest.php @@ -3,6 +3,7 @@ namespace Markup\Contentful\Tests\Log; use Markup\Contentful\Log\StandardTimer; +use Markup\Contentful\Log\TimerInterface; class StandardTimerTest extends \PHPUnit_Framework_TestCase { @@ -13,7 +14,7 @@ protected function setUp() public function testIsTimer() { - $this->assertInstanceOf('Markup\Contentful\Log\TimerInterface', $this->timer); + $this->assertInstanceOf(TimerInterface::class, $this->timer); } public function testStandardCycle()