From e4973ad8dcc3b30ea2116d8b933e098ffee1e40f Mon Sep 17 00:00:00 2001 From: Nicolas Grekas Date: Mon, 19 Mar 2018 23:12:11 +0100 Subject: [PATCH] [Cache] Rely on mock for Doctrine ArrayCache --- phpunit.xml.dist | 1 + .../Tests/Adapter/DoctrineAdapterTest.php | 2 +- .../Cache/Tests/Fixtures/ArrayCache.php | 52 +++++++++++++++++++ .../Cache/Tests/Simple/DoctrineCacheTest.php | 2 +- src/Symfony/Component/Cache/phpunit.xml.dist | 1 + 5 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 src/Symfony/Component/Cache/Tests/Fixtures/ArrayCache.php diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e44535a81a..59ec772525 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -65,6 +65,7 @@ Cache\IntegrationTests Doctrine\Common\Cache Symfony\Component\Cache + Symfony\Component\Cache\Tests\Fixtures Symfony\Component\Cache\Traits Symfony\Component\Console Symfony\Component\HttpFoundation diff --git a/src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php b/src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php index 93ec982438..8d4dfe2858 100644 --- a/src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php +++ b/src/Symfony/Component/Cache/Tests/Adapter/DoctrineAdapterTest.php @@ -11,8 +11,8 @@ namespace Symfony\Component\Cache\Tests\Adapter; -use Doctrine\Common\Cache\ArrayCache; use Symfony\Component\Cache\Adapter\DoctrineAdapter; +use Symfony\Component\Cache\Tests\Fixtures\ArrayCache; /** * @group time-sensitive diff --git a/src/Symfony/Component/Cache/Tests/Fixtures/ArrayCache.php b/src/Symfony/Component/Cache/Tests/Fixtures/ArrayCache.php new file mode 100644 index 0000000000..1a6157e822 --- /dev/null +++ b/src/Symfony/Component/Cache/Tests/Fixtures/ArrayCache.php @@ -0,0 +1,52 @@ +doContains($id) ? $this->data[$id][0] : false; + } + + protected function doContains($id) + { + if (!isset($this->data[$id])) { + return false; + } + + $expiry = $this->data[$id][1]; + + return !$expiry || time() <= $expiry || !$this->doDelete($id); + } + + protected function doSave($id, $data, $lifeTime = 0) + { + $this->data[$id] = array($data, $lifeTime ? time() + $lifeTime : false); + + return true; + } + + protected function doDelete($id) + { + unset($this->data[$id]); + + return true; + } + + protected function doFlush() + { + $this->data = array(); + + return true; + } + + protected function doGetStats() + { + return null; + } +} diff --git a/src/Symfony/Component/Cache/Tests/Simple/DoctrineCacheTest.php b/src/Symfony/Component/Cache/Tests/Simple/DoctrineCacheTest.php index 0a185297ab..127c96858c 100644 --- a/src/Symfony/Component/Cache/Tests/Simple/DoctrineCacheTest.php +++ b/src/Symfony/Component/Cache/Tests/Simple/DoctrineCacheTest.php @@ -11,8 +11,8 @@ namespace Symfony\Component\Cache\Tests\Simple; -use Doctrine\Common\Cache\ArrayCache; use Symfony\Component\Cache\Simple\DoctrineCache; +use Symfony\Component\Cache\Tests\Fixtures\ArrayCache; /** * @group time-sensitive diff --git a/src/Symfony/Component/Cache/phpunit.xml.dist b/src/Symfony/Component/Cache/phpunit.xml.dist index 6b5c79331d..9b3c30d76f 100644 --- a/src/Symfony/Component/Cache/phpunit.xml.dist +++ b/src/Symfony/Component/Cache/phpunit.xml.dist @@ -39,6 +39,7 @@ Cache\IntegrationTests Doctrine\Common\Cache Symfony\Component\Cache + Symfony\Component\Cache\Tests\Fixtures Symfony\Component\Cache\Traits