Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
AppArea.php
Go to the documentation of this file.
1 <?php
7 
8 class AppArea
9 {
10  const ANNOTATION_NAME = 'magentoAppArea';
11 
15  private $_application;
16 
22  private $_allowedAreas = [
30  ];
31 
35  public function __construct(\Magento\TestFramework\Application $application)
36  {
37  $this->_application = $application;
38  }
39 
47  protected function _getTestAppArea($annotations)
48  {
49  $area = isset(
50  $annotations['method'][self::ANNOTATION_NAME]
51  ) ? current(
52  $annotations['method'][self::ANNOTATION_NAME]
53  ) : (isset(
54  $annotations['class'][self::ANNOTATION_NAME]
55  ) ? current(
56  $annotations['class'][self::ANNOTATION_NAME]
58 
59  if (false == in_array($area, $this->_allowedAreas)) {
60  throw new \Magento\Framework\Exception\LocalizedException(
61  __(
62  'Invalid "@magentoAppArea" annotation, can be "%1" only.',
63  implode('", "', $this->_allowedAreas)
64  )
65  );
66  }
67 
68  return $area;
69  }
70 
76  public function startTest(\PHPUnit\Framework\TestCase $test)
77  {
78  $area = $this->_getTestAppArea($test->getAnnotations());
79  if ($this->_application->getArea() !== $area) {
80  $this->_application->reinitialize();
81 
82  if ($this->_application->getArea() !== $area) {
83  $this->_application->loadArea($area);
84  }
85  }
86  }
87 }
__construct(\Magento\TestFramework\Application $application)
Definition: AppArea.php:35
startTest(\PHPUnit\Framework\TestCase $test)
Definition: AppArea.php:76
__()
Definition: __.php:13
$application
Definition: bootstrap.php:58