|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace BlameButton\LaravelDockerBuilder\Tests\Feature\Commands; |
| 4 | + |
| 5 | +use BlameButton\LaravelDockerBuilder\Commands\GenerateQuestions\Choices\CiPlatform; |
| 6 | +use BlameButton\LaravelDockerBuilder\Detectors\CiPlatformDetector; |
| 7 | +use BlameButton\LaravelDockerBuilder\Tests\TestCase; |
| 8 | +use Illuminate\Support\Facades\File; |
| 9 | +use Mockery\MockInterface; |
| 10 | +use Symfony\Component\Console\Command\Command; |
| 11 | + |
| 12 | +/** |
| 13 | + * @uses \BlameButton\LaravelDockerBuilder\Commands\DockerGenerateCommand::getOptions() |
| 14 | + * @uses \BlameButton\LaravelDockerBuilder\Commands\GenerateQuestions\Choices\CiPlatform::name() |
| 15 | + * @uses \BlameButton\LaravelDockerBuilder\Commands\GenerateQuestions\Choices\CiPlatform::values() |
| 16 | + * @uses \BlameButton\LaravelDockerBuilder\Commands\GenerateQuestions\Choices\NodeBuildTool::values() |
| 17 | + * @uses \BlameButton\LaravelDockerBuilder\Commands\GenerateQuestions\Choices\NodePackageManager::values() |
| 18 | + * @uses \BlameButton\LaravelDockerBuilder\Commands\GenerateQuestions\Choices\PhpExtensions::values() |
| 19 | + * @uses \BlameButton\LaravelDockerBuilder\Commands\GenerateQuestions\Choices\PhpVersion::values() |
| 20 | + * @uses \BlameButton\LaravelDockerBuilder\DockerServiceProvider |
| 21 | + * @uses \BlameButton\LaravelDockerBuilder\Integrations\SupportedPhpExtensions |
| 22 | + * |
| 23 | + * @covers \BlameButton\LaravelDockerBuilder\Commands\DockerCiCommand |
| 24 | + */ |
| 25 | +class DockerCiCommandTest extends TestCase |
| 26 | +{ |
| 27 | + protected function setUp(): void |
| 28 | + { |
| 29 | + parent::setUp(); |
| 30 | + |
| 31 | + File::delete(base_path('.gitlab-ci.yml')); |
| 32 | + File::deleteDirectory(base_path('.github/')); |
| 33 | + } |
| 34 | + |
| 35 | + protected function tearDown(): void |
| 36 | + { |
| 37 | + File::delete(base_path('.gitlab-ci.yml')); |
| 38 | + File::deleteDirectory(base_path('.github/')); |
| 39 | + |
| 40 | + parent::tearDown(); |
| 41 | + } |
| 42 | + |
| 43 | + public function testItChecksIfGitlabFileExists(): void |
| 44 | + { |
| 45 | + touch(base_path('.gitlab-ci.yml')); |
| 46 | + |
| 47 | + $this->artisan('docker:ci gitlab') |
| 48 | + ->expectsOutput('Using [GitLab CI/CD], but [.gitlab-ci.yml] file already exists.') |
| 49 | + ->assertSuccessful(); |
| 50 | + } |
| 51 | + |
| 52 | + public function testItChecksIfGithubFileExists(): void |
| 53 | + { |
| 54 | + File::ensureDirectoryExists(base_path('.github/workflows')); |
| 55 | + touch(base_path('.github/workflows/ci.yml')); |
| 56 | + |
| 57 | + $this->artisan('docker:ci github') |
| 58 | + ->expectsOutput('Using [GitHub Actions], but [.github/workflows/ci.yml] file already exists.') |
| 59 | + ->assertSuccessful(); |
| 60 | + } |
| 61 | + |
| 62 | + public function testItUsesCiPlatformDetector(): void |
| 63 | + { |
| 64 | + $this->mock(CiPlatformDetector::class, function (MockInterface $mock) { |
| 65 | + $mock->expects('detect') |
| 66 | + ->once() |
| 67 | + ->withNoArgs() |
| 68 | + ->andReturn(CiPlatform::GITLAB_CI); |
| 69 | + }); |
| 70 | + |
| 71 | + $this->artisan('docker:ci') |
| 72 | + ->expectsOutput(sprintf('Using [GitLab CI/CD], copying [.gitlab-ci.yml] to [%s].', base_path())) |
| 73 | + ->assertSuccessful(); |
| 74 | + |
| 75 | + $this->assertFileExists(base_path('.gitlab-ci.yml')); |
| 76 | + } |
| 77 | + |
| 78 | + public function testItTellsUserToManuallyPassAPlatform(): void |
| 79 | + { |
| 80 | + $this->mock(CiPlatformDetector::class, function (MockInterface $mock) { |
| 81 | + $mock->expects('detect') |
| 82 | + ->once() |
| 83 | + ->withNoArgs() |
| 84 | + ->andReturn(false); |
| 85 | + }); |
| 86 | + |
| 87 | + $this->artisan('docker:ci') |
| 88 | + ->expectsOutput('Unfortunately, no CI platform could be detected.') |
| 89 | + ->expectsOutput('Please use the [ci-platform] argument to manually define a supported platform.') |
| 90 | + ->assertFailed(); |
| 91 | + } |
| 92 | + |
| 93 | + public function testItThrowsErrorWhenDetectorReturnsInvalid(): void |
| 94 | + { |
| 95 | + $this->mock(CiPlatformDetector::class, function (MockInterface $mock) { |
| 96 | + $mock->expects('detect') |
| 97 | + ->once() |
| 98 | + ->withNoArgs() |
| 99 | + ->andReturn('nonsense'); |
| 100 | + }); |
| 101 | + |
| 102 | + $this->artisan('docker:ci') |
| 103 | + ->expectsOutput('Invalid platform passed to BlameButton\LaravelDockerBuilder\Commands\DockerCiCommand::copy this should never happen.') |
| 104 | + ->assertExitCode(Command::INVALID); |
| 105 | + } |
| 106 | + |
| 107 | + public function testItErrorsOnInvalidArgument(): void |
| 108 | + { |
| 109 | + $this->artisan('docker:ci nonsense') |
| 110 | + ->expectsOutput('Invalid value [nonsense] for argument [ci-platform].') |
| 111 | + ->assertFailed(); |
| 112 | + } |
| 113 | +} |
0 commit comments