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
7 changes: 4 additions & 3 deletions src/Contentful.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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), ''));
}

/**
Expand Down
22 changes: 11 additions & 11 deletions tests/ContentfulTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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()
Expand Down Expand Up @@ -620,7 +620,7 @@ public function testGetContentTypeByNameAsync()

public function testGetNonExistentResourceWhenCachedThrowsWithoutRequest()
{
$expectedCacheKey = 'jskdfjhsdfk-entry:cat';
$expectedCacheKey = 'jskdfjhsdfk-entrycat';
$cachePool = $this->getMockCachePool();
$cacheItem = $this->getMockCacheItem();
$cachePool
Expand Down
8 changes: 5 additions & 3 deletions tests/Decorator/CompositeAssetDecoratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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()
Expand Down Expand Up @@ -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();
}
}
3 changes: 2 additions & 1 deletion tests/Decorator/DecoratedAssetTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
9 changes: 6 additions & 3 deletions tests/Filter/ContentTypeFilterProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@

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;

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);
}

Expand All @@ -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')
Expand All @@ -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());
}

Expand Down
3 changes: 2 additions & 1 deletion tests/Filter/ContentTypeFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Markup\Contentful\Tests\Filter;

use Markup\Contentful\Filter\ContentTypeFilter;
use Markup\Contentful\FilterInterface;

class ContentTypeFilterTest extends \PHPUnit_Framework_TestCase
{
Expand All @@ -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()
Expand Down
24 changes: 21 additions & 3 deletions tests/Filter/EqualFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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()
Expand Down
24 changes: 21 additions & 3 deletions tests/Filter/ExcludeFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand All @@ -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()
Expand Down
21 changes: 19 additions & 2 deletions tests/Filter/ExistsFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions tests/Filter/MimeTypeGroupFilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand All @@ -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()
Expand Down
Loading