Skip to content

Commit fd43cdb

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

File tree

4 files changed

+24
-14
lines changed

4 files changed

+24
-14
lines changed

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,8 @@ protected function _applyFixtures(array $fixtures, TestCase $test)
127127
'Unable to apply fixture: ' . $this->getFixtureReference($fixture),
128128
$fixture['test']['class'],
129129
$fixture['test']['method'],
130-
$exception
130+
$exception,
131+
$test
131132
);
132133
}
133134
$this->_appliedFixtures[] = $fixture;
@@ -157,7 +158,8 @@ protected function _revertFixtures(?TestCase $test = null)
157158
'Unable to revert fixture: ' . $this->getFixtureReference($fixture),
158159
$fixture['test']['class'],
159160
$fixture['test']['method'],
160-
$exception
161+
$exception,
162+
$test
161163
);
162164
}
163165
}

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

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
namespace Magento\TestFramework\Annotation;
99

1010
use PHPUnit\Framework\Exception;
11+
use PHPUnit\Framework\TestCase;
1112
use ReflectionClass;
1213
use ReflectionException;
1314

@@ -20,13 +21,15 @@ class ExceptionHandler
2021
* @param string $testClass
2122
* @param string|null $testMethod
2223
* @param \Throwable|null $previous
24+
* @param TestCase|null $test
2325
* @return void
2426
*/
2527
public static function handle(
2628
string $message,
2729
string $testClass,
2830
string $testMethod = null,
29-
\Throwable $previous = null
31+
\Throwable $previous = null,
32+
TestCase $test = null
3033
): void {
3134
try {
3235
$reflected = new ReflectionClass($testClass);
@@ -72,7 +75,7 @@ public static function handle(
7275
. $exception->getTraceAsString();
7376
} while ($exception = $exception->getPrevious());
7477
}
75-
throw new Exception(
78+
$exception = new Exception(
7679
sprintf(
7780
"%s\n#0 %s%s",
7881
$message,
@@ -82,5 +85,14 @@ public static function handle(
8285
0,
8386
$previous
8487
);
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;
96+
}
8597
}
8698
}

dev/tests/integration/framework/Magento/TestFramework/Event/TestPreparedSubscriber.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,5 @@ public function notify(Prepared $event): void
4040
$testObj->markTestSkipped($skipConfig['skipMessage']);
4141
}
4242
Magento::setTestPrepared(true);
43-
Magento::setCurrentEventObject($event);
44-
45-
$phpUnit = $objectManager->create(PhpUnit::class);
46-
$phpUnit->startTest($testObj);
4743
}
4844
}

dev/tests/integration/framework/Magento/TestFramework/Event/TestPreprationStartedSubscriber.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ public function notify(PreparationStarted $event): void
2626
$className = $event->test()->className();
2727
$methodName = $event->test()->methodName();
2828

29-
// $testObj = $objectManager->create($className, ['name' => $methodName]);
30-
//
31-
// Magento::setCurrentEventObject($event);
32-
//
33-
// $phpUnit = $objectManager->create(PhpUnit::class);
34-
// $phpUnit->startTest($testObj);
29+
$testObj = $objectManager->create($className, ['name' => $methodName]);
30+
31+
Magento::setCurrentEventObject($event);
32+
33+
$phpUnit = $objectManager->create(PhpUnit::class);
34+
$phpUnit->startTest($testObj);
3535
}
3636
}

0 commit comments

Comments
 (0)