8 class CacheTest extends \PHPUnit\Framework\TestCase
29 $this->_cacheFrontendMock = $this->getMockForAbstractClass(
39 $frontendPoolMock = $this->createMock(\
Magento\Framework\
App\
Cache\Frontend\Pool::class);
40 $frontendPoolMock->expects($this->any())->method(
'valid')->will($this->onConsecutiveCalls(
true,
false));
42 $frontendPoolMock->expects(
47 $this->returnValue($this->_cacheFrontendMock)
49 $frontendPoolMock->expects(
56 $this->returnValue($this->_cacheFrontendMock)
59 $this->_model = new \Magento\Framework\App\Cache($frontendPoolMock);
68 \Magento\Framework\Cache\Frontend\Decorator\TagScope::class,
69 \Magento\Framework\Cache\Frontend\Decorator\Bare::class,
71 foreach ($cacheTypes as
$type) {
72 $this->_cacheTypeMocks[
$type] = $this->getMockBuilder(
$type)
73 ->setMethods([
'clean'])
76 $this->getMockForAbstractClass(\
Magento\Framework\
Cache\FrontendInterface::class),
' 92 return $this->_cacheTypeMocks[
$type];
97 $this->_cacheTypeMocks = [];
98 $this->_cacheFrontendMock =
null;
104 $this->assertSame($this->_cacheFrontendMock, $this->_model->getFrontend());
109 $frontend = $this->_model->getFrontend();
110 $this->assertSame($this->_cacheFrontendMock, $frontend);
115 $this->_cacheFrontendMock->expects(
122 $this->returnValue(
'test_data')
124 $this->assertEquals(
'test_data', $this->_model->load(
'test_id'));
136 public function testSave($inputData, $inputId, $inputTags, $expectedData, $expectedId, $expectedTags)
138 $this->_cacheFrontendMock->expects(
143 $this->identicalTo($expectedData),
147 $this->_model->save($inputData, $inputId, $inputTags);
157 'default tags' => [
'test_data',
'test_id', [],
'test_data',
'test_id', []],
166 'lowercase tags' => [
174 'non-string data' => [1234567890,
'test_id', [],
'1234567890',
'test_id', []]
184 $this->_cacheFrontendMock->expects(
193 $this->assertEquals(
$result, $this->_model->remove(
'test_id'));
201 return [
'success' => [
true],
'failure' => [
false]];
206 $expectedTags = [
'test_tag'];
207 $this->_cacheFrontendMock->expects(
215 $this->returnValue(
true)
217 $this->assertTrue($this->_model->clean($expectedTags));
222 $this->_cacheFrontendMock->expects(
229 $this->returnValue(
true)
231 $this->assertTrue($this->_model->clean());
testSave($inputData, $inputId, $inputTags, $expectedData, $expectedId, $expectedTags)
successFailureDataProvider()
const CLEANING_MODE_MATCHING_ANY_TAG