From 076fddf53e8ec300e62d84bd724128887cfed5f1 Mon Sep 17 00:00:00 2001 From: James Titcumb Date: Thu, 5 Mar 2026 08:38:31 +0000 Subject: [PATCH] 435: add phpstan-phpunit extension --- composer.json | 1 + composer.lock | 58 ++++++++++++++++++- phpstan-baseline.neon | 12 ---- phpstan.neon | 1 + ...InstallExtensionsForProjectCommandTest.php | 20 +++---- .../FetchDependencyStatusesTest.php | 1 - .../Platform/TargetPhp/PhpBinaryPathTest.php | 2 - 7 files changed, 68 insertions(+), 27 deletions(-) diff --git a/composer.json b/composer.json index 9bb4f3d..2f09d92 100644 --- a/composer.json +++ b/composer.json @@ -46,6 +46,7 @@ "bnf/phpstan-psr-container": "^1.1", "doctrine/coding-standard": "^14.0.0", "phpstan/phpstan": "^2.1.38", + "phpstan/phpstan-phpunit": "^2.0", "phpstan/phpstan-webmozart-assert": "^2.0", "phpunit/phpunit": "^10.5.63" }, diff --git a/composer.lock b/composer.lock index 654bc2d..06d3fa8 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "6392877b0b53e6d18d3d156173dcbba3", + "content-hash": "1138a5a4004fa55c3068062f3a2adc43", "packages": [ { "name": "composer/ca-bundle", @@ -3362,6 +3362,62 @@ ], "time": "2026-01-30T17:12:46+00:00" }, + { + "name": "phpstan/phpstan-phpunit", + "version": "2.0.16", + "source": { + "type": "git", + "url": "https://github.com/phpstan/phpstan-phpunit.git", + "reference": "6ab598e1bc106e6827fd346ae4a12b4a5d634c32" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/phpstan/phpstan-phpunit/zipball/6ab598e1bc106e6827fd346ae4a12b4a5d634c32", + "reference": "6ab598e1bc106e6827fd346ae4a12b4a5d634c32", + "shasum": "" + }, + "require": { + "php": "^7.4 || ^8.0", + "phpstan/phpstan": "^2.1.32" + }, + "conflict": { + "phpunit/phpunit": "<7.0" + }, + "require-dev": { + "nikic/php-parser": "^5", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpstan/phpstan-deprecation-rules": "^2.0", + "phpstan/phpstan-strict-rules": "^2.0", + "phpunit/phpunit": "^9.6" + }, + "type": "phpstan-extension", + "extra": { + "phpstan": { + "includes": [ + "extension.neon", + "rules.neon" + ] + } + }, + "autoload": { + "psr-4": { + "PHPStan\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "PHPUnit extensions and rules for PHPStan", + "keywords": [ + "static analysis" + ], + "support": { + "issues": "https://github.com/phpstan/phpstan-phpunit/issues", + "source": "https://github.com/phpstan/phpstan-phpunit/tree/2.0.16" + }, + "time": "2026-02-14T09:05:21+00:00" + }, { "name": "phpstan/phpstan-webmozart-assert", "version": "2.0.0", diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 3f1ae16..484f95b 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -360,18 +360,6 @@ parameters: count: 1 path: test/integration/Command/InstallCommandTest.php - - - message: '#^Parameter \#1 \$originalClassName of method PHPUnit\\Framework\\TestCase\:\:createMock\(\) expects class\-string\, string given\.$#' - identifier: argument.type - count: 1 - path: test/integration/Command/InstallExtensionsForProjectCommandTest.php - - - - message: '#^Unable to resolve the template type RealInstanceType in call to method PHPUnit\\Framework\\TestCase\:\:createMock\(\)$#' - identifier: argument.templateType - count: 1 - path: test/integration/Command/InstallExtensionsForProjectCommandTest.php - - message: '#^Call to function assert\(\) with true will always evaluate to true\.$#' identifier: function.alreadyNarrowedType diff --git a/phpstan.neon b/phpstan.neon index 9d3ff53..80f87e1 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,6 +2,7 @@ includes: - phpstan-baseline.neon - vendor/bnf/phpstan-psr-container/extension.neon - vendor/phpstan/phpstan-webmozart-assert/extension.neon + - vendor/phpstan/phpstan-phpunit/extension.neon parameters: level: 10 diff --git a/test/integration/Command/InstallExtensionsForProjectCommandTest.php b/test/integration/Command/InstallExtensionsForProjectCommandTest.php index cad216c..ad9f6cf 100644 --- a/test/integration/Command/InstallExtensionsForProjectCommandTest.php +++ b/test/integration/Command/InstallExtensionsForProjectCommandTest.php @@ -58,17 +58,15 @@ final class InstallExtensionsForProjectCommandTest extends TestCase $container->method('get')->willReturnCallback( /** @param class-string $service */ function (string $service): mixed { - switch ($service) { - case QuieterConsoleIO::class: - return new QuieterConsoleIO( - new ArrayInput([]), - new BufferedOutput(), - new MinimalHelperSet(['question' => new QuestionHelper()]), - ); - - default: - return $this->createMock($service); - } + /** @var class-string $service */ + return match ($service) { + QuieterConsoleIO::class => new QuieterConsoleIO( + new ArrayInput([]), + new BufferedOutput(), + new MinimalHelperSet(['question' => new QuestionHelper()]), + ), + default => $this->createMock($service), + }; }, ); diff --git a/test/unit/DependencyResolver/FetchDependencyStatusesTest.php b/test/unit/DependencyResolver/FetchDependencyStatusesTest.php index 42e9f8e..03c21bd 100644 --- a/test/unit/DependencyResolver/FetchDependencyStatusesTest.php +++ b/test/unit/DependencyResolver/FetchDependencyStatusesTest.php @@ -43,7 +43,6 @@ final class FetchDependencyStatusesTest extends TestCase $package, ); - self::assertIsList($deps); self::assertCount(3, $deps); self::assertSame('ext-core: == 8.4.17.0 ✅', $deps[0]->asPrettyString()); diff --git a/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php b/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php index eeeda37..4bd9a66 100644 --- a/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php +++ b/test/unit/Platform/TargetPhp/PhpBinaryPathTest.php @@ -400,10 +400,8 @@ final class PhpBinaryPathTest extends TestCase $php = PhpBinaryPath::fromPhpBinaryPath($phpPath); self::assertArrayHasKey('Core', $php->extensions()); self::assertNotEmpty($php->extensionPath()); - self::assertInstanceOf(OperatingSystem::class, $php->operatingSystem()); self::assertNotEmpty($php->version()); self::assertNotEmpty($php->majorMinorVersion()); - self::assertInstanceOf(Architecture::class, $php->machineType()); self::assertGreaterThan(0, $php->phpIntSize()); self::assertNotEmpty($php->phpinfo()); }