Skip to content

Commit f4c9bf0

Browse files
committed
ACP2E-3334: [Internal] Fixture apply failure is not shown during execution or in logs
1 parent 6428bc7 commit f4c9bf0

13 files changed

+157
-146
lines changed

dev/tests/integration/framework/Magento/TestFramework/Annotation/AbstractDataFixture.php

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2020 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -11,8 +11,6 @@
1111
use Magento\TestFramework\Helper\Bootstrap;
1212
use Magento\TestFramework\Workaround\Override\Fixture\Resolver;
1313
use PHPUnit\Framework\TestCase;
14-
use ReflectionClass;
15-
use ReflectionException;
1614

1715
/**
1816
* Class consist of dataFixtures base logic
@@ -65,9 +63,8 @@ protected function _getFixtures(TestCase $test, $scope = null)
6563
} catch (\Throwable $exception) {
6664
ExceptionHandler::handle(
6765
'Unable to parse fixtures',
68-
get_class($test),
69-
$test->name(),
70-
$exception
66+
$exception,
67+
$test
7168
);
7269
}
7370

@@ -125,8 +122,6 @@ protected function _applyFixtures(array $fixtures, TestCase $test)
125122
} catch (\Throwable $exception) {
126123
ExceptionHandler::handle(
127124
'Unable to apply fixture: ' . $this->getFixtureReference($fixture),
128-
$fixture['test']['class'],
129-
$fixture['test']['method'],
130125
$exception,
131126
$test
132127
);
@@ -156,8 +151,6 @@ protected function _revertFixtures(?TestCase $test = null)
156151
} catch (\Throwable $exception) {
157152
ExceptionHandler::handle(
158153
'Unable to revert fixture: ' . $this->getFixtureReference($fixture),
159-
$fixture['test']['class'],
160-
$fixture['test']['method'],
161154
$exception,
162155
$test
163156
);

dev/tests/integration/framework/Magento/TestFramework/Annotation/AppArea.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2013 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\TestFramework\Annotation;
77

@@ -88,9 +88,8 @@ public function startTest(TestCase $test)
8888
} catch (\Throwable $exception) {
8989
ExceptionHandler::handle(
9090
'Unable to parse fixtures',
91-
get_class($test),
92-
null,
93-
$exception
91+
$exception,
92+
$test
9493
);
9594
}
9695

dev/tests/integration/framework/Magento/TestFramework/Annotation/AppIsolation.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
5-
*/
6-
7-
/**
8-
* Implementation of the @magentoAppIsolation DocBlock annotation - isolation of global application objects in memory
3+
* Copyright 2011 Adobe
4+
* All Rights Reserved.
95
*/
106
namespace Magento\TestFramework\Annotation;
117

@@ -16,6 +12,9 @@
1612
use Magento\TestFramework\TestCase\AbstractController;
1713
use PHPUnit\Framework\TestCase;
1814

15+
/**
16+
* Implementation of the @magentoAppIsolation DocBlock annotation - isolation of global application objects in memory
17+
*/
1918
class AppIsolation
2019
{
2120
/**
@@ -91,9 +90,8 @@ public function endTest(TestCase $test)
9190
} catch (\Throwable $exception) {
9291
ExceptionHandler::handle(
9392
'Unable to parse annotations',
94-
get_class($test),
95-
$test->name(),
96-
$exception
93+
$exception,
94+
$test
9795
);
9896
}
9997
if ($values) {

dev/tests/integration/framework/Magento/TestFramework/Annotation/Cache.php

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2014 Adobe
4+
* All Rights Reserved.
55
*/
6-
76
namespace Magento\TestFramework\Annotation;
87

98
use Magento\TestFramework\Fixture\ParserInterface;
@@ -36,9 +35,8 @@ public function startTest(TestCase $test)
3635
} catch (\Throwable $exception) {
3736
ExceptionHandler::handle(
3837
'Unable to parse fixtures',
39-
get_class($test),
40-
$test->getName(false),
41-
$exception
38+
$exception,
39+
$test
4240
);
4341
}
4442

@@ -93,8 +91,7 @@ private function setValues($values, TestCase $test)
9391
if (!isset($this->origValues[$type])) {
9492
ExceptionHandler::handle(
9593
"Unknown cache type specified: '{$type}' in @magentoCache",
96-
get_class($test),
97-
$test->getName(false)
94+
test: $test
9895
);
9996
}
10097
$states->setEnabled($type, $isEnabled);

dev/tests/integration/framework/Magento/TestFramework/Annotation/ComponentRegistrarFixture.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2015 Adobe
4+
* All Rights Reserved.
55
*/
6-
76
namespace Magento\TestFramework\Annotation;
87

98
use FilesystemIterator;
@@ -98,9 +97,8 @@ private function registerComponents(TestCase $test)
9897
} catch (Throwable $exception) {
9998
ExceptionHandler::handle(
10099
'Unable to parse fixtures',
101-
get_class($test),
102-
$test->getName(false),
103-
$exception
100+
$exception,
101+
$test
104102
);
105103
}
106104
if (!$values) {

dev/tests/integration/framework/Magento/TestFramework/Annotation/DbIsolation.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2012 Adobe
4+
* All Rights Reserved.
55
*/
66
namespace Magento\TestFramework\Annotation;
77

8-
use Magento\Framework\Exception\LocalizedException;
98
use Magento\TestFramework\Event\Param\Transaction;
109
use Magento\TestFramework\Helper\Bootstrap;
1110
use PHPUnit\Framework\TestCase;
@@ -91,9 +90,8 @@ protected function _getIsolation(TestCase $test)
9190
} catch (\Throwable $exception) {
9291
ExceptionHandler::handle(
9392
'Unable to parse fixtures',
94-
get_class($test),
95-
$test->name(),
96-
$exception
93+
$exception,
94+
$test
9795
);
9896
}
9997
return $state;
Lines changed: 14 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,98 +1,40 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2022 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

