1
0
mirror of synced 2024-12-14 15:16:04 +03:00
doctrine2/tests/Doctrine/Tests/Mocks/CacheRegionMock.php

78 lines
1.7 KiB
PHP
Raw Normal View History

2013-02-14 02:42:13 +04:00
<?php
namespace Doctrine\Tests\Mocks;
use Doctrine\ORM\Cache\CacheEntry;
use Doctrine\ORM\Cache\CacheKey;
use Doctrine\ORM\Cache\Lock;
use Doctrine\ORM\Cache\Region;
class CacheRegionMock implements Region
{
public $calls = array();
public $returns = array();
public $name;
public function addReturn($method, $value)
{
$this->returns[$method][] = $value;
}
2013-10-08 02:53:32 +04:00
public function getReturn($method, $default)
2013-02-14 02:42:13 +04:00
{
if (isset($this->returns[$method]) && ! empty($this->returns[$method])) {
return array_shift($this->returns[$method]);
}
2013-10-08 02:53:32 +04:00
return $default;
2013-02-14 02:42:13 +04:00
}
public function getName()
{
$this->calls[__FUNCTION__][] = array();
return $this->name;
}
public function contains(CacheKey $key)
{
$this->calls[__FUNCTION__][] = array('key' => $key);
return $this->getReturn(__FUNCTION__, false);
}
public function evict(CacheKey $key)
{
$this->calls[__FUNCTION__][] = array('key' => $key);
return $this->getReturn(__FUNCTION__, true);
}
public function evictAll()
{
$this->calls[__FUNCTION__][] = array();
return $this->getReturn(__FUNCTION__, true);
}
public function get(CacheKey $key)
{
$this->calls[__FUNCTION__][] = array('key' => $key);
return $this->getReturn(__FUNCTION__, null);
}
public function put(CacheKey $key, CacheEntry $entry, Lock $lock = null)
{
$this->calls[__FUNCTION__][] = array('key' => $key, 'entry' => $entry);
return $this->getReturn(__FUNCTION__, true);
}
public function clear()
{
$this->calls = array();
$this->returns = array();
}
}