1
0
mirror of synced 2025-02-03 13:59:27 +03:00
doctrine2/tests/Doctrine/Tests/ORM/Cache/AbstractRegionTest.php

86 lines
2.1 KiB
PHP
Raw Normal View History

2013-02-13 20:42:13 -02:00
<?php
namespace Doctrine\Tests\ORM\Cache;
use Doctrine\Tests\OrmFunctionalTestCase;
use Doctrine\Tests\Mocks\CacheEntryMock;
use Doctrine\Tests\Mocks\CacheKeyMock;
use Doctrine\Common\Cache\ArrayCache;
/**
* @group DDC-2183
*/
abstract class AbstractRegionTest extends OrmFunctionalTestCase
{
/**
* @var \Doctrine\ORM\Cache\Region
*/
protected $region;
/**
* @var \Doctrine\Common\Cache\ArrayCache
*/
protected $cache;
protected function setUp()
{
parent::setUp();
$this->cache = new ArrayCache();
$this->region = $this->createRegion();
}
/**
* @return \Doctrine\ORM\Cache\Region
*/
protected abstract function createRegion();
static public function dataProviderCacheValues()
{
return [
[new CacheKeyMock('key.1'), new CacheEntryMock(['id'=>1, 'name' => 'bar'])],
[new CacheKeyMock('key.2'), new CacheEntryMock(['id'=>2, 'name' => 'foo'])],
];
2013-02-13 20:42:13 -02:00
}
/**
* @dataProvider dataProviderCacheValues
*/
public function testPutGetContainsEvict($key, $value)
{
$this->assertFalse($this->region->contains($key));
$this->region->put($key, $value);
$this->assertTrue($this->region->contains($key));
$actual = $this->region->get($key);
$this->assertEquals($value, $actual);
2013-02-13 20:42:13 -02:00
$this->region->evict($key);
$this->assertFalse($this->region->contains($key));
}
public function testEvictAll()
{
$key1 = new CacheKeyMock('key.1');
$key2 = new CacheKeyMock('key.2');
$this->assertFalse($this->region->contains($key1));
$this->assertFalse($this->region->contains($key2));
$this->region->put($key1, new CacheEntryMock(['value' => 'foo']));
$this->region->put($key2, new CacheEntryMock(['value' => 'bar']));
2013-02-13 20:42:13 -02:00
$this->assertTrue($this->region->contains($key1));
$this->assertTrue($this->region->contains($key2));
$this->region->evictAll();
$this->assertFalse($this->region->contains($key1));
$this->assertFalse($this->region->contains($key2));
}
}