From 0fa932f100157dcfff03367da92f9806bcf444a2 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Fri, 5 Aug 2016 21:38:43 +0200 Subject: [PATCH 1/2] fixes #328 --- composer.json | 1 + src/Viserio/Cache/CacheManager.php | 10 ++---- src/Viserio/Cache/Tests/CacheManagerTest.php | 32 ++++++++++++++++++- src/Viserio/Cache/composer.json | 4 +-- .../Filesystem/Adapters/AwsS3Connector.php | 7 ++-- src/Viserio/Filesystem/FilesystemManager.php | 12 +++++++ .../Tests/FilesystemManagerTest.php | 21 ++++++++++++ 7 files changed, 74 insertions(+), 13 deletions(-) diff --git a/composer.json b/composer.json index 7b9c1c63e..642eed7a4 100644 --- a/composer.json +++ b/composer.json @@ -103,6 +103,7 @@ "require-dev": { "aws/aws-sdk-php" : "^3.18", "cache/array-adapter" : "^0.4", + "cache/filesystem-adapter" : "^0.3", "cache/session-handler" : "^0.1", "cache/void-adapter" : "^0.3", "fzaninotto/faker" : "^1.6", diff --git a/src/Viserio/Cache/CacheManager.php b/src/Viserio/Cache/CacheManager.php index fd7311035..42c78afad 100644 --- a/src/Viserio/Cache/CacheManager.php +++ b/src/Viserio/Cache/CacheManager.php @@ -92,8 +92,6 @@ protected function createApcuDriver(array $config): ApcuCachePool * @param array $config * * @return \Cache\Adapter\PHPArray\ArrayCachePool - * - * @codeCoverageIgnore */ protected function createArrayDriver(array $config): ArrayCachePool { @@ -171,16 +169,12 @@ protected function createPredisDriver(array $config): PredisCachePool * @param array $config * * @return \Cache\Adapter\Filesystem\FilesystemCachePool - * - * @codeCoverageIgnore */ protected function createFilesystemDriver(array $config): FilesystemCachePool { - $adapter = new FilesystemManager($this->config); - - $filesystem = new Flysystem($adapter->connection($config['connection'])); + $adapter = $this->getContainer()->get($config['connection']); - return new FilesystemCachePool($filesystem); + return new FilesystemCachePool(new Flysystem($adapter)); } /** diff --git a/src/Viserio/Cache/Tests/CacheManagerTest.php b/src/Viserio/Cache/Tests/CacheManagerTest.php index 6a697b6d7..929e3050f 100644 --- a/src/Viserio/Cache/Tests/CacheManagerTest.php +++ b/src/Viserio/Cache/Tests/CacheManagerTest.php @@ -2,13 +2,16 @@ declare(strict_types=1); namespace Viserio\Cache\Tests; +use Interop\Container\ContainerInterface; +use League\Flysystem\Adapter\Local; use Narrowspark\TestingHelper\Traits\MockeryTrait; use Viserio\Cache\CacheManager; use Viserio\Contracts\Config\Manager as ConfigManager; use Cache\Adapter\{ PHPArray\ArrayCachePool, Void\VoidCachePool, - Chain\CachePoolChain + Chain\CachePoolChain, + Filesystem\FilesystemCachePool }; use Cache\SessionHandler\Psr6SessionHandler; use Cache\Namespaced\NamespacedCachePool; @@ -108,4 +111,31 @@ public function testChain() $this->assertInstanceOf(CachePoolChain::class, $chain); } + + public function testFilesystem() + { + $this->manager->getConfig()->shouldReceive('get') + ->once() + ->with('cache.drivers', []) + ->andReturn([ + 'filesystem' => [ + 'connection' => 'local' + ] + ]); + + $this->manager->getConfig()->shouldReceive('get') + ->once() + ->with('cache.namespace') + ->andReturn(null); + + $container = $this->mock(ContainerInterface::class); + $container->shouldReceive('get') + ->once() + ->with('local') + ->andReturn(new Local(__DIR__ . '/')); + + $this->manager->setContainer($container); + + $this->assertInstanceOf(FilesystemCachePool::class, $this->manager->driver('filesystem')); + } } diff --git a/src/Viserio/Cache/composer.json b/src/Viserio/Cache/composer.json index 23b9098a8..0326dcc1c 100644 --- a/src/Viserio/Cache/composer.json +++ b/src/Viserio/Cache/composer.json @@ -49,6 +49,7 @@ "cache/array-adapter" : "^0.2", "cache/session-handler" : "^0.1", "cache/void-adapter" : "^0.3", + "cache/filesystem-adapter" : "^0.3", "narrowspark/php-cs-fixer-config" : "^1.1", "narrowspark/testing-helper" : "^1.5", "phpunit/phpunit" : "^5.1" @@ -82,8 +83,7 @@ "cache/mongodb-adapter" : "Required to use the Mongodb cache (^0.3).", "cache/predis-adapter" : "Required to use the Predis cache (^0.4).", "cache/session-handler" : "Required to use the Session cache (^0.1).", - "cache/void-adapter" : "Required to use the Void cache (^0.3).", - "viserio/filesystem" : "Required to use the Filesystem cache. (self.version)" + "cache/void-adapter" : "Required to use the Void cache (^0.3)." }, "minimum-stability" : "dev", "prefer-stable" : true diff --git a/src/Viserio/Filesystem/Adapters/AwsS3Connector.php b/src/Viserio/Filesystem/Adapters/AwsS3Connector.php index 1d262db13..e614bc15f 100644 --- a/src/Viserio/Filesystem/Adapters/AwsS3Connector.php +++ b/src/Viserio/Filesystem/Adapters/AwsS3Connector.php @@ -4,7 +4,10 @@ use Aws\S3\S3Client; use InvalidArgumentException; -use League\Flysystem\AwsS3v3\AwsS3Adapter as AwsS3v3; +use League\Flysystem\{ + AdapterInterface, + AwsS3v3\AwsS3Adapter as AwsS3v3 +}; use Narrowspark\Arr\StaticArr as Arr; class AwsS3Connector extends AbstractConnector @@ -72,7 +75,7 @@ protected function getConfig(array $config): array /** * {@inheritdoc} */ - protected function getAdapter($client, array $config): \League\Flysystem\AdapterInterface + protected function getAdapter($client, array $config): AdapterInterface { return new AwsS3v3($client, $config['bucket'], $config['prefix'], $config['options']); } diff --git a/src/Viserio/Filesystem/FilesystemManager.php b/src/Viserio/Filesystem/FilesystemManager.php index d48553d2f..c26e4930d 100644 --- a/src/Viserio/Filesystem/FilesystemManager.php +++ b/src/Viserio/Filesystem/FilesystemManager.php @@ -22,6 +22,18 @@ public function getDefaultConnection(): string return $this->config->get($this->getConfigName() . '.default', 'local'); } + /** + * Get the clean flysystem adapter. + * + * @param string|null $name + * + * @return \League\Flysystem\AdapterInterface + */ + public function getFlysystemAdapter(string $name = null): AdapterInterface + { + return parent::connection($name); + } + /** * {@inheritdoc} */ diff --git a/src/Viserio/Filesystem/Tests/FilesystemManagerTest.php b/src/Viserio/Filesystem/Tests/FilesystemManagerTest.php index 606ef55b1..1487410ff 100644 --- a/src/Viserio/Filesystem/Tests/FilesystemManagerTest.php +++ b/src/Viserio/Filesystem/Tests/FilesystemManagerTest.php @@ -4,6 +4,7 @@ use Guzzle\Http\Exception\ClientErrorResponseException; use Guzzle\Http\Exception\CurlException; +use League\Flysystem\AdapterInterface; use MongoConnectionException; use Narrowspark\TestingHelper\Traits\MockeryTrait; use Viserio\Contracts\Config\Manager as ConfigManger; @@ -267,4 +268,24 @@ public function testZipConnectorDriver() $manager->connection('zip') ); } + + public function testgetFlysystemAdapter() + { + $config = $this->mock(ConfigManger::class); + $config->shouldReceive('get') + ->once() + ->with('filesystem.connections', []) + ->andReturn([ + 'zip' => [ + 'path' => __DIR__ . '\Adapters\stubs\test.zip', + ], + ]); + + $manager = new FilesystemManager($config); + + $this->assertInstanceOf( + AdapterInterface::class, + $manager->getFlysystemAdapter('zip') + ); + } } From 6a5273f60efb6f303d825e41ece7b536e1f2f5e3 Mon Sep 17 00:00:00 2001 From: Daniel Bannert Date: Fri, 5 Aug 2016 21:50:05 +0200 Subject: [PATCH 2/2] update --- composer.json | 10 ++++++++++ src/Viserio/Cache/composer.json | 4 ++-- .../Tests/Adapters/Database/MongoConnectorTest.php | 2 +- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/composer.json b/composer.json index 642eed7a4..fcb480837 100644 --- a/composer.json +++ b/composer.json @@ -144,6 +144,16 @@ }, "suggest": { "aws/aws-sdk-php" : "Required to use the SQS queue driver and SES mail driver (^3.18).", + "cache/apc-adapter" : "Required to use the Apc cache (^0.3).", + "cache/apcu-adapter" : "Required to use the Apcu cache (^0.3).", + "cache/array-adapter" : "Required to use the Array cache (^0.2)", + "cache/filesystem-adapter" : "Required to use the Filesystem cache (^0.3).", + "cache/memcache-adapter" : "Required to use the Memcache cache (^0.3).", + "cache/memcached-adapter" : "Required to use the Memcached cache (^0.3).", + "cache/mongodb-adapter" : "Required to use the Mongodb cache (^0.2).", + "cache/predis-adapter" : "Required to use the Predis cache (^0.4).", + "cache/session-handler" : "Required to use the Session cache (^0.1).", + "cache/void-adapter" : "Required to use the Void cache (^0.3).", "guzzlehttp/guzzle" : "Required to use the Mailgun and Mandrill mail drivers and the ping methods on schedules (^6.0).", "league/flysystem" : "Required to use the Flysystem Local and FTP drivers (^1.3).", "league/flysystem-aws-s3-v3" : "Required to use the Flysystem S3 driver (^1.0).", diff --git a/src/Viserio/Cache/composer.json b/src/Viserio/Cache/composer.json index 0326dcc1c..16aae3b90 100644 --- a/src/Viserio/Cache/composer.json +++ b/src/Viserio/Cache/composer.json @@ -47,9 +47,9 @@ }, "require-dev": { "cache/array-adapter" : "^0.2", + "cache/filesystem-adapter" : "^0.3", "cache/session-handler" : "^0.1", "cache/void-adapter" : "^0.3", - "cache/filesystem-adapter" : "^0.3", "narrowspark/php-cs-fixer-config" : "^1.1", "narrowspark/testing-helper" : "^1.5", "phpunit/phpunit" : "^5.1" @@ -80,7 +80,7 @@ "cache/filesystem-adapter" : "Required to use the Filesystem cache (^0.3).", "cache/memcache-adapter" : "Required to use the Memcache cache (^0.3).", "cache/memcached-adapter" : "Required to use the Memcached cache (^0.3).", - "cache/mongodb-adapter" : "Required to use the Mongodb cache (^0.3).", + "cache/mongodb-adapter" : "Required to use the Mongodb cache (^0.2).", "cache/predis-adapter" : "Required to use the Predis cache (^0.4).", "cache/session-handler" : "Required to use the Session cache (^0.1).", "cache/void-adapter" : "Required to use the Void cache (^0.3)." diff --git a/src/Viserio/Connect/Tests/Adapters/Database/MongoConnectorTest.php b/src/Viserio/Connect/Tests/Adapters/Database/MongoConnectorTest.php index de6ccd35f..fa73dd2e4 100644 --- a/src/Viserio/Connect/Tests/Adapters/Database/MongoConnectorTest.php +++ b/src/Viserio/Connect/Tests/Adapters/Database/MongoConnectorTest.php @@ -58,7 +58,7 @@ public function testConnect() 'connect' => true, ], ]; - $connection = $this->mock('stdClass'); + $connection = $this->mock(StdClass::class); $connector = $this->getMockBuilder(MongoConnector::class) ->setMethods(['createConnection', 'getOptions'])