diff --git a/.vortex/installer/phpunit.xml b/.vortex/installer/phpunit.xml index 38c5d687cc..b6f3e8b041 100644 --- a/.vortex/installer/phpunit.xml +++ b/.vortex/installer/phpunit.xml @@ -8,11 +8,17 @@ beStrictAboutOutputDuringTests="true" failOnRisky="true" failOnWarning="true" + failOnNotice="true" + failOnDeprecation="true" + failOnPhpunitWarning="true" + failOnPhpunitNotice="true" + failOnPhpunitDeprecation="true" displayDetailsOnTestsThatTriggerWarnings="true" displayDetailsOnTestsThatTriggerErrors="true" displayDetailsOnTestsThatTriggerNotices="true" displayDetailsOnTestsThatTriggerDeprecations="true" - displayDetailsOnPhpunitDeprecations="true"> + displayDetailsOnPhpunitDeprecations="true" + displayDetailsOnPhpunitNotices="true"> tests/Unit diff --git a/.vortex/installer/tests/Functional/Command/BuildCommandTest.php b/.vortex/installer/tests/Functional/Command/BuildCommandTest.php index 8e587a276d..e3df0b83f8 100644 --- a/.vortex/installer/tests/Functional/Command/BuildCommandTest.php +++ b/.vortex/installer/tests/Functional/Command/BuildCommandTest.php @@ -14,7 +14,6 @@ use DrevOps\VortexInstaller\Tests\Helpers\TuiOutput; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Process\ExecutableFinder; /** @@ -42,12 +41,12 @@ public function testBuildCommand( $command_inputs = $before($command_inputs, self::$tmp); } // Create a mock ProcessRunner for ahoy build. - $build_process_runner = $this->createMock(ProcessRunner::class); + $build_process_runner = $this->createStub(ProcessRunner::class); // Set up common default behaviors. $current_command = ''; $build_process_runner->method('run') - ->willReturnCallback(function (string $command) use ($build_process_runner, &$current_command): MockObject { + ->willReturnCallback(function (string $command) use ($build_process_runner, &$current_command): ProcessRunner { $current_command = $command; return $build_process_runner; }); @@ -84,7 +83,7 @@ public function testBuildCommand( }); // Mock logger to prevent errors in showSuccessSummary/showFailureSummary. - $mock_logger = $this->createMock(FileLoggerInterface::class); + $mock_logger = $this->createStub(FileLoggerInterface::class); $mock_logger->method('getPath')->willReturn('/tmp/mock.log'); $build_process_runner->method('getLogger')->willReturn($mock_logger); @@ -93,7 +92,7 @@ public function testBuildCommand( // Always register CheckRequirementsCommand with mocked runner and finder. // Mock ExecutableFinder. - $requirements_finder = $this->createMock(ExecutableFinder::class); + $requirements_finder = $this->createStub(ExecutableFinder::class); $final_finder_callback = $requirements_finder_callback ?? fn(string $name): string => '/usr/bin/' . $name; $requirements_finder->method('find') ->willReturnCallback(fn(string $name) => $final_finder_callback($name)); @@ -110,11 +109,11 @@ public function testBuildCommand( // Mock ProcessRunner - use provided callback or default to // success (exit code 0). - $requirements_runner = $this->createMock(ProcessRunner::class); + $requirements_runner = $this->createStub(ProcessRunner::class); $current_requirements_command = ''; $requirements_runner->method('run') - ->willReturnCallback(function (string $command) use ($requirements_runner, &$current_requirements_command): MockObject { + ->willReturnCallback(function (string $command) use ($requirements_runner, &$current_requirements_command): ProcessRunner { $current_requirements_command = $command; return $requirements_runner; }); diff --git a/.vortex/installer/tests/Functional/Command/CheckRequirementsCommandTest.php b/.vortex/installer/tests/Functional/Command/CheckRequirementsCommandTest.php index 3c4be92673..7d363ce384 100644 --- a/.vortex/installer/tests/Functional/Command/CheckRequirementsCommandTest.php +++ b/.vortex/installer/tests/Functional/Command/CheckRequirementsCommandTest.php @@ -12,7 +12,6 @@ use DrevOps\VortexInstaller\Tests\Helpers\TuiOutput; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Process\ExecutableFinder; /** @@ -37,17 +36,17 @@ public function testCheckRequirementsCommand( $command_inputs = $before($command_inputs, self::$tmp); } // Create a mock ExecutableFinder. - $mock_finder = $this->createMock(ExecutableFinder::class); + $mock_finder = $this->createStub(ExecutableFinder::class); $mock_finder->method('find') ->willReturnCallback(fn(string $name) => $executable_finder_callback($name)); // Create a mock ProcessRunner. - $mock_runner = $this->createMock(ProcessRunner::class); + $mock_runner = $this->createStub(ProcessRunner::class); // Set up common default behaviors. $current_command = ''; $mock_runner->method('run') - ->willReturnCallback(function (string $command) use ($mock_runner, &$current_command): MockObject { + ->willReturnCallback(function (string $command) use ($mock_runner, &$current_command): ProcessRunner { $current_command = $command; return $mock_runner; }); diff --git a/.vortex/installer/tests/Functional/Command/InstallCommandTest.php b/.vortex/installer/tests/Functional/Command/InstallCommandTest.php index abbbc39c12..301a88d41b 100644 --- a/.vortex/installer/tests/Functional/Command/InstallCommandTest.php +++ b/.vortex/installer/tests/Functional/Command/InstallCommandTest.php @@ -22,7 +22,6 @@ use DrevOps\VortexInstaller\Utils\OptionsResolver; use PHPUnit\Framework\Attributes\CoversClass; use PHPUnit\Framework\Attributes\DataProvider; -use PHPUnit\Framework\MockObject\MockObject; use Symfony\Component\Process\ExecutableFinder; /** @@ -49,15 +48,15 @@ public function testInstallCommand( bool $download_should_fail = FALSE, ): void { // 1. Mock ExecutableFinder for InstallCommand (requirements checking). - $executable_finder = $this->createMock(ExecutableFinder::class); + $executable_finder = $this->createStub(ExecutableFinder::class); $executable_finder->method('find') ->willReturnCallback(fn(string $name) => $install_executable_finder_find_callback($name)); // 2. Mock ProcessRunner for BuildCommand (runs 'ahoy build'). - $build_runner = $this->createMock(ProcessRunner::class); + $build_runner = $this->createStub(ProcessRunner::class); $build_runner_command = ''; $build_runner->method('run') - ->willReturnCallback(function (string $command) use ($build_runner, &$build_runner_command): MockObject { + ->willReturnCallback(function (string $command) use ($build_runner, &$build_runner_command): ProcessRunner { $build_runner_command = $command; return $build_runner; }); @@ -68,7 +67,7 @@ public function testInstallCommand( // Mock other BuildCommand runner methods. $build_runner->method('getOutput')->willReturnCallback(fn(bool $as_array = FALSE): array|string => $as_array ? ['Mock build output line 1', 'Mock build output line 2'] : 'Mock build output'); $build_runner->method('getCommand')->willReturn('ahoy build'); - $mock_logger = $this->createMock(FileLoggerInterface::class); + $mock_logger = $this->createStub(FileLoggerInterface::class); $mock_logger->method('getPath')->willReturn('/tmp/mock.log'); $build_runner->method('getLogger')->willReturn($mock_logger); $build_runner->method('setCwd')->willReturn($build_runner); @@ -76,10 +75,10 @@ public function testInstallCommand( $build_runner->method('getExecutableFinder')->willReturn($executable_finder); // 3. Mock ProcessRunner for CheckRequirementsCommand. - $check_requirements_runner = $this->createMock(ProcessRunner::class); + $check_requirements_runner = $this->createStub(ProcessRunner::class); $check_requirements_runner_command = ''; $check_requirements_runner->method('run') - ->willReturnCallback(function (string $command) use ($check_requirements_runner, &$check_requirements_runner_command): MockObject { + ->willReturnCallback(function (string $command) use ($check_requirements_runner, &$check_requirements_runner_command): ProcessRunner { $check_requirements_runner_command = $command; return $check_requirements_runner; }); @@ -96,7 +95,7 @@ public function testInstallCommand( $install_command->setExecutableFinder($executable_finder); if ($download_should_fail) { - $mock_downloader = $this->createMock(RepositoryDownloader::class); + $mock_downloader = $this->createStub(RepositoryDownloader::class); $mock_downloader->method('download')->willThrowException(new \RuntimeException('Failed to download Vortex.')); $install_command->setRepositoryDownloader($mock_downloader); } @@ -508,14 +507,14 @@ public static function dataProviderInstallCommand(): \Iterator { */ #[DataProvider('dataProviderInstallCommandMajorGate')] public function testInstallCommandMajorGate(?string $version, string $composer_json, bool $mock_download_fail, string $expected_message): void { - $executable_finder = $this->createMock(ExecutableFinder::class); + $executable_finder = $this->createStub(ExecutableFinder::class); $executable_finder->method('find')->willReturnCallback(fn(string $command): string => '/usr/bin/' . $command); $install_command = new InstallCommand(); $install_command->setExecutableFinder($executable_finder); if ($mock_download_fail) { - $mock_downloader = $this->createMock(RepositoryDownloader::class); + $mock_downloader = $this->createStub(RepositoryDownloader::class); $mock_downloader->method('download')->willThrowException(new \RuntimeException('Failed to download Vortex.')); $install_command->setRepositoryDownloader($mock_downloader); } diff --git a/.vortex/installer/tests/Functional/Command/InstallExcludedPathsTest.php b/.vortex/installer/tests/Functional/Command/InstallExcludedPathsTest.php index c155296e9c..f4a7e5e96b 100644 --- a/.vortex/installer/tests/Functional/Command/InstallExcludedPathsTest.php +++ b/.vortex/installer/tests/Functional/Command/InstallExcludedPathsTest.php @@ -222,7 +222,7 @@ protected function templateRef(): string { * Run a non-interactive install into the system under test. */ protected function runInstall(string $prompts, string $ref): void { - $executable_finder = $this->createMock(ExecutableFinder::class); + $executable_finder = $this->createStub(ExecutableFinder::class); $executable_finder->method('find')->willReturnCallback(fn(string $command): string => '/usr/bin/' . $command); $install_command = new InstallCommand(); diff --git a/.vortex/installer/tests/Unit/Downloader/DownloaderTest.php b/.vortex/installer/tests/Unit/Downloader/DownloaderTest.php index ec3aba7b79..bea5828e72 100644 --- a/.vortex/installer/tests/Unit/Downloader/DownloaderTest.php +++ b/.vortex/installer/tests/Unit/Downloader/DownloaderTest.php @@ -17,7 +17,7 @@ class DownloaderTest extends UnitTestCase { public function testDownloadSuccess(): void { $mock_http_client = $this->createMock(ClientInterface::class); - $mock_response = $this->createMock(ResponseInterface::class); + $mock_response = $this->createStub(ResponseInterface::class); $mock_response->method('getStatusCode')->willReturn(200); $mock_http_client->expects($this->once()) ->method('request') @@ -37,9 +37,9 @@ public function testDownloadSuccess(): void { } public function testDownloadFailure(): void { - $mock_http_client = $this->createMock(ClientInterface::class); + $mock_http_client = $this->createStub(ClientInterface::class); $mock_http_client->method('request') - ->willThrowException(new RequestException('Network error', $this->createMock(RequestInterface::class))); + ->willThrowException(new RequestException('Network error', $this->createStub(RequestInterface::class))); $destination = self::$tmp . '/downloaded_file.sql'; @@ -53,7 +53,7 @@ public function testDownloadFailure(): void { public function testDownloadFollowsRedirects(): void { $mock_http_client = $this->createMock(ClientInterface::class); - $mock_response = $this->createMock(ResponseInterface::class); + $mock_response = $this->createStub(ResponseInterface::class); $mock_response->method('getStatusCode')->willReturn(200); $mock_http_client->expects($this->once()) @@ -80,7 +80,7 @@ public function testDownloadWithDefaultClient(): void { public function testDownloadWithCustomHeaders(): void { $mock_http_client = $this->createMock(ClientInterface::class); - $mock_response = $this->createMock(ResponseInterface::class); + $mock_response = $this->createStub(ResponseInterface::class); $mock_response->method('getStatusCode')->willReturn(200); $custom_headers = [ diff --git a/.vortex/installer/tests/Unit/Downloader/RepositoryDownloaderTest.php b/.vortex/installer/tests/Unit/Downloader/RepositoryDownloaderTest.php index 28e4cbdcf7..04bad72bb3 100644 --- a/.vortex/installer/tests/Unit/Downloader/RepositoryDownloaderTest.php +++ b/.vortex/installer/tests/Unit/Downloader/RepositoryDownloaderTest.php @@ -25,12 +25,12 @@ class RepositoryDownloaderTest extends UnitTestCase { public function testDownloadWithMockedArchiver(): void { - $mock_http_client = $this->createMockHttpClient(); + $mock_http_client = $this->stubHttpClient(); /** @var \PHPUnit\Framework\MockObject\MockObject&\DrevOps\VortexInstaller\Downloader\ArchiverInterface $mock_archiver */ $mock_archiver = $this->createMockArchiver(); $mock_archiver->expects($this->once())->method('validate'); $mock_archiver->expects($this->once())->method('extract'); - $mock_file_downloader = $this->createMockFileDownloader(); + $mock_file_downloader = $this->stubFileDownloader(); $destination = self::$tmp . '/destination'; File::mkdir($destination); File::dump($destination . '/composer.json', '{}'); @@ -40,9 +40,9 @@ public function testDownloadWithMockedArchiver(): void { } public function testDownloadThrowsExceptionWhenComposerJsonMissing(): void { - $mock_http_client = $this->createMock(ClientInterface::class); - $mock_archiver = $this->createMock(ArchiverInterface::class); - $mock_file_downloader = $this->createMockFileDownloader(); + $mock_http_client = $this->createStub(ClientInterface::class); + $mock_archiver = $this->createStub(ArchiverInterface::class); + $mock_file_downloader = $this->stubFileDownloader(); $destination = self::$tmp . '/destination'; File::mkdir($destination); @@ -56,9 +56,9 @@ public function testDownloadThrowsExceptionWhenComposerJsonMissing(): void { } public function testDownloadFromRemoteCallsArchiverCorrectly(): void { - $mock_http_client = $this->createMock(ClientInterface::class); + $mock_http_client = $this->createStub(ClientInterface::class); $mock_archiver = $this->createMock(ArchiverInterface::class); - $mock_file_downloader = $this->createMockFileDownloader(); + $mock_file_downloader = $this->stubFileDownloader(); $mock_archiver->expects($this->once())->method('validate')->with($this->stringContains('vortex_archive_')); $mock_archiver->expects($this->once())->method('extract')->with($this->stringContains('vortex_archive_'), $this->anything(), TRUE); @@ -72,9 +72,9 @@ public function testDownloadFromRemoteCallsArchiverCorrectly(): void { } public function testDownloadArchiveCreatesTemporaryFile(): void { - $mock_http_client = $this->createMock(ClientInterface::class); - $mock_archiver = $this->createMock(ArchiverInterface::class); - $mock_file_downloader = $this->createMockFileDownloader(); + $mock_http_client = $this->createStub(ClientInterface::class); + $mock_archiver = $this->createStub(ArchiverInterface::class); + $mock_file_downloader = $this->stubFileDownloader(); $destination = self::$tmp . '/destination'; File::mkdir($destination); File::dump($destination . '/composer.json', '{}'); @@ -84,9 +84,9 @@ public function testDownloadArchiveCreatesTemporaryFile(): void { } public function testDownloadArchiveHandlesHttpError(): void { - $mock_http_client = $this->createMock(ClientInterface::class); - $mock_archiver = $this->createMock(ArchiverInterface::class); - $mock_file_downloader = $this->createMock(Downloader::class); + $mock_http_client = $this->createStub(ClientInterface::class); + $mock_archiver = $this->createStub(ArchiverInterface::class); + $mock_file_downloader = $this->createStub(Downloader::class); $mock_file_downloader->method('download')->willThrowException(new \RuntimeException('HTTP 404 error')); $destination = self::$tmp . '/destination'; File::mkdir($destination); @@ -97,9 +97,9 @@ public function testDownloadArchiveHandlesHttpError(): void { } public function testDownloadArchiveHandlesRequestException(): void { - $mock_http_client = $this->createMock(ClientInterface::class); - $mock_archiver = $this->createMock(ArchiverInterface::class); - $mock_file_downloader = $this->createMock(Downloader::class); + $mock_http_client = $this->createStub(ClientInterface::class); + $mock_archiver = $this->createStub(ArchiverInterface::class); + $mock_file_downloader = $this->createStub(Downloader::class); $mock_file_downloader->method('download')->willThrowException(new \RuntimeException('Network error')); $destination = self::$tmp . '/destination'; File::mkdir($destination); @@ -111,15 +111,15 @@ public function testDownloadArchiveHandlesRequestException(): void { #[DataProvider('dataProviderDiscoverLatestReleaseRemote')] public function testDiscoverLatestReleaseRemote(string $repo, mixed $release_data, bool $throw_exception, bool $skip_mock_setup, ?string $expected_version, ?string $expected_exception, ?string $expected_message): void { - $mock_http_client = $this->createMock(ClientInterface::class); + $mock_http_client = $this->createStub(ClientInterface::class); if (!$skip_mock_setup) { if ($throw_exception) { - $mock_http_client->method('request')->willThrowException(new RequestException('API error', $this->createMock(RequestInterface::class))); + $mock_http_client->method('request')->willThrowException(new RequestException('API error', $this->createStub(RequestInterface::class))); } else { - $mock_response = $this->createMock(ResponseInterface::class); - $mock_body = $this->createMock(StreamInterface::class); + $mock_response = $this->createStub(ResponseInterface::class); + $mock_body = $this->createStub(StreamInterface::class); $mock_response->method('getBody')->willReturn($mock_body); $release_json = is_array($release_data) ? json_encode($release_data) : $release_data; @@ -131,8 +131,8 @@ public function testDiscoverLatestReleaseRemote(string $repo, mixed $release_dat } } - $mock_archiver = $this->createMock(ArchiverInterface::class); - $mock_file_downloader = $this->createMockFileDownloader(); + $mock_archiver = $this->createStub(ArchiverInterface::class); + $mock_file_downloader = $this->stubFileDownloader(); $destination = self::$tmp . '/destination_' . uniqid(); File::mkdir($destination); @@ -272,12 +272,12 @@ public static function dataProviderDiscoverLatestReleaseRemote(): \Iterator { } public function testDownloadFromRemoteWithGitSuffix(): void { - $mock_http_client = $this->createMock(ClientInterface::class); - $mock_response = $this->createMock(ResponseInterface::class); + $mock_http_client = $this->createStub(ClientInterface::class); + $mock_response = $this->createStub(ResponseInterface::class); $mock_response->method('getStatusCode')->willReturn(200); $mock_http_client->method('request')->willReturn($mock_response); - $mock_archiver = $this->createMock(ArchiverInterface::class); - $mock_file_downloader = $this->createMockFileDownloader(); + $mock_archiver = $this->createStub(ArchiverInterface::class); + $mock_file_downloader = $this->stubFileDownloader(); $destination = self::$tmp . '/destination'; File::mkdir($destination); File::dump($destination . '/composer.json', '{}'); @@ -293,18 +293,18 @@ public function testDownloadStableWithReleasePrefixSelectsMajor(): void { ['tag_name' => '1.39.0', 'draft' => FALSE], ]); - $mock_http_client = $this->createMock(ClientInterface::class); + $mock_http_client = $this->createStub(ClientInterface::class); $mock_http_client->method('request')->willReturnCallback(function (string $method, string $url) use ($release_json): ResponseInterface { - $response = $this->createMock(ResponseInterface::class); + $response = $this->createStub(ResponseInterface::class); $response->method('getStatusCode')->willReturn(200); - $body = $this->createMock(StreamInterface::class); + $body = $this->createStub(StreamInterface::class); $body->method('getContents')->willReturn(str_contains($url, '/releases') ? $release_json : 'ok'); $response->method('getBody')->willReturn($body); return $response; }); - $mock_archiver = $this->createMock(ArchiverInterface::class); - $mock_file_downloader = $this->createMockFileDownloader(); + $mock_archiver = $this->createStub(ArchiverInterface::class); + $mock_file_downloader = $this->stubFileDownloader(); $destination = self::$tmp . '/destination_' . uniqid(); File::mkdir($destination); File::dump($destination . '/composer.json', '{}'); @@ -319,18 +319,18 @@ public function testDownloadStableWithReleasePrefixFallsBackToBranch(): void { ['tag_name' => '1.40.0', 'draft' => FALSE], ]); - $mock_http_client = $this->createMock(ClientInterface::class); + $mock_http_client = $this->createStub(ClientInterface::class); $mock_http_client->method('request')->willReturnCallback(function (string $method, string $url) use ($release_json): ResponseInterface { - $response = $this->createMock(ResponseInterface::class); + $response = $this->createStub(ResponseInterface::class); $response->method('getStatusCode')->willReturn(200); - $body = $this->createMock(StreamInterface::class); + $body = $this->createStub(StreamInterface::class); $body->method('getContents')->willReturn(str_contains($url, '/releases') ? $release_json : 'ok'); $response->method('getBody')->willReturn($body); return $response; }); - $mock_archiver = $this->createMock(ArchiverInterface::class); - $mock_file_downloader = $this->createMockFileDownloader(); + $mock_archiver = $this->createStub(ArchiverInterface::class); + $mock_file_downloader = $this->stubFileDownloader(); $destination = self::$tmp . '/destination_' . uniqid(); File::mkdir($destination); File::dump($destination . '/composer.json', '{}'); @@ -426,8 +426,8 @@ public function testDiscoverLatestReleaseRemoteWithGithubToken(): void { ['tag_name' => 'v1.5.0', 'draft' => FALSE], ]); $mock_http_client = $this->createMock(ClientInterface::class); - $mock_response = $this->createMock(ResponseInterface::class); - $mock_body = $this->createMock(StreamInterface::class); + $mock_response = $this->createStub(ResponseInterface::class); + $mock_body = $this->createStub(StreamInterface::class); $mock_response->method('getBody')->willReturn($mock_body); $mock_body->method('getContents')->willReturn($release_json); $mock_response->method('getStatusCode')->willReturn(200); @@ -438,7 +438,7 @@ public function testDiscoverLatestReleaseRemoteWithGithubToken(): void { $this->assertEquals('Bearer test_token_12345', $options['headers']['Authorization']); return $mock_response; }); - $mock_archiver = $this->createMock(ArchiverInterface::class); + $mock_archiver = $this->createStub(ArchiverInterface::class); $mock_file_downloader = $this->createMock(Downloader::class); $mock_file_downloader->expects($this->once())->method('download')->willReturnCallback(function ($url, $dest, array $headers): void { $this->assertArrayHasKey('Authorization', $headers); @@ -454,8 +454,8 @@ public function testDiscoverLatestReleaseRemoteWithGithubToken(): void { public function testDownloadArchiveWithGithubToken(): void { static::envSet('GITHUB_TOKEN', 'test_token_67890'); - $mock_http_client = $this->createMock(ClientInterface::class); - $mock_archiver = $this->createMock(ArchiverInterface::class); + $mock_http_client = $this->createStub(ClientInterface::class); + $mock_archiver = $this->createStub(ArchiverInterface::class); $mock_file_downloader = $this->createMock(Downloader::class); $mock_file_downloader->expects($this->once())->method('download')->willReturnCallback(function ($url, $dest, array $headers): void { $this->assertArrayHasKey('Authorization', $headers); @@ -544,8 +544,8 @@ static function (self $test): array { * Stub a client answering every request with a single status code. */ protected function stubStatusClient(int $status_code): ClientInterface { - $client = $this->createMock(ClientInterface::class); - $response = $this->createMock(ResponseInterface::class); + $client = $this->createStub(ClientInterface::class); + $response = $this->createStub(ResponseInterface::class); $response->method('getStatusCode')->willReturn($status_code); $client->method('request')->willReturn($response); @@ -561,17 +561,17 @@ protected function stubStatusClient(int $status_code): ClientInterface { * Message for the thrown request exception when no status code is given. */ protected function stubRefClient(?int $status_code, ?string $exception_message = NULL): ClientInterface { - $client = $this->createMock(ClientInterface::class); - $repo_response = $this->createMock(ResponseInterface::class); + $client = $this->createStub(ClientInterface::class); + $repo_response = $this->createStub(ResponseInterface::class); $repo_response->method('getStatusCode')->willReturn(200); $ref_response = NULL; if ($status_code !== NULL) { - $ref_response = $this->createMock(ResponseInterface::class); + $ref_response = $this->createStub(ResponseInterface::class); $ref_response->method('getStatusCode')->willReturn($status_code); } - $request = $this->createMock(RequestInterface::class); + $request = $this->createStub(RequestInterface::class); $client->method('request')->willReturnCallback(function ($method, $url) use ($repo_response, $ref_response, $exception_message, $request): ResponseInterface { if (!str_contains($url, '/archive/')) { return $repo_response; @@ -591,16 +591,16 @@ protected function stubRefClient(?int $status_code, ?string $exception_message = * Stub a client that fails every request with a transport error. */ protected function stubThrowingClient(string $message): ClientInterface { - $client = $this->createMock(ClientInterface::class); - $client->method('request')->willThrowException(new RequestException($message, $this->createMock(RequestInterface::class))); + $client = $this->createStub(ClientInterface::class); + $client->method('request')->willThrowException(new RequestException($message, $this->createStub(RequestInterface::class))); return $client; } #[DataProvider('dataProviderValidateRemoteArtifact')] public function testValidateRemoteArtifact(string $ref): void { - $mock_http_client = $this->createMock(ClientInterface::class); - $mock_response = $this->createMock(ResponseInterface::class); + $mock_http_client = $this->createStub(ClientInterface::class); + $mock_response = $this->createStub(ResponseInterface::class); $mock_response->method('getStatusCode')->willReturn(200); $mock_http_client->method('request')->willReturn($mock_response); $downloader = new RepositoryDownloader($mock_http_client); @@ -631,10 +631,10 @@ public static function dataProviderValidateLocalArtifact(): \Iterator { yield 'custom ref' => ['main']; } - protected function createMockHttpClient(int $status_code = 200, string $body_content = 'mock content'): ClientInterface { - $mock_client = $this->createMock(ClientInterface::class); - $mock_response = $this->createMock(ResponseInterface::class); - $mock_body = $this->createMock(StreamInterface::class); + protected function stubHttpClient(int $status_code = 200, string $body_content = 'mock content'): ClientInterface { + $mock_client = $this->createStub(ClientInterface::class); + $mock_response = $this->createStub(ResponseInterface::class); + $mock_body = $this->createStub(StreamInterface::class); $mock_response->method('getBody')->willReturn($mock_body); $mock_body->method('getContents')->willReturn($body_content); $mock_response->method('getStatusCode')->willReturn($status_code); @@ -692,12 +692,8 @@ protected function createMockArchiverWithExtract(): MockObject { return $mock_archiver; } - /** - * @return \PHPUnit\Framework\MockObject\MockObject&\DrevOps\VortexInstaller\Downloader\Downloader - * Mock file downloader. - */ - protected function createMockFileDownloader(): MockObject { - return $this->createMock(Downloader::class); + protected function stubFileDownloader(): Downloader { + return $this->createStub(Downloader::class); } } diff --git a/.vortex/installer/tests/Unit/Prompts/InstallerPresenterTest.php b/.vortex/installer/tests/Unit/Prompts/InstallerPresenterTest.php index 6ca30c4d3a..9730c6dfb9 100644 --- a/.vortex/installer/tests/Unit/Prompts/InstallerPresenterTest.php +++ b/.vortex/installer/tests/Unit/Prompts/InstallerPresenterTest.php @@ -43,7 +43,7 @@ public function testSetPromptManager(): void { $config = $this->createConfig(); $presenter = new InstallerPresenter($config); - $mock_pm = $this->createMock(PromptManager::class); + $mock_pm = $this->createStub(PromptManager::class); $presenter->setPromptManager($mock_pm); // No exception means success - prompt manager was accepted. @@ -219,7 +219,7 @@ public function testFooterBuildSucceeded(): void { $presenter = new InstallerPresenter($config); $mock_pm = $this->createMock(PromptManager::class); - $mock_pm->method('runPostBuild') + $mock_pm->expects($this->once())->method('runPostBuild') ->with(InstallerPresenter::BUILD_RESULT_SUCCESS) ->willReturn(''); $presenter->setPromptManager($mock_pm); @@ -237,7 +237,7 @@ public function testFooterBuildSucceededWithHandlerOutput(): void { $presenter = new InstallerPresenter($config); $mock_pm = $this->createMock(PromptManager::class); - $mock_pm->method('runPostBuild') + $mock_pm->expects($this->once())->method('runPostBuild') ->with(InstallerPresenter::BUILD_RESULT_SUCCESS) ->willReturn('Setup GitHub Actions: ...'); $presenter->setPromptManager($mock_pm); @@ -255,7 +255,7 @@ public function testFooterBuildSkipped(string $starter, bool $expect_profile_com $mock_pm = $this->createMock(PromptManager::class); $mock_pm->method('getResponses')->willReturn([Starter::id() => $starter]); - $mock_pm->method('runPostBuild') + $mock_pm->expects($this->once())->method('runPostBuild') ->with(InstallerPresenter::BUILD_RESULT_SKIPPED) ->willReturn(''); $presenter->setPromptManager($mock_pm); @@ -303,7 +303,7 @@ public function testFooterBuildSkippedDefaultsToDemo(): void { $config = $this->createConfig(); $presenter = new InstallerPresenter($config); - $mock_pm = $this->createMock(PromptManager::class); + $mock_pm = $this->createStub(PromptManager::class); $mock_pm->method('getResponses')->willReturn([]); $mock_pm->method('runPostBuild')->willReturn(''); $presenter->setPromptManager($mock_pm); @@ -320,7 +320,7 @@ public function testFooterBuildFailed(): void { $presenter = new InstallerPresenter($config); $mock_pm = $this->createMock(PromptManager::class); - $mock_pm->method('runPostBuild') + $mock_pm->expects($this->once())->method('runPostBuild') ->with(InstallerPresenter::BUILD_RESULT_FAILED) ->willReturn(''); $presenter->setPromptManager($mock_pm); @@ -341,7 +341,7 @@ public function testFooterBuildFailedWithHandlerOutput(): void { $presenter = new InstallerPresenter($config); $mock_pm = $this->createMock(PromptManager::class); - $mock_pm->method('runPostBuild') + $mock_pm->expects($this->once())->method('runPostBuild') ->with(InstallerPresenter::BUILD_RESULT_FAILED) ->willReturn('Check hosting config'); $presenter->setPromptManager($mock_pm); diff --git a/.vortex/installer/tests/Unit/Runner/AbstractRunnerTest.php b/.vortex/installer/tests/Unit/Runner/AbstractRunnerTest.php index 9a685d3036..cfc0ad8be5 100644 --- a/.vortex/installer/tests/Unit/Runner/AbstractRunnerTest.php +++ b/.vortex/installer/tests/Unit/Runner/AbstractRunnerTest.php @@ -345,7 +345,7 @@ public function testInitLogger(): void { public function testResolveOutputWithNull(): void { $runner = new ConcreteRunner(); - $mock_output = $this->createMock(OutputInterface::class); + $mock_output = $this->createStub(OutputInterface::class); Tui::init($mock_output); $output = $runner->resolveOutputPublic(NULL); @@ -356,7 +356,7 @@ public function testResolveOutputWithNull(): void { public function testResolveOutputWithProvided(): void { $runner = new ConcreteRunner(); - $mock_output = $this->createMock(OutputInterface::class); + $mock_output = $this->createStub(OutputInterface::class); $output = $runner->resolveOutputPublic($mock_output); diff --git a/.vortex/installer/tests/Unit/Utils/FileManagerTest.php b/.vortex/installer/tests/Unit/Utils/FileManagerTest.php index a7a77b5af0..d3fd522d42 100644 --- a/.vortex/installer/tests/Unit/Utils/FileManagerTest.php +++ b/.vortex/installer/tests/Unit/Utils/FileManagerTest.php @@ -699,7 +699,7 @@ public function testPrepareDemo(array $config_values, ?string $dotenv, bool $wit $config->set($name, $value); } - $result = (new FileManager($config))->prepareDemo($this->createMock(Downloader::class)); + $result = (new FileManager($config))->prepareDemo($this->createStub(Downloader::class)); $messages = is_array($result) ? $result : [$result]; $this->assertStringContainsString($expected_message, implode(PHP_EOL, array_map(strval(...), $messages))); diff --git a/.vortex/installer/tests/Unit/Utils/OptionsResolverTest.php b/.vortex/installer/tests/Unit/Utils/OptionsResolverTest.php index 7d0cdfb87f..a96c210472 100644 --- a/.vortex/installer/tests/Unit/Utils/OptionsResolverTest.php +++ b/.vortex/installer/tests/Unit/Utils/OptionsResolverTest.php @@ -26,7 +26,7 @@ protected function setUp(): void { } public function testCheckRequirementsPassesWhenAllPresent(): void { - $finder = $this->createMock(ExecutableFinder::class); + $finder = $this->createStub(ExecutableFinder::class); $finder->method('find')->willReturn('/usr/bin/mock'); OptionsResolver::checkRequirements($finder); @@ -36,7 +36,7 @@ public function testCheckRequirementsPassesWhenAllPresent(): void { #[DataProvider('dataProviderCheckRequirementsThrowsOnMissing')] public function testCheckRequirementsThrowsOnMissing(string $missing_command): void { - $finder = $this->createMock(ExecutableFinder::class); + $finder = $this->createStub(ExecutableFinder::class); $finder->method('find') ->willReturnCallback(fn(string $name): ?string => $name === $missing_command ? NULL : '/usr/bin/' . $name); @@ -53,7 +53,7 @@ public static function dataProviderCheckRequirementsThrowsOnMissing(): \Iterator } public function testCheckRequirementsStopsAtFirstMissing(): void { - $finder = $this->createMock(ExecutableFinder::class); + $finder = $this->createStub(ExecutableFinder::class); $finder->method('find')->willReturn(NULL); $this->expectException(\RuntimeException::class);