File tree Expand file tree Collapse file tree 3 files changed +22
-3
lines changed
tests/Rule/data/DeadMethodRule/providers Expand file tree Collapse file tree 3 files changed +22
-3
lines changed Original file line number Diff line number Diff line change @@ -133,7 +133,7 @@ private function getDeclaringTraitDefinition(
133
133
return null ;
134
134
}
135
135
136
- if ($ realDeclaringClass ->isTrait ()) {
136
+ if ($ realDeclaringClass ->isTrait () && $ realDeclaringClass -> getName () !== $ classReflection -> getName () ) {
137
137
return new MethodDefinition (
138
138
$ realDeclaringClass ->getName (),
139
139
$ realName ,
Original file line number Diff line number Diff line change @@ -215,8 +215,19 @@ private function isEntryPoint(MethodDefinition $methodDefinition): bool
215
215
return false ;
216
216
}
217
217
218
- $ methodReflection = $ this ->reflectionProvider // @phpstan-ignore missingType.checkedException (method should exist)
219
- ->getClass ($ methodDefinition ->className )
218
+ $ reflection = $ this ->reflectionProvider ->getClass ($ methodDefinition ->className );
219
+
220
+ // if trait has users, we need to check entrypoint even from their context
221
+ if ($ reflection ->isTrait ()) {
222
+ foreach ($ this ->classHierarchy ->getMethodTraitUsages ($ methodDefinition ) as $ traitUsage ) {
223
+ if ($ this ->isEntryPoint ($ traitUsage )) {
224
+ return true ;
225
+ }
226
+ }
227
+ }
228
+
229
+ // @phpstan-ignore missingType.checkedException (method should exist)
230
+ $ methodReflection = $ reflection
220
231
->getNativeReflection ()
221
232
->getMethod ($ methodDefinition ->methodName );
222
233
Original file line number Diff line number Diff line change 7
7
use PHPUnit \Framework \Attributes \Test ;
8
8
use PHPUnit \Framework \TestCase ;
9
9
10
+ trait TraitTestCase {
11
+ #[Before] // need to be checked in context of user, not in context of trait
12
+ public function callBefore (): void
13
+ {
14
+ }
15
+ }
16
+
10
17
class SomeTest extends TestCase
11
18
{
19
+ use TraitTestCase;
12
20
13
21
#[DataProvider('provideFromAttribute ' )]
14
22
public function testFoo (string $ arg ): void
You can’t perform that action at this time.
0 commit comments