Skip to content

Commit 6769891

Browse files
committed
Test how #[Override] behaves with constructors
1 parent e8e466d commit 6769891

File tree

3 files changed

+66
-0
lines changed

3 files changed

+66
-0
lines changed

tests/PHPStan/Rules/Methods/OverridingMethodRuleTest.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -770,6 +770,10 @@ public function testOverrideAttribute(): void
770770
'Method OverrideAttribute\Bar::test2() has #[\Override] attribute but does not override any method.',
771771
24,
772772
],
773+
[
774+
'Method OverrideAttribute\ChildOfParentWithConstructor::__construct() has #[\Override] attribute but does not override any method.',
775+
42,
776+
],
773777
]);
774778
}
775779

@@ -783,6 +787,10 @@ public function dataCheckMissingOverrideAttribute(): iterable
783787
'Method CheckMissingOverrideAttr\Bar::doFoo() overrides method CheckMissingOverrideAttr\Foo::doFoo() but is missing the #[\Override] attribute.',
784788
18,
785789
],
790+
[
791+
'Method CheckMissingOverrideAttr\ChildOfParentWithAbstractConstructor::__construct() overrides method CheckMissingOverrideAttr\ParentWithAbstractConstructor::__construct() but is missing the #[\Override] attribute.',
792+
49,
793+
],
786794
]];
787795
}
788796

tests/PHPStan/Rules/Methods/data/check-missing-override-attr.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,31 @@ public function doFoo(): void
2121
}
2222

2323
}
24+
25+
class ParentWithConstructor
26+
{
27+
28+
public function __construct() {}
29+
30+
}
31+
32+
33+
class ChildOfParentWithConstructor extends ParentWithConstructor {
34+
35+
public function __construct() {}
36+
37+
}
38+
39+
abstract class ParentWithAbstractConstructor
40+
{
41+
42+
abstract public function __construct();
43+
44+
}
45+
46+
47+
class ChildOfParentWithAbstractConstructor extends ParentWithAbstractConstructor {
48+
49+
public function __construct() {}
50+
51+
}

tests/PHPStan/Rules/Methods/data/override-attribute.php

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,3 +28,33 @@ public function test2(): void
2828
}
2929

3030
}
31+
32+
class ParentWithConstructor
33+
{
34+
35+
public function __construct() {}
36+
37+
}
38+
39+
40+
class ChildOfParentWithConstructor extends ParentWithConstructor {
41+
42+
#[\Override]
43+
public function __construct() {}
44+
45+
}
46+
47+
abstract class ParentWithAbstractConstructor
48+
{
49+
50+
abstract public function __construct();
51+
52+
}
53+
54+
55+
class ChildOfParentWithAbstractConstructor extends ParentWithAbstractConstructor {
56+
57+
#[\Override]
58+
public function __construct() {}
59+
60+
}

0 commit comments

Comments
 (0)