From f5c3ed1237c01d331b55bd32da79075e96eb0dda Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Fri, 9 Oct 2026 19:45:52 +0400 Subject: [PATCH 1/2] feat: require PHP 8.2 Testo, the new test runner, needs PHP 8.2 or newer; PHP 8.0 and 8.1 are end-of-life. Assisted-By: Claude Opus 5.5 --- .github/workflows/phpunit.yml | 2 +- README.md | 2 +- composer.json | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml index 5a77d0b..6b5d423 100644 --- a/.github/workflows/phpunit.yml +++ b/.github/workflows/phpunit.yml @@ -13,6 +13,6 @@ jobs: os: >- ['ubuntu-latest'] php: >- - ['8.0', '8.1', '8.2', '8.3'] + ['8.2', '8.3'] stability: >- ['prefer-lowest', 'prefer-stable'] diff --git a/README.md b/README.md index cd0058f..cbc1045 100644 --- a/README.md +++ b/README.md @@ -12,7 +12,7 @@ Make sure that your server is configured with following PHP version and extensions: -- PHP 8.0+ +- PHP 8.2+ ## Installation diff --git a/composer.json b/composer.json index a925883..bbff8d8 100644 --- a/composer.json +++ b/composer.json @@ -9,7 +9,7 @@ "homepage": "https://github.com/roadrunner-php/version-checker", "license": "MIT", "require": { - "php": "^8.0", + "php": "^8.2", "symfony/process": "^5.4 || ^6.0 || ^7.0 || ^8.0", "composer-runtime-api": "^2.0", "composer/semver": "^3.3" From 2d8aabe881e2f90d5c071c3658128d31a45b496b Mon Sep 17 00:00:00 2001 From: roxblnfk Date: Fri, 9 Oct 2026 19:50:57 +0400 Subject: [PATCH 2/2] test: migrate from PHPUnit to Testo build: allow vimeo/psalm ^6 || ^7 PHPUnit mocks moved to Mockery, since Double needs PHP 8.3. vimeo/psalm ^5 does not install on PHP 8.4+, so it is raised to keep the Testo job on the full 8.2-8.6 matrix; psalm 6 reports new errors in src, which are left for a separate change. Assisted-By: Claude Opus 5.5 --- .gitattributes | 2 +- .github/workflows/phpunit.yml | 18 -- .github/workflows/testo.yml | 16 ++ .gitignore | 2 - README.md | 2 +- composer.json | 10 +- phpunit.xml | 34 ---- testo.php | 18 ++ tests/src/Unit/Composer/PackageTest.php | 19 +- tests/src/Unit/Environment/NativeTest.php | 13 +- tests/src/Unit/Version/ComparatorTest.php | 31 ++- tests/src/Unit/Version/InstalledTest.php | 98 ++++------ tests/src/Unit/Version/RequiredTest.php | 39 ++-- tests/src/Unit/VersionCheckerTest.php | 218 ++++++++-------------- 14 files changed, 201 insertions(+), 319 deletions(-) delete mode 100644 .github/workflows/phpunit.yml create mode 100644 .github/workflows/testo.yml delete mode 100644 phpunit.xml create mode 100644 testo.php diff --git a/.gitattributes b/.gitattributes index aa89b55..6e35822 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,7 +1,7 @@ /.github export-ignore /.gitattributes export-ignore /.gitignore export-ignore -/phpunit.xml.dist export-ignore +/testo.php export-ignore /tests export-ignore /.editorconfig export-ignore /.php_cs.dist.php export-ignore diff --git a/.github/workflows/phpunit.yml b/.github/workflows/phpunit.yml deleted file mode 100644 index 6b5d423..0000000 --- a/.github/workflows/phpunit.yml +++ /dev/null @@ -1,18 +0,0 @@ -on: - pull_request: null - push: - branches: - - 1.x - -name: phpunit - -jobs: - phpunit: - uses: spiral/gh-actions/.github/workflows/phpunit.yml@master - with: - os: >- - ['ubuntu-latest'] - php: >- - ['8.2', '8.3'] - stability: >- - ['prefer-lowest', 'prefer-stable'] diff --git a/.github/workflows/testo.yml b/.github/workflows/testo.yml new file mode 100644 index 0000000..bc976d3 --- /dev/null +++ b/.github/workflows/testo.yml @@ -0,0 +1,16 @@ +on: + pull_request: null + push: + branches: + - 1.x + +name: testo + +jobs: + testo: + uses: spiral/gh-actions/.github/workflows/testo.yml@master + with: + os: >- + ['ubuntu-latest'] + dependencies: >- + ['lowest', 'highest'] diff --git a/.gitignore b/.gitignore index 2fe23be..78d21b7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,6 @@ .idea .php_cs .php_cs.cache -.phpunit.cache -.phpunit.result.cache build composer.lock coverage diff --git a/README.md b/README.md index cbc1045..75aa9c1 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![PHP Version Require](https://poser.pugx.org/roadrunner-php/version-checker/require/php)](https://packagist.org/packages/roadrunner-php/version-checker) [![Latest Stable Version](https://poser.pugx.org/roadrunner-php/version-checker/v/stable)](https://packagist.org/packages/roadrunner-php/version-checker) -[![phpunit](https://github.com/roadrunner-php/version-checker/actions/workflows/phpunit.yml/badge.svg)](https://github.com/roadrunner-php/version-checker/actions) +[![testo](https://github.com/roadrunner-php/version-checker/actions/workflows/testo.yml/badge.svg)](https://github.com/roadrunner-php/version-checker/actions) [![psalm](https://github.com/roadrunner-php/version-checker/actions/workflows/psalm.yml/badge.svg)](https://github.com/roadrunner-php/version-checker/actions) [![Codecov](https://codecov.io/gh/roadrunner-php/version-checker/branch/master/graph/badge.svg)](https://codecov.io/gh/roadrunner-php/version-checker) [![Total Downloads](https://poser.pugx.org/roadrunner-php/version-checker/downloads)](https://packagist.org/roadrunner-php/version-checker/phpunit) diff --git a/composer.json b/composer.json index bbff8d8..f9542e9 100644 --- a/composer.json +++ b/composer.json @@ -15,9 +15,11 @@ "composer/semver": "^3.3" }, "require-dev": { - "phpunit/phpunit": "^9.6 || ^10.0", - "vimeo/psalm": "^5.9", - "friendsofphp/php-cs-fixer": "^3.8" + "friendsofphp/php-cs-fixer": "^3.8", + "mockery/mockery": "^1.6", + "testo/bridge-mockery": "^0.1.2", + "testo/testo": "^0.10.55", + "vimeo/psalm": "^6 || ^7" }, "autoload": { "psr-4": { @@ -30,7 +32,7 @@ } }, "scripts": { - "test": "vendor/bin/phpunit", + "test": "vendor/bin/testo", "psalm": "vendor/bin/psalm --config=psalm.xml ./src", "cs": "vendor/bin/php-cs-fixer fix --config=.php-cs-fixer.dist.php -vvv --dry-run --using-cache=no" }, diff --git a/phpunit.xml b/phpunit.xml deleted file mode 100644 index 8dbabf9..0000000 --- a/phpunit.xml +++ /dev/null @@ -1,34 +0,0 @@ - - - - - tests - - - - - ./src - - - - - - - - - - - diff --git a/testo.php b/testo.php new file mode 100644 index 0000000..9bbd374 --- /dev/null +++ b/testo.php @@ -0,0 +1,18 @@ +setAccessible(true); - $this->assertSame($expected, $ref->invoke($package, $version)); + Assert::same($ref->invoke($package, $version), $expected); } - /** - * @dataProvider getMinVersionDataProvider - */ + #[DataProvider('getMinVersionDataProvider')] public function testGetMinVersion(string $version, string $expected): void { $package = new Package(); $ref = new \ReflectionMethod($package, 'getMinVersion'); $ref->setAccessible(true); - $this->assertSame($expected, $ref->invoke($package, $version)); + Assert::same($ref->invoke($package, $version), $expected); } public static function isSupportedVersionDataProvider(): \Traversable diff --git a/tests/src/Unit/Environment/NativeTest.php b/tests/src/Unit/Environment/NativeTest.php index 19cc8c3..4322835 100644 --- a/tests/src/Unit/Environment/NativeTest.php +++ b/tests/src/Unit/Environment/NativeTest.php @@ -4,14 +4,15 @@ namespace RoadRunner\VersionChecker\Tests\Unit\Environment; -use PHPUnit\Framework\TestCase; use RoadRunner\VersionChecker\Environment\Native; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -final class NativeTest extends TestCase +#[Test] +final class NativeTest { - /** - * @dataProvider valuesDataProvider - */ + #[DataProvider('valuesDataProvider')] public function testGet(mixed $value, mixed $expected, string $key): void { $native = new Native([ @@ -20,7 +21,7 @@ public function testGet(mixed $value, mixed $expected, string $key): void '3' => true, ]); - $this->assertSame($expected, $native->get($key)); + Assert::same($native->get($key), $expected); } diff --git a/tests/src/Unit/Version/ComparatorTest.php b/tests/src/Unit/Version/ComparatorTest.php index 5143474..36ad071 100644 --- a/tests/src/Unit/Version/ComparatorTest.php +++ b/tests/src/Unit/Version/ComparatorTest.php @@ -4,39 +4,36 @@ namespace RoadRunner\VersionChecker\Tests\Unit\Version; -use PHPUnit\Framework\TestCase; use RoadRunner\VersionChecker\Version\Comparator; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Test; -final class ComparatorTest extends TestCase +#[Test] +final class ComparatorTest { - /** - * @dataProvider greaterThanDataProvider - */ + #[DataProvider('greaterThanDataProvider')] public function testGreaterThan(string $requested, string $installed, bool $expected): void { $comparator = new Comparator(); - $this->assertSame($expected, $comparator->greaterThan($requested, $installed)); + Assert::same($comparator->greaterThan($requested, $installed), $expected); } - /** - * @dataProvider lessThanDataProvider - */ + #[DataProvider('lessThanDataProvider')] public function testLessThan(string $requested, string $installed, bool $expected): void { $comparator = new Comparator(); - $this->assertSame($expected, $comparator->lessThan($requested, $installed)); + Assert::same($comparator->lessThan($requested, $installed), $expected); } - /** - * @dataProvider equalDataProvider - */ + #[DataProvider('equalDataProvider')] public function testEqual(string $requested, string $installed, bool $expected): void { $comparator = new Comparator(); - $this->assertSame($expected, $comparator->equal($requested, $installed)); + Assert::same($comparator->equal($requested, $installed), $expected); } public static function greaterThanDataProvider(): \Traversable @@ -116,12 +113,10 @@ public static function equalDataProvider(): \Traversable yield ['2025.1.0', '3.0.0', false]; } - /** - * @dataProvider compareDataProvider - */ + #[DataProvider('compareDataProvider')] public function testCompare(string $a, string $b, int $expected): void { - $this->assertSame($expected, Comparator::compare($a, $b)); + Assert::same(Comparator::compare($a, $b), $expected); } public static function compareDataProvider(): \Traversable diff --git a/tests/src/Unit/Version/InstalledTest.php b/tests/src/Unit/Version/InstalledTest.php index ecf0396..1cf0242 100644 --- a/tests/src/Unit/Version/InstalledTest.php +++ b/tests/src/Unit/Version/InstalledTest.php @@ -4,15 +4,21 @@ namespace RoadRunner\VersionChecker\Tests\Unit\Version; -use PHPUnit\Framework\TestCase; +use Mockery; use RoadRunner\VersionChecker\Environment\EnvironmentInterface; use RoadRunner\VersionChecker\Exception\RoadrunnerNotInstalledException; use RoadRunner\VersionChecker\Process\ProcessInterface; use RoadRunner\VersionChecker\Version\Installed; use Symfony\Component\Process\Exception\ProcessFailedException; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Expect; +use Testo\Lifecycle\AfterTest; +use Testo\Test; -final class InstalledTest extends TestCase +final class InstalledTest { + #[AfterTest] protected function tearDown(): void { // clean the cache @@ -21,110 +27,80 @@ protected function tearDown(): void $ref->setValue(null); } - /** - * @dataProvider outputDataProvider - */ + #[Test] + #[DataProvider('outputDataProvider')] public function testGetInstalledVersion(string $version, string $output): void { - $process = $this->createMock(ProcessInterface::class); - $process - ->expects($this->once()) - ->method('exec') - ->with(['./rr', '--version']) - ->willReturn($output); + $process = Mockery::mock(ProcessInterface::class)->shouldIgnoreMissing(); + $process->shouldReceive('exec')->once()->with(['./rr', '--version'], Mockery::andAnyOtherArgs())->andReturn($output); $installed = new Installed($process); - $this->assertSame($version, $installed->getInstalledVersion()); + Assert::same($installed->getInstalledVersion(), $version); } + #[Test] public function testCachedVersion(): void { - $env = $this->createMock(EnvironmentInterface::class); - $env - // $this->once() is important for this test! - ->expects($this->once()) - ->method('get') - ->with('RR_VERSION') - ->willReturn('2023.1.0'); + $env = Mockery::mock(EnvironmentInterface::class)->shouldIgnoreMissing(); + $env->shouldReceive('get')->once()->with('RR_VERSION', Mockery::andAnyOtherArgs())->andReturn('2023.1.0'); $installed = new Installed(environment: $env); $version = $installed->getInstalledVersion(); $version2 = $installed->getInstalledVersion(); - $this->assertSame('2023.1.0', $version); - $this->assertSame('2023.1.0', $version2); + Assert::same($version, '2023.1.0'); + Assert::same($version2, '2023.1.0'); } public function getVersionFromEnv(): void { - $env = $this->createMock(EnvironmentInterface::class); - $env - ->expects($this->once()) - ->method('get') - ->with('RR_VERSION') - ->willReturn('2023.1.0'); + $env = Mockery::mock(EnvironmentInterface::class)->shouldIgnoreMissing(); + $env->shouldReceive('get')->once()->with('RR_VERSION', Mockery::andAnyOtherArgs())->andReturn('2023.1.0'); - $process = $this->createMock(ProcessInterface::class); - $process->expects($this->never()); + $process = Mockery::mock(ProcessInterface::class)->shouldIgnoreMissing(); + $process->shouldNotReceive('exec'); $installed = new Installed($process, $env); - $this->assertSame('2023.1.0', $installed->getInstalledVersion()); + Assert::same($installed->getInstalledVersion(), '2023.1.0'); } public function getVersionFromConsoleCommand(): void { - $env = $this->createMock(EnvironmentInterface::class); - $env - ->expects($this->once()) - ->method('get') - ->with('RR_VERSION') - ->willReturn(null); - - $process = $this->createMock(ProcessInterface::class); - $process - ->expects($this->once()) - ->method('exec') - ->with(['./rr', '--version']) - ->willReturn('version 2023.1.0'); + $env = Mockery::mock(EnvironmentInterface::class)->shouldIgnoreMissing(); + $env->shouldReceive('get')->once()->with('RR_VERSION', Mockery::andAnyOtherArgs())->andReturn(null); + + $process = Mockery::mock(ProcessInterface::class)->shouldIgnoreMissing(); + $process->shouldReceive('exec')->once()->with(['./rr', '--version'], Mockery::andAnyOtherArgs())->andReturn('version 2023.1.0'); $installed = new Installed($process, $env); - $this->assertSame('2023.1.0', $installed->getInstalledVersion()); + Assert::same($installed->getInstalledVersion(), '2023.1.0'); } + #[Test] public function testGetInstalledVersionRoadRunnerIsNotInstalled(): void { - $process = $this->createMock(ProcessInterface::class); - $process - ->expects($this->once()) - ->method('exec') - ->with(['./rr', '--version']) - ->willThrowException( - (new \ReflectionClass(ProcessFailedException::class))->newInstanceWithoutConstructor() - ); + $process = Mockery::mock(ProcessInterface::class)->shouldIgnoreMissing(); + $process->shouldReceive('exec')->once()->with(['./rr', '--version'], Mockery::andAnyOtherArgs())->andThrow((new \ReflectionClass(ProcessFailedException::class))->newInstanceWithoutConstructor()); $installed = new Installed($process); - $this->expectException(RoadrunnerNotInstalledException::class); + Expect::exception(RoadrunnerNotInstalledException::class); $installed->getInstalledVersion(); } + #[Test] public function testGetInstalledVersionUnableToDetermineVersion(): void { - $process = $this->createMock(ProcessInterface::class); - $process - ->expects($this->once()) - ->method('exec') - ->with(['./rr', '--version']) - ->willReturn('foo'); + $process = Mockery::mock(ProcessInterface::class)->shouldIgnoreMissing(); + $process->shouldReceive('exec')->once()->with(['./rr', '--version'], Mockery::andAnyOtherArgs())->andReturn('foo'); $installed = new Installed($process); - $this->expectException(RoadrunnerNotInstalledException::class); - $this->expectExceptionMessage('Unable to determine RoadRunner version.'); + Expect::exception(RoadrunnerNotInstalledException::class)->withMessageContaining('Unable to determine RoadRunner version.'); $installed->getInstalledVersion(); } diff --git a/tests/src/Unit/Version/RequiredTest.php b/tests/src/Unit/Version/RequiredTest.php index b26c915..793231d 100644 --- a/tests/src/Unit/Version/RequiredTest.php +++ b/tests/src/Unit/Version/RequiredTest.php @@ -4,12 +4,18 @@ namespace RoadRunner\VersionChecker\Tests\Unit\Version; -use PHPUnit\Framework\TestCase; +use Mockery; use RoadRunner\VersionChecker\Composer\PackageInterface; use RoadRunner\VersionChecker\Version\Required; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Lifecycle\AfterTest; +use Testo\Test; -final class RequiredTest extends TestCase +#[Test] +final class RequiredTest { + #[AfterTest] protected function tearDown(): void { // clean the cache @@ -18,46 +24,35 @@ protected function tearDown(): void $ref->setValue(null); } - /** - * @dataProvider versionsDataProvider - */ + #[DataProvider('versionsDataProvider')] public function testGetMaximumVersion(string $version, ?string $previous, string $expected): void { $required = new Required(); $ref = new \ReflectionMethod($required, 'getMaximumVersion'); $ref->setAccessible(true); - $this->assertSame($expected, $ref->invoke($required, $version, $previous)); + Assert::same($ref->invoke($required, $version, $previous), $expected); } public function testGetRequiredVersion(): void { - $package = $this->createMock(PackageInterface::class); - $package - ->expects($this->once()) - ->method('getRequiredVersions') - ->with('spiral/roadrunner') - ->willReturn(['2.0', '1.0', '2.0.0.0-dev', '2.0.0-alpha']); + $package = Mockery::mock(PackageInterface::class)->shouldIgnoreMissing(); + $package->shouldReceive('getRequiredVersions')->once()->with('spiral/roadrunner', Mockery::andAnyOtherArgs())->andReturn(['2.0', '1.0', '2.0.0.0-dev', '2.0.0-alpha']); $required = new Required($package); - $this->assertSame('2.0.0.0-dev', $required->getRequiredVersion()); + Assert::same($required->getRequiredVersion(), '2.0.0.0-dev'); } public function testGetCachedVersion(): void { - $package = $this->createMock(PackageInterface::class); - $package - // $this->once() is important for this test! - ->expects($this->once()) - ->method('getRequiredVersions') - ->with('spiral/roadrunner') - ->willReturn(['1.0']); + $package = Mockery::mock(PackageInterface::class)->shouldIgnoreMissing(); + $package->shouldReceive('getRequiredVersions')->once()->with('spiral/roadrunner', Mockery::andAnyOtherArgs())->andReturn(['1.0']); $required = new Required($package); - $this->assertSame('1.0', $required->getRequiredVersion()); - $this->assertSame('1.0', $required->getRequiredVersion()); + Assert::same($required->getRequiredVersion(), '1.0'); + Assert::same($required->getRequiredVersion(), '1.0'); } public static function versionsDataProvider(): \Traversable diff --git a/tests/src/Unit/VersionCheckerTest.php b/tests/src/Unit/VersionCheckerTest.php index cc0105b..a883139 100644 --- a/tests/src/Unit/VersionCheckerTest.php +++ b/tests/src/Unit/VersionCheckerTest.php @@ -4,35 +4,32 @@ namespace RoadRunner\VersionChecker\Tests\Unit; -use PHPUnit\Framework\TestCase; +use Mockery; use RoadRunner\VersionChecker\Exception\RequiredVersionException; use RoadRunner\VersionChecker\Exception\UnsupportedVersionException; use RoadRunner\VersionChecker\Version\ComparatorInterface; use RoadRunner\VersionChecker\Version\InstalledInterface; use RoadRunner\VersionChecker\Version\RequiredInterface; use RoadRunner\VersionChecker\VersionChecker; +use Testo\Assert; +use Testo\Data\DataProvider; +use Testo\Expect; +use Testo\Test; -final class VersionCheckerTest extends TestCase +#[Test] +final class VersionCheckerTest { - /** - * @dataProvider invalidVersionsDataProvider - */ + #[DataProvider('invalidVersionsDataProvider')] public function testSuccessGreaterThanWithoutVersion(?string $version = null): void { - $comparator = $this->createMock(ComparatorInterface::class); - $comparator - ->expects($this->once()) - ->method('greaterThan') - ->willReturn(true); - - $requiredVersion = $this->createMock(RequiredInterface::class); - $requiredVersion - ->expects($this->once()) - ->method('getRequiredVersion') - ->willReturn('1.0'); + $comparator = Mockery::mock(ComparatorInterface::class)->shouldIgnoreMissing(); + $comparator->shouldReceive('greaterThan')->once()->andReturn(true); + + $requiredVersion = Mockery::mock(RequiredInterface::class)->shouldIgnoreMissing(); + $requiredVersion->shouldReceive('getRequiredVersion')->once()->andReturn('1.0'); $checker = new VersionChecker( - $this->createMock(InstalledInterface::class), + Mockery::mock(InstalledInterface::class)->shouldIgnoreMissing(), $requiredVersion, $comparator ); @@ -42,19 +39,14 @@ public function testSuccessGreaterThanWithoutVersion(?string $version = null): v public function testSuccessGreaterThanWithVersion(): void { - $comparator = $this->createMock(ComparatorInterface::class); - $comparator - ->expects($this->once()) - ->method('greaterThan') - ->willReturn(true); + $comparator = Mockery::mock(ComparatorInterface::class)->shouldIgnoreMissing(); + $comparator->shouldReceive('greaterThan')->once()->andReturn(true); - $requiredVersion = $this->createMock(RequiredInterface::class); - $requiredVersion - ->expects($this->never()) - ->method('getRequiredVersion'); + $requiredVersion = Mockery::mock(RequiredInterface::class)->shouldIgnoreMissing(); + $requiredVersion->shouldReceive('getRequiredVersion')->never(); $checker = new VersionChecker( - $this->createMock(InstalledInterface::class), + Mockery::mock(InstalledInterface::class)->shouldIgnoreMissing(), $requiredVersion, $comparator ); @@ -64,48 +56,33 @@ public function testSuccessGreaterThanWithVersion(): void public function testGreaterThanWithoutVersionAndWithoutRoadRunnerPackage(): void { - $comparator = $this->createMock(ComparatorInterface::class); - $comparator - ->expects($this->never()) - ->method('greaterThan'); + $comparator = Mockery::mock(ComparatorInterface::class)->shouldIgnoreMissing(); + $comparator->shouldReceive('greaterThan')->never(); - $requiredVersion = $this->createMock(RequiredInterface::class); - $requiredVersion - ->expects($this->once()) - ->method('getRequiredVersion') - ->willReturn(null); + $requiredVersion = Mockery::mock(RequiredInterface::class)->shouldIgnoreMissing(); + $requiredVersion->shouldReceive('getRequiredVersion')->once()->andReturn(null); $checker = new VersionChecker( - $this->createMock(InstalledInterface::class), + Mockery::mock(InstalledInterface::class)->shouldIgnoreMissing(), $requiredVersion, $comparator ); - $this->expectException(RequiredVersionException::class); + Expect::exception(RequiredVersionException::class); $checker->greaterThan(); } - /** - * @dataProvider invalidVersionsDataProvider - */ + #[DataProvider('invalidVersionsDataProvider')] public function testFailGreaterThanWithoutVersion(?string $version = null): void { - $comparator = $this->createMock(ComparatorInterface::class); - $comparator - ->expects($this->once()) - ->method('greaterThan') - ->willReturn(false); - - $installedVersion = $this->createMock(InstalledInterface::class); - $installedVersion - ->expects($this->once()) - ->method('getInstalledVersion') - ->willReturn('1.0'); - - $requiredVersion = $this->createMock(RequiredInterface::class); - $requiredVersion - ->method('getRequiredVersion') - ->willReturn('2023.1'); + $comparator = Mockery::mock(ComparatorInterface::class)->shouldIgnoreMissing(); + $comparator->shouldReceive('greaterThan')->once()->andReturn(false); + + $installedVersion = Mockery::mock(InstalledInterface::class)->shouldIgnoreMissing(); + $installedVersion->shouldReceive('getInstalledVersion')->once()->andReturn('1.0'); + + $requiredVersion = Mockery::mock(RequiredInterface::class)->shouldIgnoreMissing(); + $requiredVersion->shouldReceive('getRequiredVersion')->andReturn('2023.1'); $checker = new VersionChecker($installedVersion, $requiredVersion, $comparator); @@ -114,32 +91,21 @@ public function testFailGreaterThanWithoutVersion(?string $version = null): void } catch (UnsupportedVersionException $exception) { } - $this->assertSame('1.0', $exception->getInstalledVersion()); - $this->assertSame('2023.1', $exception->getRequestedVersion()); - $this->assertSame( - 'Installed RoadRunner version `1.0` not supported. Requires version `2023.1` or higher.', - $exception->getMessage() - ); + Assert::same($exception->getInstalledVersion(), '1.0'); + Assert::same($exception->getRequestedVersion(), '2023.1'); + Assert::same($exception->getMessage(), 'Installed RoadRunner version `1.0` not supported. Requires version `2023.1` or higher.'); } public function testFailGreaterThanWithVersion(): void { - $comparator = $this->createMock(ComparatorInterface::class); - $comparator - ->expects($this->once()) - ->method('greaterThan') - ->willReturn(false); - - $installedVersion = $this->createMock(InstalledInterface::class); - $installedVersion - ->expects($this->once()) - ->method('getInstalledVersion') - ->willReturn('1.0'); - - $requiredVersion = $this->createMock(RequiredInterface::class); - $requiredVersion - ->expects($this->never()) - ->method('getRequiredVersion'); + $comparator = Mockery::mock(ComparatorInterface::class)->shouldIgnoreMissing(); + $comparator->shouldReceive('greaterThan')->once()->andReturn(false); + + $installedVersion = Mockery::mock(InstalledInterface::class)->shouldIgnoreMissing(); + $installedVersion->shouldReceive('getInstalledVersion')->once()->andReturn('1.0'); + + $requiredVersion = Mockery::mock(RequiredInterface::class)->shouldIgnoreMissing(); + $requiredVersion->shouldReceive('getRequiredVersion')->never(); $checker = new VersionChecker($installedVersion, $requiredVersion, $comparator); @@ -148,25 +114,19 @@ public function testFailGreaterThanWithVersion(): void } catch (UnsupportedVersionException $exception) { } - $this->assertSame('1.0', $exception->getInstalledVersion()); - $this->assertSame('2.0', $exception->getRequestedVersion()); - $this->assertSame( - 'Installed RoadRunner version `1.0` not supported. Requires version `2.0` or higher.', - $exception->getMessage() - ); + Assert::same($exception->getInstalledVersion(), '1.0'); + Assert::same($exception->getRequestedVersion(), '2.0'); + Assert::same($exception->getMessage(), 'Installed RoadRunner version `1.0` not supported. Requires version `2.0` or higher.'); } public function testSuccessLessThan(): void { - $comparator = $this->createMock(ComparatorInterface::class); - $comparator - ->expects($this->once()) - ->method('lessThan') - ->willReturn(true); + $comparator = Mockery::mock(ComparatorInterface::class)->shouldIgnoreMissing(); + $comparator->shouldReceive('lessThan')->once()->andReturn(true); $checker = new VersionChecker( - $this->createMock(InstalledInterface::class), - $this->createMock(RequiredInterface::class), + Mockery::mock(InstalledInterface::class)->shouldIgnoreMissing(), + Mockery::mock(RequiredInterface::class)->shouldIgnoreMissing(), $comparator ); @@ -175,21 +135,15 @@ public function testSuccessLessThan(): void public function testFailLessThan(): void { - $comparator = $this->createMock(ComparatorInterface::class); - $comparator - ->expects($this->once()) - ->method('lessThan') - ->willReturn(false); - - $installedVersion = $this->createMock(InstalledInterface::class); - $installedVersion - ->expects($this->once()) - ->method('getInstalledVersion') - ->willReturn('2.0'); + $comparator = Mockery::mock(ComparatorInterface::class)->shouldIgnoreMissing(); + $comparator->shouldReceive('lessThan')->once()->andReturn(false); + + $installedVersion = Mockery::mock(InstalledInterface::class)->shouldIgnoreMissing(); + $installedVersion->shouldReceive('getInstalledVersion')->once()->andReturn('2.0'); $checker = new VersionChecker( $installedVersion, - $this->createMock(RequiredInterface::class), + Mockery::mock(RequiredInterface::class)->shouldIgnoreMissing(), $comparator ); @@ -198,25 +152,19 @@ public function testFailLessThan(): void } catch (UnsupportedVersionException $exception) { } - $this->assertSame('2.0', $exception->getInstalledVersion()); - $this->assertSame('1.0', $exception->getRequestedVersion()); - $this->assertSame( - 'Installed RoadRunner version `2.0` not supported. Requires version `1.0` or lower.', - $exception->getMessage() - ); + Assert::same($exception->getInstalledVersion(), '2.0'); + Assert::same($exception->getRequestedVersion(), '1.0'); + Assert::same($exception->getMessage(), 'Installed RoadRunner version `2.0` not supported. Requires version `1.0` or lower.'); } public function testSuccessEqual(): void { - $comparator = $this->createMock(ComparatorInterface::class); - $comparator - ->expects($this->once()) - ->method('equal') - ->willReturn(true); + $comparator = Mockery::mock(ComparatorInterface::class)->shouldIgnoreMissing(); + $comparator->shouldReceive('equal')->once()->andReturn(true); $checker = new VersionChecker( - $this->createMock(InstalledInterface::class), - $this->createMock(RequiredInterface::class), + Mockery::mock(InstalledInterface::class)->shouldIgnoreMissing(), + Mockery::mock(RequiredInterface::class)->shouldIgnoreMissing(), $comparator ); @@ -225,21 +173,15 @@ public function testSuccessEqual(): void public function testFailEqual(): void { - $comparator = $this->createMock(ComparatorInterface::class); - $comparator - ->expects($this->once()) - ->method('equal') - ->willReturn(false); - - $installedVersion = $this->createMock(InstalledInterface::class); - $installedVersion - ->expects($this->once()) - ->method('getInstalledVersion') - ->willReturn('2.0'); + $comparator = Mockery::mock(ComparatorInterface::class)->shouldIgnoreMissing(); + $comparator->shouldReceive('equal')->once()->andReturn(false); + + $installedVersion = Mockery::mock(InstalledInterface::class)->shouldIgnoreMissing(); + $installedVersion->shouldReceive('getInstalledVersion')->once()->andReturn('2.0'); $checker = new VersionChecker( $installedVersion, - $this->createMock(RequiredInterface::class), + Mockery::mock(RequiredInterface::class)->shouldIgnoreMissing(), $comparator ); @@ -248,27 +190,19 @@ public function testFailEqual(): void } catch (UnsupportedVersionException $exception) { } - $this->assertSame('2.0', $exception->getInstalledVersion()); - $this->assertSame('1.0', $exception->getRequestedVersion()); - $this->assertSame( - 'Installed RoadRunner version `2.0` not supported. Requires version `1.0`.', - $exception->getMessage() - ); + Assert::same($exception->getInstalledVersion(), '2.0'); + Assert::same($exception->getRequestedVersion(), '1.0'); + Assert::same($exception->getMessage(), 'Installed RoadRunner version `2.0` not supported. Requires version `1.0`.'); } - /** - * @dataProvider getFormattedMessageDataProvider - */ + #[DataProvider('getFormattedMessageDataProvider')] public function testGetFormattedMessage(string $version, string $expected): void { $checker = new VersionChecker(); $ref = new \ReflectionMethod($checker, 'getFormattedMessage'); $ref->setAccessible(true); - $this->assertSame( - \sprintf('installed 1 required %s', $expected), - $ref->invoke($checker, 'installed %s required %s', '1', $version) - ); + Assert::same($ref->invoke($checker, 'installed %s required %s', '1', $version), \sprintf('installed 1 required %s', $expected)); } public static function invalidVersionsDataProvider(): \Traversable