Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .vortex/installer/phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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">
<testsuites>
<testsuite name="default">
<directory>tests/Unit</directory>
Expand Down
13 changes: 6 additions & 7 deletions .vortex/installer/tests/Functional/Command/BuildCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
});
Expand Down Expand Up @@ -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);

Expand All @@ -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));
Expand All @@ -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;
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
});
Expand Down
19 changes: 9 additions & 10 deletions .vortex/installer/tests/Functional/Command/InstallCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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;
});
Expand All @@ -68,18 +67,18 @@ 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);
// Mock ExecutableFinder for BuildCommand's ProcessRunner.
$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;
});
Expand All @@ -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);
}
Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions .vortex/installer/tests/Unit/Downloader/DownloaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand All @@ -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';

Expand All @@ -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())
Expand All @@ -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 = [
Expand Down
Loading
Loading