Skip to content

Commit

Permalink
add test for deprecation inheritance in trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Khartir authored and ondrejmirtes committed Mar 17, 2023
1 parent a22b36b commit cbbbaa9
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
],
"require": {
"php": "^7.2 || ^8.0",
"phpstan/phpstan": "^1.10"
"phpstan/phpstan": "^1.10.3"
},
"require-dev": {
"php-parallel-lint/php-parallel-lint": "^1.2",
Expand Down
4 changes: 4 additions & 0 deletions tests/Rules/Deprecations/CallToDeprecatedMethodRuleTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public function testDeprecatedMethodCall(): void
"Call to deprecated method deprecatedWithDescription() of class CheckDeprecatedMethodCall\\Foo:\nCall a different method instead.",
15,
],
[
"Call to deprecated method prophesize() of class CheckDeprecatedMethodCall\\UsingDeprecatedMethodFromTrait:\nUse TraitReplacingDeprecatedMethod::prophesize()",
64,
],
]
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,3 +65,32 @@ public function deprecatedFoo()
}

}

abstract class MethodMovedToTraitClass
{
/** @deprecated Use TraitReplacingDeprecatedMethod::prophesize() */
protected function prophesize(): void
{
echo 'Base';
}
}

trait TraitCallingDeprecatedMethod
{
protected function prophesize(): void
{
echo 'Trait';
}
}

trait TraitReplacingDeprecatedMethod
{
/**
* @not-deprecated
*/
protected function prophesize(): void
{
echo 'Trait';
}
}

21 changes: 21 additions & 0 deletions tests/Rules/Deprecations/data/call-to-deprecated-method.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,3 +53,24 @@ public function foo()
}

}


final class UsingDeprecatedMethodFromTrait extends MethodMovedToTraitClass
{
use TraitCallingDeprecatedMethod;

public function callProphesize(): void
{
$this->prophesize();
}
}

final class UsingTraitReplacementForDeprecatedMethod extends MethodMovedToTraitClass
{
use TraitReplacingDeprecatedMethod;

public function callProphesize(): void
{
$this->prophesize();
}
}

0 comments on commit cbbbaa9

Please sign in to comment.