|
| 1 | +<?php |
| 2 | + |
| 3 | +declare(strict_types=1); |
| 4 | + |
| 5 | +namespace RoadRunner\VersionChecker\Tests\Unit; |
| 6 | + |
| 7 | +use PHPUnit\Framework\TestCase; |
| 8 | +use RoadRunner\VersionChecker\Exception\RoadrunnerNotInstalledException; |
| 9 | +use RoadRunner\VersionChecker\Process\ProcessInterface; |
| 10 | +use RoadRunner\VersionChecker\Version\Installed; |
| 11 | +use Symfony\Component\Process\Exception\ProcessFailedException; |
| 12 | + |
| 13 | +final class InstalledTest extends TestCase |
| 14 | +{ |
| 15 | + /** |
| 16 | + * @dataProvider outputDataProvider |
| 17 | + */ |
| 18 | + public function testGetInstalledVersion(string $version, string $output): void |
| 19 | + { |
| 20 | + $process = $this->createMock(ProcessInterface::class); |
| 21 | + $process |
| 22 | + ->expects($this->once()) |
| 23 | + ->method('exec') |
| 24 | + ->with(['./rr', '--version']) |
| 25 | + ->willReturn($output); |
| 26 | + |
| 27 | + $installed = new Installed($process); |
| 28 | + |
| 29 | + $this->assertSame($version, $installed->getInstalledVersion()); |
| 30 | + } |
| 31 | + |
| 32 | + public function testGetInstalledVersionRoadRunnerIsNotInstalled(): void |
| 33 | + { |
| 34 | + $process = $this->createMock(ProcessInterface::class); |
| 35 | + $process |
| 36 | + ->expects($this->once()) |
| 37 | + ->method('exec') |
| 38 | + ->with(['./rr', '--version']) |
| 39 | + ->willThrowException( |
| 40 | + (new \ReflectionClass(ProcessFailedException::class))->newInstanceWithoutConstructor() |
| 41 | + ); |
| 42 | + |
| 43 | + $installed = new Installed($process); |
| 44 | + |
| 45 | + $this->expectException(RoadrunnerNotInstalledException::class); |
| 46 | + $installed->getInstalledVersion(); |
| 47 | + } |
| 48 | + |
| 49 | + public function testGetInstalledVersionUnableToDetermineVersion(): void |
| 50 | + { |
| 51 | + $process = $this->createMock(ProcessInterface::class); |
| 52 | + $process |
| 53 | + ->expects($this->once()) |
| 54 | + ->method('exec') |
| 55 | + ->with(['./rr', '--version']) |
| 56 | + ->willReturn('foo'); |
| 57 | + |
| 58 | + $installed = new Installed($process); |
| 59 | + |
| 60 | + $this->expectException(RoadrunnerNotInstalledException::class); |
| 61 | + $this->expectExceptionMessage('Unable to determine RoadRunner version.'); |
| 62 | + $installed->getInstalledVersion(); |
| 63 | + } |
| 64 | + |
| 65 | + public static function outputDataProvider(): \Traversable |
| 66 | + { |
| 67 | + yield ['2.12.3', 'rr version 2.12.3 (build time: 2023-02-16T13:08:23+0000, go1.20), OS: darwin, arch: arm64']; |
| 68 | + yield ['2023.1.0-rc.2', 'rr version 2023.1.0-rc.2 (build time: 2023-02-16T13:08:23+0000, go1.20)']; |
| 69 | + yield ['2023.1.0-beta', 'version 2023.1.0-beta']; |
| 70 | + } |
| 71 | +} |
0 commit comments