Skip to content
This repository has been archived by the owner on Jan 29, 2020. It is now read-only.

#156 PSR-6 / PSR-16: use serialization with storage plugin #161

Merged
merged 8 commits into from
Apr 23, 2018

Conversation

thomasvargiu
Copy link
Contributor

#156 Removed serialization. Throw exception when storage adapter require serialization


foreach ($requiredTypes as $type) {
// 'object' => 'object' is OK
// 'integer' => 'string' is not (redis)
// 'integer' => 'integer' is not (memcache)
if (! (isset($types[$type]) && in_array($types[$type], [true, 'array', 'object'], true))) {
$shouldSerialize = true;
break;
return true;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For anybody stumbling across this patch and wondering why it works...

If an adapter does not support one of the required types, getCapabilities() will return a boolean false for that data type. However, if the Serializer plugin is attached to the adapter, it overrides getCapabilities() and returns a list of supported data types that indicates true for each type. As such, we only need to test that the adapter supports serialization at instantiation of the decorator.

@@ -304,6 +290,13 @@ public function commit()
*/
private function validateStorage(StorageInterface $storage)
{
if ($this->isSerializationRequired($storage)) {
throw new CacheException(sprintf(
'Storage %s requires a serializer plugin',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should expand on this to indicate what the user will need to do to make the storage adapter work; I'd include a link to https://docs.zendframework.com/zend-cache/storage/plugin/#quick-start, as the very first example specifically demonstrates adding a serialization plugin.

$this->memoizeSerializationCapabilities($storage);
if ($this->isSerializationRequired($storage)) {
throw new SimpleCacheException(sprintf(
'Storage %s requires a serializer plugin',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here regarding exception message.

@@ -25,6 +26,39 @@ class CacheItemPoolDecoratorTest extends TestCase
public function testStorageNotFlushableThrowsException()
{
$storage = $this->prophesize(StorageInterface::class);

$capabilities = new Capabilities($storage->reveal(), new \stdClass(), $this->defaultCapabilities);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Import stdClass.

@@ -19,6 +20,7 @@ class FilesystemIntegrationTest extends TestCase
public function testAdapterNotSupported()
{
$storage = StorageFactory::adapterFactory('filesystem');
$storage->addPlugin(new Serializer());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With this change, will the filesystem adapter work as a PSR-6 adapter? If so, we need to have it extend the PSR-6 integration test case.

Copy link
Contributor Author

@thomasvargiu thomasvargiu Apr 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think it's supported, it was just to skip that check. Probably it's better to move the required serialization check after all others checks in the validateStorage() method.

@@ -129,6 +130,27 @@ public function invalidatingTtls()
];
}

/**
* @expectedException \Zend\Cache\Psr\SimpleCache\SimpleCacheException
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please use expectException() calls directly before the statements that will raise them. This ensures that an unexpected exception of the same type is not caught, causing a false positive.

@weierophinney
Copy link
Member

@thomasvargiu I've rebased from develop, and made updates based on the feedback I provided. Once Travis is green, I'll merge.

Thanks!

@weierophinney weierophinney merged commit 11518ae into zendframework:develop Apr 23, 2018
@weierophinney
Copy link
Member

Thanks, @thomasvargiu!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants