From 7dc4ef191fece4da362c47e00473f08e83591c27 Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Tue, 28 Nov 2023 20:54:02 +0000 Subject: [PATCH 1/5] Update PHPUnit (9.x -> 10.x) --- .github/workflows/build.yml | 2 +- Makefile | 4 ---- composer.json | 4 ++-- phpunit.xml.dist | 14 ++++++++------ tests/Cli/ServiceContainer/RunnerFactoryTest.php | 3 +++ tests/Cli/ServiceContainerTest.php | 2 +- tests/Json/Factory/BoxBuildCommandFactoryTest.php | 2 +- .../ComposerBinPluginCommandFactoryTest.php | 2 +- .../Factory/ComposerInstallCommandFactoryTest.php | 2 +- .../Factory/FileDownloadCommandFactoryTest.php | 2 +- .../Factory/PharDownloadCommandFactoryTest.php | 2 +- .../Factory/PhiveInstallCommandFactoryTest.php | 2 +- tests/Json/Factory/ToolFactoryTest.php | 2 +- 13 files changed, 22 insertions(+), 21 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index ecd5fbfd..a538053c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,7 +35,7 @@ jobs: php-version: "${{ matrix.php }}" tools: composer ini-values: "phar.readonly=0" - coverage: none + coverage: pcov - if: matrix.deps == 'high' run: make update test package package-devkit diff --git a/Makefile b/Makefile index 2726a859..eb8f5a35 100644 --- a/Makefile +++ b/Makefile @@ -56,10 +56,6 @@ phpunit: tools/phpunit tools/phpunit .PHONY: phpunit -phpunit-coverage: tools/phpunit - phpdbg -qrr tools/phpunit -.PHONY: phpunit - package: tools/box @rm -rf build/phar && mkdir -p build/phar build/phar/bin diff --git a/composer.json b/composer.json index dd90fbdd..f566ab88 100644 --- a/composer.json +++ b/composer.json @@ -8,8 +8,8 @@ "psr/container": "^2.0" }, "require-dev": { - "phpunit/phpunit": "^9.5", - "zalas/phpunit-globals": "^2.1", + "phpunit/phpunit": "^10.0", + "zalas/phpunit-globals": "^3.2", "infection/infection": "^0.26" }, "autoload": { diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 158f138e..091e0031 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,9 +1,6 @@ - - - - src - + + @@ -20,7 +17,12 @@ - + + + + src + + diff --git a/tests/Cli/ServiceContainer/RunnerFactoryTest.php b/tests/Cli/ServiceContainer/RunnerFactoryTest.php index 22860d1f..1d2ea6e7 100644 --- a/tests/Cli/ServiceContainer/RunnerFactoryTest.php +++ b/tests/Cli/ServiceContainer/RunnerFactoryTest.php @@ -2,6 +2,7 @@ namespace Zalas\Toolbox\Tests\Cli\ServiceContainer; +use PHPUnit\Framework\Attributes\DoesNotPerformAssertions; use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\TestCase; use Psr\Container\ContainerExceptionInterface; @@ -89,6 +90,7 @@ public function test_it_creates_the_parametrised_runner_if_target_dir_option_is_ $this->assertInstanceOf(ParametrisedRunner::class, $runner); } + #[DoesNotPerformAssertions] public function test_the_parametrised_runner_includes_the_target_dir_parameter() { $this->givenInput(['--target-dir' => '/usr/local/bin', '--dry-run' => true]); @@ -114,6 +116,7 @@ public function test_it_throws_an_exception_if_target_dir_does_not_exist() $this->runnerFactory->createRunner(); } + #[DoesNotPerformAssertions] public function test_it_uses_the_real_path_as_target_dir() { $this->givenInput(['--target-dir' => __DIR__.'/../../../bin', '--dry-run' => true]); diff --git a/tests/Cli/ServiceContainerTest.php b/tests/Cli/ServiceContainerTest.php index 5cf05849..7bda293f 100644 --- a/tests/Cli/ServiceContainerTest.php +++ b/tests/Cli/ServiceContainerTest.php @@ -48,7 +48,7 @@ public function test_it_creates_application_services(string $serviceId, string $ $this->assertInstanceOf($expectedType, $this->container->get($serviceId)); } - public function provideApplicationServices() + public static function provideApplicationServices() { yield [InstallCommand::class, InstallCommand::class]; yield [ListCommand::class, ListCommand::class]; diff --git a/tests/Json/Factory/BoxBuildCommandFactoryTest.php b/tests/Json/Factory/BoxBuildCommandFactoryTest.php index d80f2bdc..df1170be 100644 --- a/tests/Json/Factory/BoxBuildCommandFactoryTest.php +++ b/tests/Json/Factory/BoxBuildCommandFactoryTest.php @@ -58,7 +58,7 @@ public function test_it_complains_if_any_of_required_properties_is_missing(strin BoxBuildCommandFactory::import($properties); } - public function provideRequiredProperties(): \Generator + public static function provideRequiredProperties(): \Generator { yield ['repository']; yield ['phar']; diff --git a/tests/Json/Factory/ComposerBinPluginCommandFactoryTest.php b/tests/Json/Factory/ComposerBinPluginCommandFactoryTest.php index 4d9d52b2..b214af01 100644 --- a/tests/Json/Factory/ComposerBinPluginCommandFactoryTest.php +++ b/tests/Json/Factory/ComposerBinPluginCommandFactoryTest.php @@ -57,7 +57,7 @@ public function test_it_complains_if_any_of_required_properties_is_missing(strin ComposerBinPluginCommandFactory::import($properties); } - public function provideRequiredProperties(): \Generator + public static function provideRequiredProperties(): \Generator { yield ['package']; yield ['namespace']; diff --git a/tests/Json/Factory/ComposerInstallCommandFactoryTest.php b/tests/Json/Factory/ComposerInstallCommandFactoryTest.php index a9c93742..c3fd5959 100644 --- a/tests/Json/Factory/ComposerInstallCommandFactoryTest.php +++ b/tests/Json/Factory/ComposerInstallCommandFactoryTest.php @@ -41,7 +41,7 @@ public function test_it_complains_if_a_required_property_is_missing(string $prop ComposerInstallCommandFactory::import($properties); } - public function provideRequiredProperties() + public static function provideRequiredProperties() { yield ['repository']; yield ['target-dir']; diff --git a/tests/Json/Factory/FileDownloadCommandFactoryTest.php b/tests/Json/Factory/FileDownloadCommandFactoryTest.php index 6dd9ff28..f17b0aa3 100644 --- a/tests/Json/Factory/FileDownloadCommandFactoryTest.php +++ b/tests/Json/Factory/FileDownloadCommandFactoryTest.php @@ -38,7 +38,7 @@ public function test_it_complains_if_any_of_required_properties_is_missing(strin FileDownloadCommandFactory::import($properties); } - public function provideRequiredProperties(): \Generator + public static function provideRequiredProperties(): \Generator { yield ['url']; yield ['file']; diff --git a/tests/Json/Factory/PharDownloadCommandFactoryTest.php b/tests/Json/Factory/PharDownloadCommandFactoryTest.php index 21ae9ae7..1664278d 100644 --- a/tests/Json/Factory/PharDownloadCommandFactoryTest.php +++ b/tests/Json/Factory/PharDownloadCommandFactoryTest.php @@ -38,7 +38,7 @@ public function test_it_complains_if_any_of_required_properties_is_missing(strin PharDownloadCommandFactory::import($properties); } - public function provideRequiredProperties(): \Generator + public static function provideRequiredProperties(): \Generator { yield ['phar']; yield ['bin']; diff --git a/tests/Json/Factory/PhiveInstallCommandFactoryTest.php b/tests/Json/Factory/PhiveInstallCommandFactoryTest.php index 3ec413f6..b8d406a0 100644 --- a/tests/Json/Factory/PhiveInstallCommandFactoryTest.php +++ b/tests/Json/Factory/PhiveInstallCommandFactoryTest.php @@ -53,7 +53,7 @@ public function test_it_accepts_unsigned_phars() $this->assertStringContainsString('unsigned', (string)$command); } - public function provideRequiredProperties(): \Generator + public static function provideRequiredProperties(): \Generator { yield ['alias']; yield ['bin']; diff --git a/tests/Json/Factory/ToolFactoryTest.php b/tests/Json/Factory/ToolFactoryTest.php index 42f0ce0b..bbf0b9b2 100644 --- a/tests/Json/Factory/ToolFactoryTest.php +++ b/tests/Json/Factory/ToolFactoryTest.php @@ -209,7 +209,7 @@ public function test_it_complains_if_any_of_required_properties_is_missing(strin ToolFactory::import($properties); } - public function provideRequiredProperties(): \Generator + public static function provideRequiredProperties(): \Generator { yield ['name']; yield ['summary']; From d1f072117ed03dbe92c17a09c440b9d913255a4b Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Tue, 28 Nov 2023 21:21:47 +0000 Subject: [PATCH 2/5] Replace annotations with attributes --- phpunit.xml.dist | 2 +- tests/Cli/ApplicationTest.php | 9 +++------ tests/Cli/Command/InstallCommandTest.php | 13 ++++--------- tests/Cli/Command/ListCommandTest.php | 9 +++------ tests/Cli/Command/TestCommandTest.php | 13 ++++--------- 5 files changed, 15 insertions(+), 31 deletions(-) diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 091e0031..6c596f44 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -17,7 +17,7 @@ - + diff --git a/tests/Cli/ApplicationTest.php b/tests/Cli/ApplicationTest.php index 975b240a..7963c001 100644 --- a/tests/Cli/ApplicationTest.php +++ b/tests/Cli/ApplicationTest.php @@ -8,6 +8,7 @@ use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; use Symfony\Component\Console\Output\OutputInterface; +use Zalas\PHPUnit\Globals\Attribute\Putenv; use Zalas\Toolbox\Cli\Application; use Zalas\Toolbox\Cli\Command\InstallCommand; use Zalas\Toolbox\Cli\Command\ListCommand; @@ -70,17 +71,13 @@ public function test_it_defines_tools_option() ); } - /** - * @putenv TOOLBOX_JSON=resources/pre.json,resources/tools.json - */ + #[Putenv('TOOLBOX_JSON', 'resources/pre.json,resources/tools.json')] public function test_it_takes_the_tools_option_default_from_environment_if_present() { $this->assertSame(['resources/pre.json', 'resources/tools.json'], $this->app->getDefinition()->getOption('tools')->getDefault()); } - /** - * @putenv TOOLBOX_JSON=resources/pre.json , resources/tools.json - */ + #[Putenv('TOOLBOX_JSON', 'resources/pre.json , resources/tools.json')] public function test_it_trims_the_tools_option() { $this->assertSame(['resources/pre.json', 'resources/tools.json'], $this->app->getDefinition()->getOption('tools')->getDefault()); diff --git a/tests/Cli/Command/InstallCommandTest.php b/tests/Cli/Command/InstallCommandTest.php index 4d4a5e2d..227fa937 100644 --- a/tests/Cli/Command/InstallCommandTest.php +++ b/tests/Cli/Command/InstallCommandTest.php @@ -3,6 +3,7 @@ namespace Zalas\Toolbox\Tests\Cli\Command; use PHPUnit\Framework\MockObject\Stub; +use Zalas\PHPUnit\Globals\Attribute\Putenv; use Zalas\Toolbox\Cli\Command\InstallCommand; use Zalas\Toolbox\Runner\Runner; use Zalas\Toolbox\Tool\Command; @@ -77,9 +78,7 @@ public function test_it_defines_target_dir_option() $this->assertSame('/usr/local/bin', $this->cliCommand()->getDefinition()->getOption('target-dir')->getDefault()); } - /** - * @putenv TOOLBOX_TARGET_DIR=/tmp - */ + #[Putenv('TOOLBOX_TARGET_DIR', '/tmp')] public function test_it_takes_the_target_dir_option_default_from_environment_if_present() { $this->assertSame('/tmp', $this->cliCommand()->getDefinition()->getOption('target-dir')->getDefault()); @@ -91,9 +90,7 @@ public function test_it_defines_exclude_tag_option() $this->assertSame([], $this->cliCommand()->getDefinition()->getOption('exclude-tag')->getDefault()); } - /** - * @putenv TOOLBOX_EXCLUDED_TAGS=foo,bar,baz - */ + #[Putenv('TOOLBOX_EXCLUDED_TAGS', 'foo,bar,baz')] public function test_it_takes_the_excluded_tag_option_default_from_environment_if_present() { $this->assertSame(['foo', 'bar', 'baz'], $this->cliCommand()->getDefinition()->getOption('exclude-tag')->getDefault()); @@ -105,9 +102,7 @@ public function test_it_defines_tag_option() $this->assertSame([], $this->cliCommand()->getDefinition()->getOption('tag')->getDefault()); } - /** - * @putenv TOOLBOX_TAGS=foo,bar,baz - */ + #[Putenv('TOOLBOX_TAGS', 'foo,bar,baz')] public function test_it_takes_the_tag_option_default_from_environment_if_present() { $this->assertSame(['foo', 'bar', 'baz'], $this->cliCommand()->getDefinition()->getOption('tag')->getDefault()); diff --git a/tests/Cli/Command/ListCommandTest.php b/tests/Cli/Command/ListCommandTest.php index a44eeea4..1d7142de 100644 --- a/tests/Cli/Command/ListCommandTest.php +++ b/tests/Cli/Command/ListCommandTest.php @@ -3,6 +3,7 @@ namespace Zalas\Toolbox\Tests\Cli\Command; use PHPUnit\Framework\MockObject\Stub; +use Zalas\PHPUnit\Globals\Attribute\Putenv; use Zalas\Toolbox\Cli\Command\ListCommand; use Zalas\Toolbox\Tool\Collection; use Zalas\Toolbox\Tool\Command\ShCommand; @@ -59,9 +60,7 @@ public function test_it_defines_exclude_tag_option() $this->assertSame([], $this->cliCommand()->getDefinition()->getOption('exclude-tag')->getDefault()); } - /** - * @putenv TOOLBOX_EXCLUDED_TAGS=foo,bar,baz - */ + #[Putenv('TOOLBOX_EXCLUDED_TAGS', 'foo,bar,baz')] public function test_it_takes_the_excluded_tag_option_default_from_environment_if_present() { $this->assertSame(['foo', 'bar', 'baz'], $this->cliCommand()->getDefinition()->getOption('exclude-tag')->getDefault()); @@ -72,9 +71,7 @@ public function test_it_defines_tag_option() $this->assertTrue($this->cliCommand()->getDefinition()->hasOption('tag')); } - /** - * @putenv TOOLBOX_TAGS=foo,bar,baz - */ + #[Putenv('TOOLBOX_TAGS', 'foo,bar,baz')] public function test_it_takes_the_tag_option_default_from_environment_if_present() { $this->assertSame(['foo', 'bar', 'baz'], $this->cliCommand()->getDefinition()->getOption('tag')->getDefault()); diff --git a/tests/Cli/Command/TestCommandTest.php b/tests/Cli/Command/TestCommandTest.php index be6fb590..d2198692 100644 --- a/tests/Cli/Command/TestCommandTest.php +++ b/tests/Cli/Command/TestCommandTest.php @@ -3,6 +3,7 @@ namespace Zalas\Toolbox\Tests\Cli\Command; use PHPUnit\Framework\MockObject\Stub; +use Zalas\PHPUnit\Globals\Attribute\Putenv; use Zalas\Toolbox\Cli\Command\TestCommand; use Zalas\Toolbox\Runner\Runner; use Zalas\Toolbox\Tool\Command; @@ -74,9 +75,7 @@ public function test_it_defines_target_dir_option() $this->assertTrue($this->cliCommand()->getDefinition()->hasOption('target-dir')); } - /** - * @putenv TOOLBOX_TARGET_DIR=/tmp - */ + #[Putenv('TOOLBOX_TARGET_DIR', '/tmp')] public function test_it_takes_the_target_dir_option_default_from_environment_if_present() { $this->assertSame('/tmp', $this->cliCommand()->getDefinition()->getOption('target-dir')->getDefault()); @@ -88,9 +87,7 @@ public function test_it_defines_exclude_tag_option() $this->assertSame([], $this->cliCommand()->getDefinition()->getOption('exclude-tag')->getDefault()); } - /** - * @putenv TOOLBOX_EXCLUDED_TAGS=foo,bar,baz - */ + #[Putenv('TOOLBOX_EXCLUDED_TAGS', 'foo,bar,baz')] public function test_it_takes_the_excluded_tag_option_default_from_environment_if_present() { $this->assertSame(['foo', 'bar', 'baz'], $this->cliCommand()->getDefinition()->getOption('exclude-tag')->getDefault()); @@ -101,9 +98,7 @@ public function test_it_defines_tag_option() $this->assertTrue($this->cliCommand()->getDefinition()->hasOption('tag')); } - /** - * @putenv TOOLBOX_TAGS=foo,bar,baz - */ + #[Putenv('TOOLBOX_TAGS', 'foo,bar,baz')] public function test_it_takes_the_tag_option_default_from_environment_if_present() { $this->assertSame(['foo', 'bar', 'baz'], $this->cliCommand()->getDefinition()->getOption('tag')->getDefault()); From 2871ffc7cc704c4c3c5f428a9fdf050c812ead24 Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Tue, 28 Nov 2023 21:30:23 +0000 Subject: [PATCH 3/5] Update infection --- Makefile | 2 +- composer.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index eb8f5a35..bbcd8ff8 100644 --- a/Makefile +++ b/Makefile @@ -49,7 +49,7 @@ deptrac: tools/deptrac .PHONY: deptrac infection: - phpdbg -qrr ./vendor/bin/infection --no-interaction --formatter=progress --min-msi=100 --min-covered-msi=100 --only-covered --ansi + ./vendor/bin/infection --no-interaction --formatter=progress --min-msi=100 --min-covered-msi=100 --only-covered --ansi .PHONY: infection phpunit: tools/phpunit diff --git a/composer.json b/composer.json index f566ab88..db1f09eb 100644 --- a/composer.json +++ b/composer.json @@ -10,7 +10,7 @@ "require-dev": { "phpunit/phpunit": "^10.0", "zalas/phpunit-globals": "^3.2", - "infection/infection": "^0.26" + "infection/infection": "^0.27" }, "autoload": { "psr-4": { From a49038815607de41b35461f30f4702c2a8462ddb Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Tue, 28 Nov 2023 21:33:15 +0000 Subject: [PATCH 4/5] Set the minimum phpunit version higher due to its BC breaks --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index db1f09eb..68521b65 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,7 @@ "psr/container": "^2.0" }, "require-dev": { - "phpunit/phpunit": "^10.0", + "phpunit/phpunit": "^10.4", "zalas/phpunit-globals": "^3.2", "infection/infection": "^0.27" }, From e841cf1fda8da9996c1d6360d7a24228d903c9d8 Mon Sep 17 00:00:00 2001 From: Jakub Zalas Date: Tue, 28 Nov 2023 21:42:06 +0000 Subject: [PATCH 5/5] Configure cov in scrutinizer --- .scrutinizer.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 588db2c2..832cd37f 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -4,6 +4,8 @@ build: environment: php: version: 8.2 + variables: + XDEBUG_MODE: coverage tests: override: - make phpunit @@ -12,7 +14,7 @@ build: coverage: tests: override: - - command: make phpunit-coverage + - command: make phpunit coverage: file: build/coverage.xml format: clover