From 94d807830edb356472382bf8c7da7caf01171c03 Mon Sep 17 00:00:00 2001 From: Jason McCreary Date: Thu, 13 Aug 2020 11:48:22 -0400 Subject: [PATCH] Backfill tests for blueprint:erase (#320) --- src/Commands/BuildCommand.php | 1 - src/Commands/EraseCommand.php | 7 +- tests/Feature/Commands/BuildCommandTest.php | 3 + tests/Feature/Commands/EraseCommandTest.php | 83 +++++++++++++++++++++ tests/Feature/Commands/NewCommandTest.php | 10 +-- 5 files changed, 93 insertions(+), 11 deletions(-) create mode 100644 tests/Feature/Commands/EraseCommandTest.php diff --git a/src/Commands/BuildCommand.php b/src/Commands/BuildCommand.php index 56a23f77..4a8eca33 100644 --- a/src/Commands/BuildCommand.php +++ b/src/Commands/BuildCommand.php @@ -5,7 +5,6 @@ use Blueprint\Blueprint; use Blueprint\Builder; use Illuminate\Console\Command; -use Illuminate\Contracts\Filesystem\FileNotFoundException; use Illuminate\Filesystem\Filesystem; use Illuminate\Support\Str; use Symfony\Component\Console\Input\InputArgument; diff --git a/src/Commands/EraseCommand.php b/src/Commands/EraseCommand.php index 42a9a648..8b314bec 100644 --- a/src/Commands/EraseCommand.php +++ b/src/Commands/EraseCommand.php @@ -5,7 +5,7 @@ use Blueprint\Blueprint; use Illuminate\Console\Command; use Illuminate\Filesystem\Filesystem; -use Symfony\Component\Console\Input\InputArgument; +use Illuminate\Support\Facades\Artisan; class EraseCommand extends Command { @@ -46,7 +46,8 @@ public function handle() { $contents = $this->files->get('.blueprint'); - $blueprint = new Blueprint(); + $blueprint = resolve(Blueprint::class); + $generated = $blueprint->parse($contents, false); collect($generated)->each(function ($files, $action) { @@ -60,7 +61,7 @@ public function handle() } collect($files)->each(function ($file) { - $this->line('- ' . $file); + $this->line('- '.$file); }); $this->line(''); diff --git a/tests/Feature/Commands/BuildCommandTest.php b/tests/Feature/Commands/BuildCommandTest.php index 4e88cff1..af670300 100644 --- a/tests/Feature/Commands/BuildCommandTest.php +++ b/tests/Feature/Commands/BuildCommandTest.php @@ -7,6 +7,9 @@ use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration; use Tests\TestCase; +/** + * @covers \Blueprint\Commands\BuildCommand + */ class BuildCommandTest extends TestCase { use MockeryPHPUnitIntegration; diff --git a/tests/Feature/Commands/EraseCommandTest.php b/tests/Feature/Commands/EraseCommandTest.php new file mode 100644 index 00000000..4ca07a39 --- /dev/null +++ b/tests/Feature/Commands/EraseCommandTest.php @@ -0,0 +1,83 @@ +makePartial(); + $this->swap('files', $filesystem); + + $filesystem->expects('get') + ->with('.blueprint') + ->andReturn("created: created_file.php \nupdated: updated_file.php \nother: test.php"); + + $filesystem->expects('put') + ->with('.blueprint', "other: test.php\n"); + + $this->artisan('blueprint:erase') + ->assertExitCode(0); + } + + /** @test */ + public function it_deletes_the_created_files() + { + $filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial(); + $this->swap('files', $filesystem); + + $filesystem->expects('get') + ->with('.blueprint') + ->andReturn("created:\n - created_file1.php\n - created_file2.php"); + + $filesystem->expects('delete')->with([ + "created_file1.php", + "created_file2.php", + ]); + + $this->artisan('blueprint:erase') + ->assertExitCode(0) + ->expectsOutput("Deleted:") + ->expectsOutput("- created_file1.php") + ->expectsOutput("- created_file2.php"); + } + + /** @test */ + public function it_notify_about_the_updated_files() + { + $filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial(); + $this->swap('files', $filesystem); + + $filesystem->expects('get') + ->with('.blueprint') + ->andReturn("updated:\n - updated_file1.php\n - updated_file2.php"); + + $this->artisan('blueprint:erase') + ->assertExitCode(0) + ->expectsOutput("The updates to the following files can not be erased automatically.") + ->expectsOutput("- updated_file1.php") + ->expectsOutput("- updated_file2.php"); + } + + /** @test */ + public function it_calls_the_trace_command() + { + $filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial(); + $this->swap('files', $filesystem); + + $filesystem->expects('get')->with('.blueprint')->andReturn("other: test.php"); + $filesystem->expects('put')->with('.blueprint', "other: test.php\n"); + + $this->artisan('blueprint:erase') + ->assertExitCode(0); + } +} diff --git a/tests/Feature/Commands/NewCommandTest.php b/tests/Feature/Commands/NewCommandTest.php index 89105880..899ebe4e 100644 --- a/tests/Feature/Commands/NewCommandTest.php +++ b/tests/Feature/Commands/NewCommandTest.php @@ -6,15 +6,13 @@ use Tests\TestCase; /** - * @covers \Blueprint\Commands\NewCommand; + * @covers \Blueprint\Commands\NewCommand */ class NewCommandTest extends TestCase { use MockeryPHPUnitIntegration; - /** - * @test - */ + /** @test */ public function it_creates_a_draft_file_from_stub_if_none_exists() { $filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial(); @@ -33,9 +31,7 @@ public function it_creates_a_draft_file_from_stub_if_none_exists() ->assertExitCode(0); } - /** - * @test - */ + /** @test */ public function it_does_not_create_a_draft_file_if_one_exists_already() { $filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial();