|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace BlameButton\LaravelDockerBuilder\Tests\Commands; |
| 4 | + |
| 5 | +use BlameButton\LaravelDockerBuilder\Commands\BaseDockerCommand; |
| 6 | +use BlameButton\LaravelDockerBuilder\Tests\TestCase; |
| 7 | +use Mockery\MockInterface; |
| 8 | +use Symfony\Component\Process\Process; |
| 9 | + |
| 10 | +/** |
| 11 | + * @uses \BlameButton\LaravelDockerBuilder\DockerServiceProvider |
| 12 | + * |
| 13 | + * @covers \BlameButton\LaravelDockerBuilder\Commands\BaseDockerCommand |
| 14 | + */ |
| 15 | +class BaseDockerCommandTest extends TestCase |
| 16 | +{ |
| 17 | + public function testItUsesConfigurationValues(): void |
| 18 | + { |
| 19 | + $this->mock('config', function (MockInterface $mock) { |
| 20 | + $mock->shouldReceive('get') |
| 21 | + ->once() |
| 22 | + ->with('docker-builder.tags.nginx') |
| 23 | + ->andReturn('test:nginx'); |
| 24 | + $mock->shouldReceive('get') |
| 25 | + ->once() |
| 26 | + ->with('docker-builder.tags.php') |
| 27 | + ->andReturn('test:php'); |
| 28 | + }); |
| 29 | + |
| 30 | + $class = $this->newBaseDockerCommand(); |
| 31 | + $environment = $class->getEnvironment(); |
| 32 | + |
| 33 | + self::assertEquals([ |
| 34 | + 'DOCKER_NGINX_TAG' => 'test:nginx', |
| 35 | + 'DOCKER_PHP_TAG' => 'test:php', |
| 36 | + ], $environment); |
| 37 | + } |
| 38 | + |
| 39 | + public function testItRunsProcess(): void |
| 40 | + { |
| 41 | + $mock = $this->createMock(Process::class); |
| 42 | + $mock->expects($this->once()) |
| 43 | + ->method('run') |
| 44 | + ->willReturnCallback(function ($callable) { |
| 45 | + $callable(Process::OUT, "stdout output\n"); |
| 46 | + $callable(Process::ERR, "stderr output\n"); |
| 47 | + |
| 48 | + return 0; |
| 49 | + }); |
| 50 | + |
| 51 | + $class = $this->newBaseDockerCommand(); |
| 52 | + $output = $class->runProcess( |
| 53 | + process: $mock, |
| 54 | + out: fopen('php://memory', 'r+'), |
| 55 | + err: fopen('php://memory', 'r+'), |
| 56 | + ); |
| 57 | + |
| 58 | + self::assertEquals(0, $output); |
| 59 | + } |
| 60 | + |
| 61 | + private function newBaseDockerCommand(): BaseDockerCommand |
| 62 | + { |
| 63 | + return new class extends BaseDockerCommand |
| 64 | + { |
| 65 | + }; |
| 66 | + } |
| 67 | +} |
0 commit comments