|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Feature\Commands; |
| 4 | + |
| 5 | +use Blueprint\Blueprint; |
| 6 | +use Blueprint\Builder; |
| 7 | +use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; |
| 8 | +use Tests\TestCase; |
| 9 | + |
| 10 | +class BuildCommandTest extends TestCase |
| 11 | +{ |
| 12 | + use MockeryPHPUnitIntegration; |
| 13 | + |
| 14 | + /** @test */ |
| 15 | + public function it_uses_the_default_draft_file() |
| 16 | + { |
| 17 | + $filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial(); |
| 18 | + $this->swap('files', $filesystem); |
| 19 | + |
| 20 | + $filesystem->shouldReceive('exists') |
| 21 | + ->with('draft.yaml') |
| 22 | + ->andReturnTrue(); |
| 23 | + |
| 24 | + $builder = $this->mock(Builder::class); |
| 25 | + |
| 26 | + $builder->shouldReceive('execute') |
| 27 | + ->with(resolve(Blueprint::class), $filesystem, 'draft.yaml', '', '') |
| 28 | + ->andReturn(collect([])); |
| 29 | + |
| 30 | + $this->artisan('blueprint:build') |
| 31 | + ->assertExitCode(0); |
| 32 | + } |
| 33 | + |
| 34 | + /** @test */ |
| 35 | + public function it_passes_the_command_args_to_the_builder_in_right_order() |
| 36 | + { |
| 37 | + $filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial(); |
| 38 | + $this->swap('files', $filesystem); |
| 39 | + |
| 40 | + $filesystem->shouldReceive('exists') |
| 41 | + ->with('test.yml') |
| 42 | + ->andReturnTrue(); |
| 43 | + |
| 44 | + $builder = $this->mock(Builder::class); |
| 45 | + |
| 46 | + $builder->shouldReceive('execute') |
| 47 | + ->with(resolve(Blueprint::class), $filesystem, 'test.yml', 'a,b,c', 'x,y,z') |
| 48 | + ->andReturn(collect([])); |
| 49 | + |
| 50 | + $this->artisan('blueprint:build test.yml --only=a,b,c --skip=x,y,z') |
| 51 | + ->assertExitCode(0); |
| 52 | + } |
| 53 | + |
| 54 | + /** @test */ |
| 55 | + public function it_fails_if_the_draft_file_not_exists() |
| 56 | + { |
| 57 | + $filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial(); |
| 58 | + $this->swap('files', $filesystem); |
| 59 | + |
| 60 | + $filesystem->shouldReceive('exists') |
| 61 | + ->with('test.yml') |
| 62 | + ->andReturnFalse(); |
| 63 | + |
| 64 | + $builder = $this->mock(Builder::class); |
| 65 | + |
| 66 | + $builder->shouldNotReceive('execute'); |
| 67 | + |
| 68 | + $this->artisan('blueprint:build test.yml --only=a,b,c --skip=x,y,z') |
| 69 | + ->assertExitCode(1); |
| 70 | + } |
| 71 | + |
| 72 | + /** @test */ |
| 73 | + public function it_shows_the_generated_files_groupbed_by_actions() |
| 74 | + { |
| 75 | + $filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial(); |
| 76 | + $this->swap('files', $filesystem); |
| 77 | + |
| 78 | + $filesystem->shouldReceive('exists') |
| 79 | + ->with('draft.yaml') |
| 80 | + ->andReturnTrue(); |
| 81 | + |
| 82 | + $builder = $this->mock(Builder::class); |
| 83 | + |
| 84 | + $builder->shouldReceive('execute') |
| 85 | + ->with(resolve(Blueprint::class), $filesystem, 'draft.yaml', '', '') |
| 86 | + ->andReturn(collect([ |
| 87 | + "created" => [ |
| 88 | + "file1", |
| 89 | + "file2", |
| 90 | + ] |
| 91 | + ])); |
| 92 | + |
| 93 | + $this->artisan('blueprint:build') |
| 94 | + ->assertExitCode(0) |
| 95 | + ->expectsOutput('Created:') |
| 96 | + ->expectsOutput('- file1') |
| 97 | + ->expectsOutput('- file2'); |
| 98 | + } |
| 99 | +} |
0 commit comments