|
| 1 | +<?php |
| 2 | + |
| 3 | +namespace Tests\Feature\Commands; |
| 4 | + |
| 5 | +use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; |
| 6 | +use Tests\TestCase; |
| 7 | + |
| 8 | +/** |
| 9 | + * @covers \Blueprint\Commands\EraseCommand |
| 10 | + */ |
| 11 | +class EraseCommandTest extends TestCase |
| 12 | +{ |
| 13 | + use MockeryPHPUnitIntegration; |
| 14 | + |
| 15 | + /** @test */ |
| 16 | + public function it_parses_and_update_the_trace_file() |
| 17 | + { |
| 18 | + $filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial(); |
| 19 | + $this->swap('files', $filesystem); |
| 20 | + |
| 21 | + $filesystem->expects('get') |
| 22 | + ->with('.blueprint') |
| 23 | + ->andReturn("created: created_file.php \nupdated: updated_file.php \nother: test.php"); |
| 24 | + |
| 25 | + $filesystem->expects('put') |
| 26 | + ->with('.blueprint', "other: test.php\n"); |
| 27 | + |
| 28 | + $this->artisan('blueprint:erase') |
| 29 | + ->assertExitCode(0); |
| 30 | + } |
| 31 | + |
| 32 | + /** @test */ |
| 33 | + public function it_deletes_the_created_files() |
| 34 | + { |
| 35 | + $filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial(); |
| 36 | + $this->swap('files', $filesystem); |
| 37 | + |
| 38 | + $filesystem->expects('get') |
| 39 | + ->with('.blueprint') |
| 40 | + ->andReturn("created:\n - created_file1.php\n - created_file2.php"); |
| 41 | + |
| 42 | + $filesystem->expects('delete')->with([ |
| 43 | + "created_file1.php", |
| 44 | + "created_file2.php", |
| 45 | + ]); |
| 46 | + |
| 47 | + $this->artisan('blueprint:erase') |
| 48 | + ->assertExitCode(0) |
| 49 | + ->expectsOutput("Deleted:") |
| 50 | + ->expectsOutput("- created_file1.php") |
| 51 | + ->expectsOutput("- created_file2.php"); |
| 52 | + } |
| 53 | + |
| 54 | + /** @test */ |
| 55 | + public function it_notify_about_the_updated_files() |
| 56 | + { |
| 57 | + $filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial(); |
| 58 | + $this->swap('files', $filesystem); |
| 59 | + |
| 60 | + $filesystem->expects('get') |
| 61 | + ->with('.blueprint') |
| 62 | + ->andReturn("updated:\n - updated_file1.php\n - updated_file2.php"); |
| 63 | + |
| 64 | + $this->artisan('blueprint:erase') |
| 65 | + ->assertExitCode(0) |
| 66 | + ->expectsOutput("The updates to the following files can not be erased automatically.") |
| 67 | + ->expectsOutput("- updated_file1.php") |
| 68 | + ->expectsOutput("- updated_file2.php"); |
| 69 | + } |
| 70 | + |
| 71 | + /** @test */ |
| 72 | + public function it_calls_the_trace_command() |
| 73 | + { |
| 74 | + $filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial(); |
| 75 | + $this->swap('files', $filesystem); |
| 76 | + |
| 77 | + $filesystem->expects('get')->with('.blueprint')->andReturn("other: test.php"); |
| 78 | + $filesystem->expects('put')->with('.blueprint', "other: test.php\n"); |
| 79 | + |
| 80 | + $this->artisan('blueprint:erase') |
| 81 | + ->assertExitCode(0); |
| 82 | + } |
| 83 | +} |
0 commit comments