[Cache] Rely on mock for Doctrine ArrayCache

This commit is contained in:
Nicolas Grekas 2018-03-19 23:12:11 +01:00
parent 28f4662935
commit e4973ad8dc
5 changed files with 56 additions and 2 deletions

View File

@ -65,6 +65,7 @@
<element><string>Cache\IntegrationTests</string></element>
<element><string>Doctrine\Common\Cache</string></element>
<element><string>Symfony\Component\Cache</string></element>
<element><string>Symfony\Component\Cache\Tests\Fixtures</string></element>
<element><string>Symfony\Component\Cache\Traits</string></element>
<element><string>Symfony\Component\Console</string></element>
<element><string>Symfony\Component\HttpFoundation</string></element>

View File

@ -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

View File

@ -0,0 +1,52 @@
<?php
namespace Symfony\Component\Cache\Tests\Fixtures;
use Doctrine\Common\Cache\CacheProvider;
class ArrayCache extends CacheProvider
{
private $data = array();
protected function doFetch($id)
{
return $this->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;
}
}

View File

@ -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

View File

@ -39,6 +39,7 @@
<element><string>Cache\IntegrationTests</string></element>
<element><string>Doctrine\Common\Cache</string></element>
<element><string>Symfony\Component\Cache</string></element>
<element><string>Symfony\Component\Cache\Tests\Fixtures</string></element>
<element><string>Symfony\Component\Cache\Traits</string></element>
</array>
</element>