1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84
|
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/lgpl-3.0.html LGPL v3 or later
*/
namespace Tests\Matomo\Cache\Backend;
use Matomo\Cache\Backend\KeyPrefixDecorated;
use Matomo\Cache\Backend\NullCache;
use PHPUnit\Framework\TestCase;
/**
* @covers \Matomo\Cache\Backend\KeyPrefixDecorated
*/
class KeyPrefixTest extends TestCase
{
/**
* @var KeyPrefixDecorated
*/
private $cache;
/**
* @var NullCache
*/
private $backendMock;
private $keyPrefix = 'somePrefix';
public function setUp()
{
$this->backendMock = $this->getMockBuilder(NullCache::class)->getMock();
$opts = ['keyPrefix'=>$this->keyPrefix];
$this->cache = new KeyPrefixDecorated($this->backendMock, $opts);
}
public function test_doFetch_shouldCallDecoratedWithKeyPrefix()
{
$this->backendMock
->expects($this->once())
->method('doFetch')
->with($this->stringStartsWith($this->keyPrefix));
$this->cache->doFetch('randomid');
}
public function test_doContains_shouldCallDecoratedWithKeyPrefix()
{
$this->backendMock
->expects($this->once())
->method('doContains')
->with($this->stringStartsWith($this->keyPrefix));
$this->cache->doContains('randomid');
}
public function test_doSave_shouldCallDecoratedWithKeyPrefix()
{
$this->backendMock
->expects($this->once())
->method('doSave')
->with($this->stringStartsWith($this->keyPrefix),
$this->anything(),
$this->anything());
$this->cache->doSave('randomid', 'anyvalue');
}
public function test_doDelete_shouldCallDecoratedWithKeyPrefix()
{
$this->backendMock
->expects($this->once())
->method('doDelete')
->with($this->stringStartsWith($this->keyPrefix));
$this->cache->doDelete('randomid');
}
}
|