You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: tests/acceptance/TestCase.feature
+89Lines changed: 89 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -909,6 +909,95 @@ Feature: TestCase
909
909
When I run Psalm with dead code detection
910
910
Then I see no errors
911
911
912
+
Scenario: Test methods marked with #[Test] in a trait are not marked as unused when the consuming class does not import the Test attribute
913
+
Given I have the following code in "MyTestTrait.php"
914
+
"""
915
+
<?php
916
+
namespace NS;
917
+
use PHPUnit\Framework\Attributes\Test;
918
+
trait MyTestTrait {
919
+
#[Test]
920
+
public function itDoesSomething(): void {}
921
+
}
922
+
"""
923
+
And I have the following code in "code.php"
924
+
"""
925
+
<?php
926
+
namespace NS;
927
+
use PHPUnit\Framework\TestCase;
928
+
final class MyTestCase extends TestCase {
929
+
use MyTestTrait;
930
+
}
931
+
"""
932
+
When I run Psalm with dead code detection
933
+
Then I see no errors
934
+
935
+
Scenario: Test methods marked with a partially-imported #[Attributes\Test] in a trait are not marked as unused when the consuming class does not import the namespace
936
+
Given I have the following code in "MyTestTrait.php"
937
+
"""
938
+
<?php
939
+
namespace NS;
940
+
use PHPUnit\Framework\Attributes;
941
+
trait MyTestTrait {
942
+
#[Attributes\Test]
943
+
public function itDoesSomething(): void {}
944
+
}
945
+
"""
946
+
And I have the following code in "code.php"
947
+
"""
948
+
<?php
949
+
namespace NS;
950
+
use PHPUnit\Framework\TestCase;
951
+
final class MyTestCase extends TestCase {
952
+
use MyTestTrait;
953
+
}
954
+
"""
955
+
When I run Psalm with dead code detection
956
+
Then I see no errors
957
+
958
+
Scenario: Test methods marked with an aliased #[Test] attribute in a trait are not marked as unused when the consuming class does not import the alias
959
+
Given I have the following code in "MyTestTrait.php"
960
+
"""
961
+
<?php
962
+
namespace NS;
963
+
use PHPUnit\Framework\Attributes\Test as PHPUnitTest;
964
+
trait MyTestTrait {
965
+
#[PHPUnitTest]
966
+
public function itDoesSomething(): void {}
967
+
}
968
+
"""
969
+
And I have the following code in "code.php"
970
+
"""
971
+
<?php
972
+
namespace NS;
973
+
use PHPUnit\Framework\TestCase;
974
+
final class MyTestCase extends TestCase {
975
+
use MyTestTrait;
976
+
}
977
+
"""
978
+
When I run Psalm with dead code detection
979
+
Then I see no errors
980
+
981
+
Scenario: Test methods marked with a fully-qualified #[Test] attribute are not marked as unused
982
+
Given I have the following code in "BaseTestCase.php"
983
+
"""
984
+
<?php
985
+
namespace NS;
986
+
use PHPUnit\Framework\TestCase;
987
+
abstract class BaseTestCase extends TestCase {}
988
+
"""
989
+
And I have the following code in "code.php"
990
+
"""
991
+
<?php
992
+
namespace NS;
993
+
final class MyTestCase extends BaseTestCase {
994
+
#[\PHPUnit\Framework\Attributes\Test]
995
+
public function itDoesSomething(): void {}
996
+
}
997
+
"""
998
+
When I run Psalm with dead code detection
999
+
Then I see no errors
1000
+
912
1001
Scenario: Inherited test methods are not marked as unused
0 commit comments