Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AccessProxyTest.php
Go to the documentation of this file.
1 <?php
7 
8 class AccessProxyTest extends \PHPUnit\Framework\TestCase
9 {
17  public function testProxyMethod($method, $params, $disabledResult, $enabledResult)
18  {
19  $identifier = 'cache_type_identifier';
20 
21  $frontendMock = $this->createMock(\Magento\Framework\Cache\FrontendInterface::class);
22 
23  $cacheEnabler = $this->createMock(\Magento\Framework\App\Cache\StateInterface::class);
24  $cacheEnabler->expects($this->at(0))->method('isEnabled')->with($identifier)->will($this->returnValue(false));
25  $cacheEnabler->expects($this->at(1))->method('isEnabled')->with($identifier)->will($this->returnValue(true));
26 
27  $object = new \Magento\Framework\App\Cache\Type\AccessProxy($frontendMock, $cacheEnabler, $identifier);
28  $helper = new \Magento\Framework\TestFramework\Unit\Helper\ProxyTesting();
29 
30  // For the first call the cache is disabled - so fake default result is returned
31  $result = $helper->invokeWithExpectations($object, $frontendMock, $method, $params, $enabledResult);
32  $this->assertSame($disabledResult, $result);
33 
34  // For the second call the cache is enabled - so real cache result is returned
35  $result = $helper->invokeWithExpectations($object, $frontendMock, $method, $params, $enabledResult);
36  $this->assertSame($enabledResult, $result);
37  }
38 
42  public static function proxyMethodDataProvider()
43  {
44  return [
45  ['test', ['record_id'], false, 111],
46  ['load', ['record_id'], false, '111'],
47  ['save', ['record_value', 'record_id', ['tag'], 555], true, false],
48  ['remove', ['record_id'], true, false],
49  ['clean', [\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, ['tag']], true, false]
50  ];
51  }
52 }
$helper
Definition: iframe.phtml:13
testProxyMethod($method, $params, $disabledResult, $enabledResult)
$method
Definition: info.phtml:13
const CLEANING_MODE_MATCHING_ANY_TAG
Definition: Cache.php:76
$params[\Magento\Store\Model\StoreManager::PARAM_RUN_CODE]
Definition: website.php:18