Skip to content

Commit 9780870

Browse files
committed
MTA-1276: Wrong tests number is displayed for functional tests on Bamboo
1 parent e9b1024 commit 9780870

File tree

5 files changed

+175
-86
lines changed

5 files changed

+175
-86
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
* Fixed wrong tests number is displayed for functional tests on Bamboo
12
* Fixed fatal error after create screenshot or report on Windows
23
* Implemented mechanism of applying 3rd party credentials
34
* Fixed setValue() method for StrictselectElement class

Magento/Mtf/System/JUnit.php

+33-28
Original file line numberDiff line numberDiff line change
@@ -52,44 +52,49 @@ public function __construct($out = null, $logIncompleteSkipped = false)
5252
public function endTest(\PHPUnit_Framework_Test $test, $time)
5353
{
5454
if (!$test instanceof \PHPUnit_Framework_Warning) {
55-
if ($this->attachCurrentTestCase) {
56-
if ($test instanceof \PHPUnit_Framework_TestCase) {
57-
$numAssertions = $test->getNumAssertions();
58-
$this->testSuiteAssertions[$this->testSuiteLevel] += $numAssertions;
55+
if ($test instanceof \PHPUnit_Framework_TestCase) {
56+
$numAssertions = $test->getNumAssertions();
57+
$this->testSuiteAssertions[$this->testSuiteLevel] += $numAssertions;
5958

60-
$this->currentTestCase->setAttribute('assertions', $numAssertions);
61-
}
59+
$this->currentTestCase->setAttribute('assertions', $numAssertions);
60+
}
6261

63-
$this->currentTestCase->setAttribute(
64-
'time',
65-
sprintf('%F', $time)
66-
);
62+
$this->currentTestCase->setAttribute(
63+
'time',
64+
sprintf('%F', $time)
65+
);
66+
67+
$class = new \ReflectionClass($test);
6768

68-
$class = new \ReflectionClass($test);
69+
$xpath = new \DOMXPath($this->document);
6970

70-
$xpath = new \DOMXPath($this->document);
71-
$query = '//testsuite[@name="' . $class->name . '"]';
72-
$entries = $xpath->query($query);
71+
$queryForRemoveEmptyTestSuite = '//testsuite/testsuite/testsuite/testsuite';
72+
$entriesForRemoveEmptyTestSuite = $xpath->query($queryForRemoveEmptyTestSuite)->item(0);
73+
if ($entriesForRemoveEmptyTestSuite) {
74+
$entriesForRemoveEmptyTestSuite->parentNode->removeChild($entriesForRemoveEmptyTestSuite);
75+
}
76+
77+
$query = '//testsuite[@name="' . $class->name . '"]';
78+
$entries = $xpath->query($query);
7379

74-
$entries->item(0)->appendChild($this->currentTestCase);
80+
$entries->item(0)->appendChild($this->currentTestCase);
7581

76-
$entries->item(0)->setAttribute("tests", $entries->item(0)->childNodes->length);
82+
$entries->item(0)->setAttribute("tests", $entries->item(0)->childNodes->length);
7783

78-
$errors = $xpath->query('//testsuite[@name="' . $class->name . '"]//error')->length;
79-
$entries->item(0)->setAttribute("errors", $errors);
84+
$errors = $xpath->query('//testsuite[@name="' . $class->name . '"]//error')->length;
85+
$entries->item(0)->setAttribute("errors", $errors);
8086

81-
$errors = $xpath->query('//testsuite[@name="' . $class->name . '"]//failure')->length;
82-
$entries->item(0)->setAttribute("failures", $errors);
87+
$errors = $xpath->query('//testsuite[@name="' . $class->name . '"]//failure')->length;
88+
$entries->item(0)->setAttribute("failures", $errors);
8389

84-
$entries->item(0)->setAttribute("time", $entries->item(0)->getAttribute("time") + $time);
90+
$entries->item(0)->setAttribute("time", $entries->item(0)->getAttribute("time") + $time);
8591

86-
if (method_exists($test, 'hasOutput') && $test->hasOutput()) {
87-
$systemOut = $this->document->createElement('system-out');
88-
$systemOut->appendChild(
89-
$this->document->createTextNode($test->getActualOutput())
90-
);
91-
$this->currentTestCase->appendChild($systemOut);
92-
}
92+
if (method_exists($test, 'hasOutput') && $test->hasOutput()) {
93+
$systemOut = $this->document->createElement('system-out');
94+
$systemOut->appendChild(
95+
$this->document->createTextNode($test->getActualOutput())
96+
);
97+
$this->currentTestCase->appendChild($systemOut);
9398
}
9499
}
95100

Magento/Mtf/TestCase/Injectable.php

+10
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,16 @@ public function setVariationName($variationName)
124124
$this->variationName = $variationName;
125125
}
126126

127+
/**
128+
* Get variation name
129+
*
130+
* @return string
131+
*/
132+
public function getVariationName()
133+
{
134+
return $this->variationName;
135+
}
136+
127137
/**
128138
* Run with Variations Iterator
129139
*

Magento/Mtf/TestRunner/Process/PHPUnitUtils.php

+42-54
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
/**
2727
* Class Process
28-
*
2928
*/
3029
class PHPUnitUtils extends \PHPUnit_Util_PHP
3130
{
@@ -38,9 +37,7 @@ class PHPUnitUtils extends \PHPUnit_Util_PHP
3837
*/
3938
public function runJob($job, array $settings = [])
4039
{
41-
throw new \PHPUnit_Framework_Exception(
42-
'Should not call this method.'
43-
);
40+
throw new \PHPUnit_Framework_Exception('Should not call this method.');
4441
}
4542

4643
/**
@@ -53,7 +50,7 @@ public function runJob($job, array $settings = [])
5350
*/
5451
protected function process($pipe, $job)
5552
{
56-
/* do nothing */
53+
//
5754
}
5855

5956
/**
@@ -76,11 +73,7 @@ public function processChildResult(
7673
$time = 0;
7774

7875
if (!empty($stderr)) {
79-
$result->addError(
80-
$test,
81-
new \PHPUnit_Framework_Exception(trim($stderr)),
82-
$time
83-
);
76+
$result->addError($test, new \PHPUnit_Framework_Exception(trim($stderr)), $time);
8477
} else {
8578
set_error_handler(
8679
function ($errno, $errstr, $errfile, $errline) {
@@ -98,11 +91,7 @@ function ($errno, $errstr, $errfile, $errline) {
9891
restore_error_handler();
9992
$childResult = false;
10093

101-
$result->addError(
102-
$test,
103-
new \PHPUnit_Framework_Exception(trim($stdout), 0, $e),
104-
$time
105-
);
94+
$result->addError($test, new \PHPUnit_Framework_Exception(trim($stdout), 0, $e), $time);
10695
}
10796

10897
if ($childResult !== false) {
@@ -116,9 +105,7 @@ function ($errno, $errstr, $errfile, $errline) {
116105
$childResult = $childResult['result'];
117106

118107
if ($result->getCollectCodeCoverageInformation()) {
119-
$result->getCodeCoverage()->merge(
120-
$childResult->getCodeCoverage()
121-
);
108+
$result->getCodeCoverage()->merge($childResult->getCodeCoverage());
122109
}
123110

124111
$time = $childResult->time();
@@ -129,38 +116,43 @@ function ($errno, $errstr, $errfile, $errline) {
129116
$failures = $childResult->failures();
130117

131118
if (!empty($notImplemented)) {
132-
$result->addError(
133-
$test,
134-
$this->getException($notImplemented[0]),
135-
$time
136-
);
137-
} elseif (!empty($risky)) {
138-
$result->addError(
139-
$test,
140-
$this->getException($risky[0]),
141-
$time
142-
);
143-
} elseif (!empty($skipped)) {
144-
$result->addError(
145-
$test,
146-
$this->getException($skipped[0]),
147-
$time
148-
);
149-
} elseif (!empty($errors)) {
150-
foreach ($errors as $error) {
151-
$result->addError(
152-
$test,
153-
$this->getException($error),
154-
$time
155-
);
119+
foreach ($notImplemented as $variation => $error) {
120+
$name = $test->getName();
121+
$test->setName($name . " variation $variation");
122+
$result->addError($test, $this->getException($error), $time);
123+
$test->setName($name);
156124
}
157-
} elseif (!empty($failures)) {
158-
foreach ($failures as $failure) {
159-
$result->addFailure(
160-
$test,
161-
$this->getException($failure),
162-
$time
163-
);
125+
}
126+
if (!empty($risky)) {
127+
foreach ($risky as $variation => $error) {
128+
$name = $test->getName();
129+
$test->setName($name . " variation $variation");
130+
$result->addError($test, $this->getException($error), $time);
131+
$test->setName($name);
132+
}
133+
}
134+
if (!empty($skipped)) {
135+
foreach ($skipped as $variation => $error) {
136+
$name = $test->getName();
137+
$test->setName($name . " variation $variation");
138+
$result->addError($test, $this->getException($error), $time);
139+
$test->setName($name);
140+
}
141+
}
142+
if (!empty($errors)) {
143+
foreach ($errors as $variation => $error) {
144+
$name = $test->getName();
145+
$test->setName($name . " variation $variation");
146+
$result->addError($test, $this->getException($error), $time);
147+
$test->setName($name);
148+
}
149+
}
150+
if (!empty($failures)) {
151+
foreach ($failures as $variation => $failure) {
152+
$name = $test->getName();
153+
$test->setName($name . " variation $variation");
154+
$result->addFailure($test, $this->getException($failure), $time);
155+
$test->setName($name);
164156
}
165157
}
166158
}
@@ -189,11 +181,7 @@ public function getException(\PHPUnit_Framework_TestFailure $error)
189181
}
190182

191183
$exception = new \PHPUnit_Framework_SyntheticError(
192-
sprintf(
193-
'%s: %s',
194-
$exceptionArray['_PHP_Incomplete_Class_Name'],
195-
$exceptionArray['message']
196-
),
184+
sprintf('%s: %s', $exceptionArray['_PHP_Incomplete_Class_Name'], $exceptionArray['message']),
197185
$exceptionArray['code'],
198186
$exceptionArray['file'],
199187
$exceptionArray['line'],

Magento/Mtf/TestRunner/Process/TestResult.php

+89-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use Magento\Mtf\TestRunner\Process\Exception\Skipped;
2929
use Magento\Mtf\TestRunner\Process\Exception\Risky;
3030
use Magento\Mtf\TestRunner\Process\Exception\Incomplete;
31+
use Magento\Mtf\TestCase\Injectable;
3132

3233
/**
3334
* Class ProcessTestResult
@@ -48,21 +49,105 @@ class TestResult extends \PHPUnit_Framework_TestResult
4849
*/
4950
public function addError(\PHPUnit_Framework_Test $test, \Exception $e, $time)
5051
{
51-
parent::addError($test, $this->wrapException($e), $time);
52+
$variation = 0;
53+
if ($test instanceof Injectable) {
54+
$variation = $test->getVariationName();
55+
}
56+
57+
if ($e instanceof \PHPUnit_Framework_RiskyTest) {
58+
$this->risky[$variation] = new \PHPUnit_Framework_TestFailure($test, $e);
59+
60+
$notifyMethod = 'addRiskyTest';
61+
62+
if ($this->stopOnRisky) {
63+
$this->stop();
64+
}
65+
} elseif ($e instanceof \PHPUnit_Framework_IncompleteTest) {
66+
$this->notImplemented[$variation] = new \PHPUnit_Framework_TestFailure($test, $e);
67+
68+
$notifyMethod = 'addIncompleteTest';
69+
70+
if ($this->stopOnIncomplete) {
71+
$this->stop();
72+
}
73+
} elseif ($e instanceof \PHPUnit_Framework_SkippedTest) {
74+
$this->skipped[$variation] = new \PHPUnit_Framework_TestFailure($test, $e);
75+
$notifyMethod = 'addSkippedTest';
76+
77+
if ($this->stopOnSkipped) {
78+
$this->stop();
79+
}
80+
} else {
81+
$this->errors[$variation] = new \PHPUnit_Framework_TestFailure($test, $e);
82+
$notifyMethod = 'addError';
83+
84+
if ($this->stopOnError || $this->stopOnFailure) {
85+
$this->stop();
86+
}
87+
}
88+
89+
foreach ($this->listeners as $listener) {
90+
$listener->$notifyMethod($test, $e, $time);
91+
}
92+
93+
$this->lastTestFailed = true;
94+
$this->time += $time;
5295
}
5396

5497
/**
5598
* Adds a failure to the list of failures.
5699
* The passed in exception caused the failure.
57100
*
58-
* @param \PHPUnit_Framework_Test $test
101+
* @param \PHPUnit_Framework_Test $test
59102
* @param \PHPUnit_Framework_AssertionFailedError $e
60-
* @param float $time
103+
* @param float $time
61104
* @return void
62105
*/
63106
public function addFailure(\PHPUnit_Framework_Test $test, \PHPUnit_Framework_AssertionFailedError $e, $time)
64107
{
65-
parent::addFailure($test, $this->wrapException($e), $time);
108+
$variation = null;
109+
if ($test instanceof \Magento\Mtf\TestCase\Functional) {
110+
$variation = $test->getVariationName();
111+
}
112+
113+
if ($e instanceof \PHPUnit_Framework_RiskyTest) {
114+
$this->risky[$variation] = new \PHPUnit_Framework_TestFailure($test, $e);
115+
116+
$notifyMethod = 'addRiskyTest';
117+
118+
if ($this->stopOnRisky) {
119+
$this->stop();
120+
}
121+
} elseif ($e instanceof \PHPUnit_Framework_IncompleteTest) {
122+
$this->notImplemented[$variation] = new \PHPUnit_Framework_TestFailure($test, $e);
123+
124+
$notifyMethod = 'addIncompleteTest';
125+
126+
if ($this->stopOnIncomplete) {
127+
$this->stop();
128+
}
129+
} elseif ($e instanceof \PHPUnit_Framework_SkippedTest) {
130+
$this->skipped[$variation] = new \PHPUnit_Framework_TestFailure($test, $e);
131+
$notifyMethod = 'addSkippedTest';
132+
133+
if ($this->stopOnSkipped) {
134+
$this->stop();
135+
}
136+
} else {
137+
$this->failures[$variation] = new \PHPUnit_Framework_TestFailure($test, $e);
138+
$notifyMethod = 'addFailure';
139+
140+
if ($this->stopOnFailure) {
141+
$this->stop();
142+
}
143+
}
144+
145+
foreach ($this->listeners as $listener) {
146+
$listener->$notifyMethod($test, $e, $time);
147+
}
148+
149+
$this->lastTestFailed = true;
150+
$this->time += $time;
66151
}
67152

68153
/**

0 commit comments

Comments
 (0)