Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
FrontendPoolTest.php
Go to the documentation of this file.
1 <?php
7 
8 use \Magento\Framework\App\Cache\Type\FrontendPool;
9 
10 class FrontendPoolTest extends \PHPUnit\Framework\TestCase
11 {
15  protected $_model;
16 
20  protected $_objectManager;
21 
25  protected $deploymentConfig;
26 
30  protected $_cachePool;
31 
32  protected function setUp()
33  {
34  $this->_objectManager = $this->createMock(\Magento\Framework\ObjectManagerInterface::class);
35  $this->deploymentConfig = $this->createMock(\Magento\Framework\App\DeploymentConfig::class);
36  $this->_cachePool = $this->createMock(\Magento\Framework\App\Cache\Frontend\Pool::class);
37  $this->_model = new FrontendPool(
38  $this->_objectManager,
39  $this->deploymentConfig,
40  $this->_cachePool,
41  ['fixture_cache_type' => 'fixture_frontend_id']
42  );
43  }
44 
52  public function testGet($fixtureConfigData, $inputCacheType, $expectedFrontendId)
53  {
54  $this->deploymentConfig->expects(
55  $this->once()
56  )->method(
57  'getConfigData'
58  )->with(
60  )->will(
61  $this->returnValue($fixtureConfigData)
62  );
63 
64  $cacheFrontend = $this->createMock(\Magento\Framework\Cache\FrontendInterface::class);
65  $this->_cachePool->expects(
66  $this->once()
67  )->method(
68  'get'
69  )->with(
70  $expectedFrontendId
71  )->will(
72  $this->returnValue($cacheFrontend)
73  );
74 
75  $accessProxy = $this->createMock(\Magento\Framework\App\Cache\Type\AccessProxy::class);
76  $this->_objectManager->expects(
77  $this->once()
78  )->method(
79  'create'
80  )->with(
81  \Magento\Framework\App\Cache\Type\AccessProxy::class,
82  $this->identicalTo(['frontend' => $cacheFrontend, 'identifier' => $inputCacheType])
83  )->will(
84  $this->returnValue($accessProxy)
85  );
86 
87  $this->assertSame($accessProxy, $this->_model->get($inputCacheType));
88  // Result has to be cached in memory
89  $this->assertSame($accessProxy, $this->_model->get($inputCacheType));
90  }
91 
95  public function getDataProvider()
96  {
97  $configData1 = [
98  'frontend' => [],
99  'type' => ['fixture_cache_type' => ['frontend' => 'configured_frontend_id']],
100  ];
101  $configData2 = ['frontend' => [], 'type' => ['fixture_cache_type' => ['frontend' => null]]];
102  $configData3 = ['frontend' => [], 'type' => ['unknown_cache_type' => ['frontend' => null]]];
103  return [
104  'retrieval from config' => [$configData1, 'fixture_cache_type', 'configured_frontend_id'],
105  'retrieval from map' => [$configData2, 'fixture_cache_type', 'fixture_frontend_id'],
106  'fallback to default id' => [
107  $configData3,
108  'unknown_cache_type',
110  ]
111  ];
112  }
113 }
testGet($fixtureConfigData, $inputCacheType, $expectedFrontendId)