Skip to content

Commit 94d8078

Browse files
Backfill tests for blueprint:erase (#320)
1 parent a2cde81 commit 94d8078

File tree

5 files changed

+93
-11
lines changed

5 files changed

+93
-11
lines changed

src/Commands/BuildCommand.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Blueprint\Blueprint;
66
use Blueprint\Builder;
77
use Illuminate\Console\Command;
8-
use Illuminate\Contracts\Filesystem\FileNotFoundException;
98
use Illuminate\Filesystem\Filesystem;
109
use Illuminate\Support\Str;
1110
use Symfony\Component\Console\Input\InputArgument;

src/Commands/EraseCommand.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
use Blueprint\Blueprint;
66
use Illuminate\Console\Command;
77
use Illuminate\Filesystem\Filesystem;
8-
use Symfony\Component\Console\Input\InputArgument;
8+
use Illuminate\Support\Facades\Artisan;
99

1010
class EraseCommand extends Command
1111
{
@@ -46,7 +46,8 @@ public function handle()
4646
{
4747
$contents = $this->files->get('.blueprint');
4848

49-
$blueprint = new Blueprint();
49+
$blueprint = resolve(Blueprint::class);
50+
5051
$generated = $blueprint->parse($contents, false);
5152

5253
collect($generated)->each(function ($files, $action) {
@@ -60,7 +61,7 @@ public function handle()
6061
}
6162

6263
collect($files)->each(function ($file) {
63-
$this->line('- ' . $file);
64+
$this->line('- '.$file);
6465
});
6566

6667
$this->line('');

tests/Feature/Commands/BuildCommandTest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
88
use Tests\TestCase;
99

10+
/**
11+
* @covers \Blueprint\Commands\BuildCommand
12+
*/
1013
class BuildCommandTest extends TestCase
1114
{
1215
use MockeryPHPUnitIntegration;
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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+
}

tests/Feature/Commands/NewCommandTest.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@
66
use Tests\TestCase;
77

88
/**
9-
* @covers \Blueprint\Commands\NewCommand;
9+
* @covers \Blueprint\Commands\NewCommand
1010
*/
1111
class NewCommandTest extends TestCase
1212
{
1313
use MockeryPHPUnitIntegration;
1414

15-
/**
16-
* @test
17-
*/
15+
/** @test */
1816
public function it_creates_a_draft_file_from_stub_if_none_exists()
1917
{
2018
$filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial();
@@ -33,9 +31,7 @@ public function it_creates_a_draft_file_from_stub_if_none_exists()
3331
->assertExitCode(0);
3432
}
3533

36-
/**
37-
* @test
38-
*/
34+
/** @test */
3935
public function it_does_not_create_a_draft_file_if_one_exists_already()
4036
{
4137
$filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial();

0 commit comments

Comments
 (0)