Skip to content

Commit c66cbcf

Browse files
committed
Merge branch 'ACP2E-3334' of https://github.com/adobe-commerce-tier-4/magento2ce into PR-Tier4-VK-2025-01-09
2 parents c4a868c + 3d6f1e3 commit c66cbcf

13 files changed

+164
-138
lines changed

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

Lines changed: 8 additions & 13 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,9 +122,8 @@ 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'],
130-
$exception
125+
$exception,
126+
$test
131127
);
132128
}
133129
$this->_appliedFixtures[] = $fixture;
@@ -155,9 +151,8 @@ protected function _revertFixtures(?TestCase $test = null)
155151
} catch (\Throwable $exception) {
156152
ExceptionHandler::handle(
157153
'Unable to revert fixture: ' . $this->getFixtureReference($fixture),
158-
$fixture['test']['class'],
159-
$fixture['test']['method'],
160-
$exception
154+
$exception,
155+
$test
161156
);
162157
}
163158
}

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: 16 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +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;
11-
use ReflectionClass;
12-
use ReflectionException;
12+
use PHPUnit\Framework\TestCase;
1313

1414
class ExceptionHandler
1515
{
1616
/**
17-
* Format exception message and throws PHPUnit\Framework\Exception
17+
* Throws \PHPUnit\Framework\Exception and fail the test if provided.
1818
*
1919
* @param string $message
20-
* @param string $testClass
21-
* @param string|null $testMethod
2220
* @param \Throwable|null $previous
23-
* @return void
21+
* @param TestCase|null $test
22+
* @return never
23+
* @throws Exception
2424
*/
2525
public static function handle(
2626
string $message,
27-
string $testClass,
28-
?string $testMethod = null,
29-
?\Throwable $previous = null
30-
): void {
31-
try {
32-
$reflected = new ReflectionClass($testClass);
33-
} catch (ReflectionException $e) {
34-
throw new Exception(
35-
$e->getMessage(),
36-
(int) $e->getCode(),
37-
$e
38-
);
27+
?\Throwable $previous = null,
28+
?TestCase $test = null
29+
): never {
30+
if (!$test) {
31+
throw new Exception($message, 0, $previous);
3932
}
4033

41-
$name = $testMethod;
42-
43-
if ($name && $reflected->hasMethod($name)) {
44-
try {
45-
$reflected = $reflected->getMethod($name);
46-
} catch (ReflectionException $e) {
47-
throw new Exception(
48-
$e->getMessage(),
49-
(int) $e->getCode(),
50-
$e
51-
);
52-
}
53-
}
54-
55-
$location = sprintf(
56-
"%s(%d): %s->%s()",
57-
$reflected->getFileName(),
58-
$reflected->getStartLine(),
59-
$testClass,
60-
$testMethod
61-
);
62-
63-
$summary = '';
6434
if ($previous) {
65-
$exception = $previous;
66-
do {
67-
$summary .= PHP_EOL
68-
. PHP_EOL
69-
. 'Caused By: '
70-
. $exception->getMessage()
71-
. PHP_EOL
72-
. $exception->getTraceAsString();
73-
} while ($exception = $exception->getPrevious());
35+
$throwable = ThrowableBuilder::from($previous);
36+
$message .= PHP_EOL . 'Caused by' . PHP_EOL . $throwable->asString();
7437
}
75-
throw new Exception(
76-
sprintf(
77-
"%s\n#0 %s%s",
78-
$message,
79-
$location,
80-
$summary
81-
),
82-
0,
83-
$previous
84-
);
38+
$test::fail($message);
8539
}
8640
}

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)