Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated PHPStan and Rector to verson 2. #266

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
"mikey179/vfsstream": "^1.6",
"opis/closure": "^3.6",
"phpmd/phpmd": "^2.13",
"phpstan/phpstan": "^1.10",
"phpstan/phpstan": "^2",
"phpunit/phpunit": "^11",
"rector/rector": "^1.0.0"
"rector/rector": "^2"
},
"minimum-stability": "stable",
"prefer-stable": true,
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/Traits/ArrayTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* Trait ArrayTrait.
*
* Provides methods for working with arrays.
*
* @phpstan-ignore trait.unused
*/
trait ArrayTrait {

Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/Traits/AssertTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* Trait AssertTrait.
*
* Provides custom assertions.
*
* @phpstan-ignore trait.unused
*/
trait AssertTrait {

Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/Traits/ClosureWrapperTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
* fnw() stands for "function wrap" and fnu() stands for "function unwrap".
*
* @see https://github.com/sebastianbergmann/phpunit/issues/2739
*
* @phpstan-ignore trait.unused
*/
trait ClosureWrapperTrait {

Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/Traits/EnvTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* Trait EnvTrait.
*
* Trait for managing environment variables.
*
* @phpstan-ignore trait.unused
*/
trait EnvTrait {

Expand Down
11 changes: 8 additions & 3 deletions tests/phpunit/Traits/MockTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Trait MockTrait.
*
* This trait provides a method to prepare class mock.
*
* @phpstan-ignore trait.unused
*/
trait MockTrait {

Expand All @@ -32,7 +34,7 @@ trait MockTrait {
* @SuppressWarnings("PHPMD.CyclomaticComplexity")
*/
protected function prepareMock(string $class, array $methods = [], array|bool $args = []): MockObject {
$methods = array_filter($methods, fn($value, $key): bool => is_string($key), ARRAY_FILTER_USE_BOTH);
$methods = array_filter($methods, fn($value, $key): bool => !is_numeric($key), ARRAY_FILTER_USE_BOTH);

if (!class_exists($class)) {
throw new \InvalidArgumentException(sprintf('Class %s does not exist', $class));
Expand All @@ -47,8 +49,11 @@ protected function prepareMock(string $class, array $methods = [], array|bool $a
$builder->disableOriginalConstructor();
}

$method_names = array_filter(array_keys($methods), fn($method): bool => is_string($method) && !empty($method));
$mock = $builder->onlyMethods($method_names)->getMock();
$method_names = array_values(array_filter(array_keys($methods), fn($method): bool => !empty($method)));
if (!empty($method_names)) {
$builder->onlyMethods($method_names);
}
$mock = $builder->getMock();

foreach ($methods as $method => $value) {
// Handle callback value differently based on its type.
Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/Traits/ReflectionTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
* Trait ReflectionTrait.
*
* Provides methods to work with class reflection.
*
* @phpstan-ignore trait.unused
*/
trait ReflectionTrait {

Expand Down
2 changes: 2 additions & 0 deletions tests/phpunit/Traits/VfsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
* Trait VfsTrait.
*
* Provides methods for working with the virtual file system.
*
* @phpstan-ignore trait.unused
*/
trait VfsTrait {

Expand Down
1 change: 1 addition & 0 deletions tests/phpunit/Unit/Command/JokeCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class JokeCommandTest extends CommandTestCase {
#[DataProvider('dataProviderExecute')]
public function testExecute(string $content, int $expected_code, array|string $expected_output = []): void {
/** @var \YourNamespace\App\Command\JokeCommand $mock */
// @phpstan-ignore varTag.nativeType
$mock = $this->prepareMock(JokeCommand::class, [
'getContent' => $content,
]);
Expand Down
Loading