From 8e28d1fc44e2633bd3fe289cebaf1df25342429d Mon Sep 17 00:00:00 2001 From: Chris Kankiewicz Date: Fri, 29 May 2020 22:03:38 -0700 Subject: [PATCH] Use a data provider in CacheFactoryTest --- tests/Factories/CacheFactoryTest.php | 64 +++++++--------------------- 1 file changed, 16 insertions(+), 48 deletions(-) diff --git a/tests/Factories/CacheFactoryTest.php b/tests/Factories/CacheFactoryTest.php index da5f0e7..44d2d93 100644 --- a/tests/Factories/CacheFactoryTest.php +++ b/tests/Factories/CacheFactoryTest.php @@ -9,58 +9,14 @@ use Tests\TestCase; class CacheFactoryTest extends TestCase { - public function test_it_can_compose_an_apcu_adapter(): void + /** @dataProvider cacheAdapters */ + public function test_it_can_compose_an_adapter(string $config, string $adapter): void { - $this->container->set('cache_driver', 'apcu'); + $this->container->set('cache_driver', $config); $cache = (new CacheFactory($this->container))(); - $this->assertInstanceOf(Adapter\ApcuAdapter::class, $cache); - } - - public function test_it_can_compose_an_array_adapter(): void - { - $this->container->set('cache_driver', 'array'); - - $cache = (new CacheFactory($this->container))(); - - $this->assertInstanceOf(Adapter\ArrayAdapter::class, $cache); - } - - public function test_it_can_compose_a_filesystem_adapter(): void - { - $this->container->set('cache_driver', 'file'); - - $cache = (new CacheFactory($this->container))(); - - $this->assertInstanceOf(Adapter\FilesystemAdapter::class, $cache); - } - - public function test_it_can_compose_a_memcached_adapter(): void - { - $this->container->set('cache_driver', 'memcached'); - - $cache = (new CacheFactory($this->container))(); - - $this->assertInstanceOf(Adapter\MemcachedAdapter::class, $cache); - } - - public function test_it_can_compose_a_php_files_adapter(): void - { - $this->container->set('cache_driver', 'php-file'); - - $cache = (new CacheFactory($this->container))(); - - $this->assertInstanceOf(Adapter\PhpFilesAdapter::class, $cache); - } - - public function test_it_can_compose_a_redis_adapter(): void - { - $this->container->set('cache_driver', 'redis'); - - $cache = (new CacheFactory($this->container))(); - - $this->assertInstanceOf(Adapter\RedisAdapter::class, $cache); + $this->assertInstanceOf($adapter, $cache); } public function test_it_throws_a_runtime_exception_with_an_invalid_sort_order(): void @@ -71,4 +27,16 @@ class CacheFactoryTest extends TestCase (new CacheFactory($this->container))(); } + + public function cacheAdapters(): array + { + return [ + 'APCu adapter' => ['apcu', Adapter\ApcuAdapter::class], + 'Array adapter' => ['array', Adapter\ArrayAdapter::class], + 'File adapter' => ['file', Adapter\FilesystemAdapter::class], + 'Memcached adapter' => ['memcached', Adapter\MemcachedAdapter::class], + 'PHP files adapter' => ['php-file', Adapter\PhpFilesAdapter::class], + 'Redis adapter' => ['redis', Adapter\RedisAdapter::class], + ]; + } }