Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
PhpUnit.php
Go to the documentation of this file.
1 <?php
11 
12 class PhpUnit implements \PHPUnit\Framework\TestListener
13 {
19  protected static $_defaultEventManager;
20 
24  protected $_eventManager;
25 
31  public static function setDefaultEventManager(\Magento\TestFramework\EventManager $eventManager = null)
32  {
33  self::$_defaultEventManager = $eventManager;
34  }
35 
42  public function __construct(\Magento\TestFramework\EventManager $eventManager = null)
43  {
44  $this->_eventManager = $eventManager ?: self::$_defaultEventManager;
45  if (!$this->_eventManager) {
46  throw new \Magento\Framework\Exception\LocalizedException(__('Instance of the event manager is required.'));
47  }
48  }
49 
55  public function addError(\PHPUnit\Framework\Test $test, \Exception $e, $time)
56  {
57  }
58 
64  public function addFailure(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\AssertionFailedError $e, $time)
65  {
66  }
67 
73  public function addIncompleteTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
74  {
75  }
76 
82  public function addRiskyTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
83  {
84  }
85 
91  public function addSkippedTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
92  {
93  }
94 
98  public function startTestSuite(\PHPUnit\Framework\TestSuite $suite)
99  {
100  /* PHPUnit runs tests with data provider in own test suite for each test, so just skip such test suites */
101  if ($suite instanceof \PHPUnit\Framework\DataProviderTestSuite) {
102  return;
103  }
104  $this->_eventManager->fireEvent('startTestSuite');
105  }
106 
110  public function endTestSuite(\PHPUnit\Framework\TestSuite $suite)
111  {
112  if ($suite instanceof \PHPUnit\Framework\DataProviderTestSuite) {
113  return;
114  }
115  $this->_eventManager->fireEvent('endTestSuite', [$suite], true);
116  }
117 
121  public function startTest(\PHPUnit\Framework\Test $test)
122  {
123  if (!$test instanceof \PHPUnit\Framework\TestCase || $test instanceof \PHPUnit\Framework\Warning) {
124  return;
125  }
126  $this->_eventManager->fireEvent('startTest', [$test]);
127  }
128 
133  public function endTest(\PHPUnit\Framework\Test $test, $time)
134  {
135  if (!$test instanceof \PHPUnit\Framework\TestCase || $test instanceof \PHPUnit\Framework\Warning) {
136  return;
137  }
138  $this->_eventManager->fireEvent('endTest', [$test], true);
139  }
140 
144  public function addWarning(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\Warning $e, $time)
145  {
146  }
147 }
addSkippedTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
Definition: PhpUnit.php:91
addFailure(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\AssertionFailedError $e, $time)
Definition: PhpUnit.php:64
__construct(\Magento\TestFramework\EventManager $eventManager=null)
Definition: PhpUnit.php:42
addIncompleteTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
Definition: PhpUnit.php:73
__()
Definition: __.php:13
startTestSuite(\PHPUnit\Framework\TestSuite $suite)
Definition: PhpUnit.php:98
startTest(\PHPUnit\Framework\Test $test)
Definition: PhpUnit.php:121
addWarning(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\Warning $e, $time)
Definition: PhpUnit.php:144
static setDefaultEventManager(\Magento\TestFramework\EventManager $eventManager=null)
Definition: PhpUnit.php:31
addRiskyTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
Definition: PhpUnit.php:82
endTestSuite(\PHPUnit\Framework\TestSuite $suite)
Definition: PhpUnit.php:110
addError(\PHPUnit\Framework\Test $test, \Exception $e, $time)
Definition: PhpUnit.php:55
endTest(\PHPUnit\Framework\Test $test, $time)
Definition: PhpUnit.php:133