88
namespace Magento\TestFramework\Annotation;
99

10+
use PHPUnit\Event\Code\ThrowableBuilder;
1011
use PHPUnit\Framework\Exception;
1112
use PHPUnit\Framework\TestCase;
12-
use ReflectionClass;
13-
use ReflectionException;
1413

1514
class ExceptionHandler
1615
{
1716
/**
18-
* Format exception message and throws PHPUnit\Framework\Exception
17+
* Throws \PHPUnit\Framework\Exception and fail the test if provided.
1918
*
2019
* @param string $message
21-
* @param string $testClass
22-
* @param string|null $testMethod
2320
* @param \Throwable|null $previous
2421
* @param TestCase|null $test
25-
* @return void
22+
* @return never
23+
* @throws Exception
2624
*/
2725
public static function handle(
2826
string $message,
29-
string $testClass,
30-
string $testMethod = null,
31-
\Throwable $previous = null,
32-
TestCase $test = null
33-
): void {
34-
try {
35-
$reflected = new ReflectionClass($testClass);
36-
} catch (ReflectionException $e) {
37-
throw new Exception(
38-
$e->getMessage(),
39-
(int) $e->getCode(),
40-
$e
41-
);
27+
?\Throwable $previous = null,
28+
?TestCase $test = null
29+
): never {
30+
if (!$test) {
31+
throw new Exception($message, 0, $previous);
4232
}
4333

44-
$name = $testMethod;
45-
46-
if ($name && $reflected->hasMethod($name)) {
47-
try {
48-
$reflected = $reflected->getMethod($name);
49-
} catch (ReflectionException $e) {
50-
throw new Exception(
51-
$e->getMessage(),
52-
(int) $e->getCode(),
53-
$e
54-
);
55-
}
56-
}
57-
58-
$location = sprintf(
59-
"%s(%d): %s->%s()",
60-
$reflected->getFileName(),
61-
$reflected->getStartLine(),
62-
$testClass,
63-
$testMethod
64-
);
65-
66-
$summary = '';
6734
if ($previous) {
68-
$exception = $previous;
69-
do {
70-
$summary .= PHP_EOL
71-
. PHP_EOL
72-
. 'Caused By: '
73-
. $exception->getMessage()
74-
. PHP_EOL
75-
. $exception->getTraceAsString();
76-
} while ($exception = $exception->getPrevious());
77-
}
78-
$exception = new Exception(
79-
sprintf(
80-
"%s\n#0 %s%s",
81-
$message,
82-
$location,
83-
$summary
84-
),
85-
0,
86-
$previous
87-
);
88-
if ($test) {
89-
\PHPUnit\Event\Facade::emitter()->testErrored(
90-
$test->valueObjectForEvents(),
91-
\PHPUnit\Event\Code\ThrowableBuilder::from($exception),
92-
);
93-
$test::fail($exception->getMessage());
94-
} else {
95-
throw $exception;
35+
$throwable = ThrowableBuilder::from($previous);
36+
$message .= PHP_EOL . 'Caused by' . PHP_EOL . $throwable->asString();
9637
}
38+
$test::fail($message);
9739
}
9840
}

dev/tests/integration/framework/Magento/TestFramework/Annotation/IndexerDimensionMode.php

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* Copyright © Magento, Inc. All rights reserved.
4-
* See COPYING.txt for license details.
3+
* Copyright 2018 Adobe
4+
* All Rights Reserved.
55
*/
66
declare(strict_types=1);
77

@@ -15,14 +15,14 @@
1515
use Magento\Framework\App\Config\ScopeConfigInterface;
1616
use Magento\Framework\Exception\LocalizedException;
1717
use Magento\Framework\ObjectManagerInterface;
18-
use Magento\TestFramework\Annotation\TestCaseAnnotation;
1918
use Magento\TestFramework\App\Config;
2019
use Magento\TestFramework\Fixture\ParserInterface;
2120
use Magento\TestFramework\Helper\Bootstrap;
2221
use PHPUnit\Framework\TestCase;
2322

2423
/**
2524
* Implementation of the @magentoIndexerDimensionMode DocBlock annotation
25+
*
2626
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
2727
*/
2828
class IndexerDimensionMode
@@ -85,8 +85,7 @@ private function setDimensionMode(string $mode, TestCase $test)
8585
} else {
8686
ExceptionHandler::handle(
8787
'Dimensions mode for indexer has not been changed',
88-
get_class($test),
89-
$test->getName(false)
88+
test: $test
9089
);
9190
}
9291
}
@@ -106,9 +105,8 @@ public function startTest(TestCase $test)
106105
} catch (\Throwable $exception) {
107106
ExceptionHandler::handle(
108107
'Unable to parse fixtures',
109-
get_class($test),
110-
$test->getName(false),
111-
$exception
108+
$exception,
109+
$test
112110
);
113111
}
114112

@@ -117,8 +115,7 @@ public function startTest(TestCase $test)
117115
if ($dbIsolation) {
118116
ExceptionHandler::handle(
119117
'@magentoDbIsolation must be disabled when using @magentoIndexerDimensionMode',
120-
get_class($test),
121-
$test->getName(false)
118+
test: $test
122119
);
123120
}
124121

0 commit comments

Comments
 (0)