Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DecoratorAbstractTest.php
Go to the documentation of this file.
1 <?php
11 
12 class DecoratorAbstractTest extends \PHPUnit\Framework\TestCase
13 {
17  protected $_mockBackend;
18 
19  protected function setUp()
20  {
21  $this->_mockBackend = $this->createMock(\Zend_Cache_Backend_File::class);
22  }
23 
24  protected function tearDown()
25  {
26  unset($this->_mockBackend);
27  }
28 
29  public function testConstructor()
30  {
31  $options = ['concrete_backend' => $this->_mockBackend, 'testOption' => 'testOption'];
32 
33  $decorator = $this->getMockForAbstractClass(
34  \Magento\Framework\Cache\Backend\Decorator\AbstractDecorator::class,
35  [$options]
36  );
37 
38  $backendProperty = new \ReflectionProperty(
39  \Magento\Framework\Cache\Backend\Decorator\AbstractDecorator::class,
40  '_backend'
41  );
42  $backendProperty->setAccessible(true);
43 
44  $optionsProperty = new \ReflectionProperty(
45  \Magento\Framework\Cache\Backend\Decorator\AbstractDecorator::class,
46  '_decoratorOptions'
47  );
48  $optionsProperty->setAccessible(true);
49 
50  $this->assertSame($backendProperty->getValue($decorator), $this->_mockBackend);
51 
52  $this->assertArrayNotHasKey('concrete_backend', $optionsProperty->getValue($decorator));
53  $this->assertArrayNotHasKey('testOption', $optionsProperty->getValue($decorator));
54  }
55 
62  {
63  $this->getMockForAbstractClass(\Magento\Framework\Cache\Backend\Decorator\AbstractDecorator::class, [$options]);
64  }
65 
70  {
71  return [
72  'empty' => [[]],
73  'wrong_class' => [['concrete_backend' => $this->getMockBuilder('Test_Class')->getMock()]]
74  ];
75  }
76 
80  public function testAllMethods($methodName)
81  {
82  $this->_mockBackend->expects($this->once())->method($methodName);
83 
84  $decorator = $this->getMockForAbstractClass(
85  \Magento\Framework\Cache\Backend\Decorator\AbstractDecorator::class,
86  [['concrete_backend' => $this->_mockBackend]]
87  );
88 
89  call_user_func([$decorator, $methodName], null, null);
90  }
91 
95  public function allMethodsDataProvider()
96  {
97  $return = [];
98  $allMethods = [
99  'setDirectives',
100  'load',
101  'test',
102  'save',
103  'remove',
104  'clean',
105  'getIds',
106  'getTags',
107  'getIdsMatchingTags',
108  'getIdsNotMatchingTags',
109  'getIdsMatchingAnyTags',
110  'getFillingPercentage',
111  'getMetadatas',
112  'touch',
113  'getCapabilities',
114  'setOption',
115  'getLifetime',
116  'getTmpDir',
117  ];
118  foreach ($allMethods as $method) {
119  $return[$method] = [$method];
120  }
121  return $return;
122  }
123 }
$method
Definition: info.phtml:13