Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
ExtededTestdox.php
Go to the documentation of this file.
1 <?php
7 
8 class ExtededTestdox extends \PHPUnit_Util_Printer implements \PHPUnit\Framework\TestListener
9 {
13  protected $prettifier;
14 
18  protected $testClass = '';
19 
23  protected $testStatus = false;
24 
28  protected $tests = [];
29 
33  protected $successful = 0;
34 
38  protected $failed = 0;
39 
43  protected $skipped = 0;
44 
48  protected $incomplete = 0;
49 
53  protected $risky = 0;
54 
58  protected $testTypeOfInterest = \PHPUnit\Framework\TestCase::class;
59 
64 
69 
75  public function __construct($out = null)
76  {
77  parent::__construct($out);
78 
79  $this->prettifier = new \PHPUnit_Util_TestDox_NamePrettifier();
80  $this->startRun();
81  }
82 
87  public function flush()
88  {
89  $this->doEndClass();
90  $this->endRun();
91 
92  parent::flush();
93  }
94 
103  public function addError(\PHPUnit\Framework\Test $test, \Exception $e, $time)
104  {
105  if ($test instanceof $this->testTypeOfInterest) {
106  $this->testStatus = \PHPUnit_Runner_BaseTestRunner::STATUS_ERROR;
107  $this->failed++;
108  }
109  }
110 
119  public function addFailure(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\AssertionFailedError $e, $time)
120  {
121  if ($test instanceof $this->testTypeOfInterest) {
122  $this->testStatus = \PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE;
123  $this->failed++;
124  }
125  }
126 
135  public function addIncompleteTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
136  {
137  if ($test instanceof $this->testTypeOfInterest) {
138  $this->testStatus = \PHPUnit_Runner_BaseTestRunner::STATUS_INCOMPLETE;
139  $this->incomplete++;
140  }
141  }
142 
152  public function addSkippedTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
153  {
154  if ($test instanceof $this->testTypeOfInterest) {
155  $this->testStatus = \PHPUnit_Runner_BaseTestRunner::STATUS_SKIPPED;
156  $this->skipped++;
157  }
158  }
159 
169  public function addRiskyTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
170  {
171  if ($test instanceof $this->testTypeOfInterest) {
172  $this->testStatus = \PHPUnit_Runner_BaseTestRunner::STATUS_RISKY;
173  $this->risky++;
174  }
175  }
176 
184  public function startTestSuite(\PHPUnit\Framework\TestSuite $suite)
185  {
186  }
187 
195  public function endTestSuite(\PHPUnit\Framework\TestSuite $suite)
196  {
197  }
198 
204  public function startTest(\PHPUnit\Framework\Test $test)
205  {
206  if ($test instanceof $this->testTypeOfInterest) {
207  $class = get_class($test);
208 
209  if ($this->testClass != $class) {
210  if ($this->testClass != '') {
211  $this->doEndClass();
212  }
213 
214  $this->currentTestClassPrettified = $this->prettifier->prettifyTestClass($class);
215  $this->startClass($class);
216 
217  $this->testClass = $class;
218  $this->tests = [];
219  }
220  $this->write('.');
221  $this->currentTestMethodPrettified = $this->prettifier->prettifyTestMethod($test->getName(false));
222 
223  $this->testStatus = \PHPUnit_Runner_BaseTestRunner::STATUS_PASSED;
224  }
225  }
226 
233  public function endTest(\PHPUnit\Framework\Test $test, $time)
234  {
235  if ($test instanceof $this->testTypeOfInterest) {
236  if (!isset($this->tests[$this->currentTestMethodPrettified])) {
237  $this->tests[$this->currentTestMethodPrettified] = ['success' => 0, 'failure' => 0, 'time' => 0];
238  }
239 
240  if ($this->testStatus == \PHPUnit_Runner_BaseTestRunner::STATUS_PASSED) {
241  $this->tests[$this->currentTestMethodPrettified]['success']++;
242  }
243  if ($this->testStatus == \PHPUnit_Runner_BaseTestRunner::STATUS_ERROR) {
244  $this->tests[$this->currentTestMethodPrettified]['failure']++;
245  }
246  if ($this->testStatus == \PHPUnit_Runner_BaseTestRunner::STATUS_FAILURE) {
247  $this->tests[$this->currentTestMethodPrettified]['failure']++;
248  }
249  $this->tests[$this->currentTestMethodPrettified]['time'] += $time;
250  $this->currentTestClassPrettified = null;
251  $this->currentTestMethodPrettified = null;
252  }
253  }
254 
259  protected function startRun()
260  {
261  }
262 
267  protected function endRun()
268  {
269  }
270 
277  protected function startClass($name)
278  {
279  $this->write($this->currentTestClassPrettified . ' ');
280  }
281 
288  protected function endClass($name)
289  {
290  $this->write("\n");
291  }
292 
296  protected function doEndClass()
297  {
298  foreach ($this->tests as $name => $data) {
299  $check = $data['failure'] == 0 ? ' - [x] ' : ' - [ ] ';
300  $this->write(
301  "\n" . $check . $name . ($data['failure'] + $data['success'] ==
302  0 ? ' (skipped)' : '') . ($data['time'] > 1 ? ' - ' . number_format(
303  $data['time'],
304  2
305  ) . "s" : '')
306  );
307  }
308 
309  $this->endClass($this->testClass);
310  }
311 }
addIncompleteTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
startTestSuite(\PHPUnit\Framework\TestSuite $suite)
$_option $_optionId $class
Definition: date.phtml:13
addError(\PHPUnit\Framework\Test $test, \Exception $e, $time)
addSkippedTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
endTestSuite(\PHPUnit\Framework\TestSuite $suite)
addRiskyTest(\PHPUnit\Framework\Test $test, \Exception $e, $time)
endTest(\PHPUnit\Framework\Test $test, $time)
addFailure(\PHPUnit\Framework\Test $test, \PHPUnit\Framework\AssertionFailedError $e, $time)
startTest(\PHPUnit\Framework\Test $test)
if(!isset($_GET['name'])) $name
Definition: log.php:14