Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AppAreaTest.php
Go to the documentation of this file.
1 <?php
8 
10 
11 class AppAreaTest extends \PHPUnit\Framework\TestCase
12 {
16  protected $_object;
17 
21  protected $_applicationMock;
22 
26  protected $_testCaseMock;
27 
28  protected function setUp()
29  {
30  $this->_testCaseMock = $this->createMock(\PHPUnit\Framework\TestCase::class);
31  $this->_applicationMock = $this->createMock(\Magento\TestFramework\Application::class);
32  $this->_object = new \Magento\TestFramework\Annotation\AppArea($this->_applicationMock);
33  }
34 
40  public function testGetTestAppArea($annotations, $expectedArea)
41  {
42  $this->_testCaseMock->expects($this->once())->method('getAnnotations')->will($this->returnValue($annotations));
43  $this->_applicationMock->expects($this->any())->method('getArea')->will($this->returnValue(null));
44  $this->_applicationMock->expects($this->once())->method('reinitialize');
45  $this->_applicationMock->expects($this->once())->method('loadArea')->with($expectedArea);
46  $this->_object->startTest($this->_testCaseMock);
47  }
48 
49  public function getTestAppAreaDataProvider()
50  {
51  return [
52  'method scope' => [['method' => ['magentoAppArea' => ['adminhtml']]], 'adminhtml'],
53  'class scope' => [['class' => ['magentoAppArea' => ['frontend']]], 'frontend'],
54  'mixed scope' => [
55  [
56  'class' => ['magentoAppArea' => ['adminhtml']],
57  'method' => ['magentoAppArea' => ['frontend']],
58  ],
59  'frontend',
60  ],
61  'default area' => [[], 'global']
62  ];
63  }
64 
69  {
70  $annotations = ['method' => ['magentoAppArea' => ['some_invalid_area']]];
71  $this->_testCaseMock->expects($this->once())->method('getAnnotations')->will($this->returnValue($annotations));
72  $this->_object->startTest($this->_testCaseMock);
73  }
74 
81  public function testStartTestWithDifferentAreaCodes(string $areaCode)
82  {
83  $annotations = ['method' => ['magentoAppArea' => [$areaCode]]];
84  $this->_testCaseMock->expects($this->once())->method('getAnnotations')->will($this->returnValue($annotations));
85  $this->_applicationMock->expects($this->any())->method('getArea')->willReturn(null);
86  $this->_applicationMock->expects($this->once())->method('reinitialize');
87  $this->_applicationMock->expects($this->once())->method('loadArea')->with($areaCode);
88  $this->_object->startTest($this->_testCaseMock);
89  }
90 
92  {
93  $annotations = ['method' => ['magentoAppArea' => ['global']]];
94  $this->_testCaseMock->expects($this->once())->method('getAnnotations')->will($this->returnValue($annotations));
95  $this->_applicationMock->expects($this->at(0))->method('getArea')->will($this->returnValue('adminhtml'));
96  $this->_applicationMock->expects($this->once())->method('reinitialize');
97  $this->_applicationMock->expects($this->at(2))->method('getArea')->will($this->returnValue('global'));
98  $this->_applicationMock->expects($this->never())->method('loadArea');
99  $this->_object->startTest($this->_testCaseMock);
100  }
101 
103  {
104  $annotations = ['method' => ['magentoAppArea' => ['adminhtml']]];
105  $this->_testCaseMock->expects($this->once())->method('getAnnotations')->will($this->returnValue($annotations));
106  $this->_applicationMock->expects($this->once())->method('getArea')->will($this->returnValue('adminhtml'));
107  $this->_applicationMock->expects($this->never())->method('reinitialize');
108  $this->_applicationMock->expects($this->never())->method('loadArea');
109  $this->_object->startTest($this->_testCaseMock);
110  }
111 
118  {
119  return [
120  [
121  'area_code' => Area::AREA_GLOBAL,
122  ],
123  [
124  'area_code' => Area::AREA_ADMINHTML,
125  ],
126  [
127  'area_code' => Area::AREA_FRONTEND,
128  ],
129  [
130  'area_code' => Area::AREA_WEBAPI_REST,
131  ],
132  [
133  'area_code' => Area::AREA_WEBAPI_SOAP,
134  ],
135  [
136  'area_code' => Area::AREA_CRONTAB,
137  ],
138  [
139  'area_code' => Area::AREA_GRAPHQL,
140  ],
141  ];
142  }
143 }
testGetTestAppArea($annotations, $expectedArea)
Definition: AppAreaTest.php:40
testStartTestWithDifferentAreaCodes(string $areaCode)
Definition: AppAreaTest.php:81