Skip to content

Commit ca1defa

Browse files
committed
consider traits imported in parent classes
A public method declared in a trait can be used by a class without importing the trait itself when the trait is already imported by one of the parent classes from the inheritance chain.
1 parent 5992bf0 commit ca1defa

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/Symfony/Bridge/PhpUnit/Legacy/SymfonyTestsListenerTrait.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,14 @@ public function startTest($test)
232232
if (isset($annotations['class']['expectedDeprecation'])) {
233233
$test->getTestResultObject()->addError($test, new AssertionFailedError('`@expectedDeprecation` annotations are not allowed at the class level.'), 0);
234234
}
235-
if (isset($annotations['method']['expectedDeprecation']) || $this->checkNumAssertions = \in_array(ExpectDeprecationTrait::class, class_uses($test), true)) {
235+
236+
if (method_exists($test, 'expectDeprecation') && (new \ReflectionMethod($test, 'expectDeprecation'))->getFileName() === (new \ReflectionMethod(ExpectDeprecationTrait::class, 'expectDeprecation'))->getFileName()) {
237+
$this->checkNumAssertions = true;
238+
} else {
239+
$this->checkNumAssertions = false;
240+
}
241+
242+
if (isset($annotations['method']['expectedDeprecation']) || $this->checkNumAssertions) {
236243
if (isset($annotations['method']['expectedDeprecation'])) {
237244
self::$expectedDeprecations = $annotations['method']['expectedDeprecation'];
238245
self::$previousErrorHandler = set_error_handler([self::class, 'handleError']);

0 commit comments

Comments
 (0)