Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 9 additions & 23 deletions tests/Feature/Commands/BuildCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,28 +6,26 @@
use Blueprint\Builder;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Tests\TestCase;
use Tests\Traits\MocksFilesystem;

/**
* @covers \Blueprint\Commands\BuildCommand
*/
class BuildCommandTest extends TestCase
{
use MockeryPHPUnitIntegration;
use MockeryPHPUnitIntegration, MocksFilesystem;

/** @test */
public function it_uses_the_default_draft_file()
{
$filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial();
$this->swap('files', $filesystem);

$filesystem->shouldReceive('exists')
$this->files->shouldReceive('exists')
->with('draft.yaml')
->andReturnTrue();

$builder = $this->mock(Builder::class);

$builder->shouldReceive('execute')
->with(resolve(Blueprint::class), $filesystem, 'draft.yaml', '', '', false)
->with(resolve(Blueprint::class), $this->files, 'draft.yaml', '', '', false)
->andReturn(collect([]));

$this->artisan('blueprint:build')
Expand All @@ -37,17 +35,14 @@ public function it_uses_the_default_draft_file()
/** @test */
public function it_passes_the_command_args_to_the_builder_in_right_order()
{
$filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial();
$this->swap('files', $filesystem);

$filesystem->shouldReceive('exists')
$this->files->shouldReceive('exists')
->with('test.yml')
->andReturnTrue();

$builder = $this->mock(Builder::class);

$builder->shouldReceive('execute')
->with(resolve(Blueprint::class), $filesystem, 'test.yml', 'a,b,c', 'x,y,z', false)
->with(resolve(Blueprint::class), $this->files, 'test.yml', 'a,b,c', 'x,y,z', false)
->andReturn(collect([]));

$this->artisan('blueprint:build test.yml --only=a,b,c --skip=x,y,z')
Expand All @@ -57,10 +52,7 @@ public function it_passes_the_command_args_to_the_builder_in_right_order()
/** @test */
public function it_fails_if_the_draft_file_not_exists()
{
$filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial();
$this->swap('files', $filesystem);

$filesystem->shouldReceive('exists')
$this->files->shouldReceive('exists')
->with('test.yml')
->andReturnFalse();

Expand All @@ -75,24 +67,18 @@ public function it_fails_if_the_draft_file_not_exists()
/** @test */
public function it_shows_the_generated_files_groupbed_by_actions()
{
$filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial();
$this->swap('files', $filesystem);

$filesystem->shouldReceive('exists')
$this->files->shouldReceive('exists')
->with('draft.yaml')
->andReturnTrue();

$builder = $this->mock(Builder::class);

$builder->shouldReceive('execute')
->with(resolve(Blueprint::class), $filesystem, 'draft.yaml', '', '', false)
->with(resolve(Blueprint::class), $this->files, 'draft.yaml', '', '', false)
->andReturn(collect([
"created" => [
"file1",
"file2",
]
]));

$this->artisan('blueprint:build')
->assertExitCode(0)
->expectsOutput('Created:')
Expand Down
41 changes: 20 additions & 21 deletions tests/Feature/Commands/EraseCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,46 +6,48 @@
use Blueprint\Tracer;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Tests\TestCase;
use Tests\Traits\MocksFilesystem;

/**
* @covers \Blueprint\Commands\EraseCommand
*/
class EraseCommandTest extends TestCase
{
use MockeryPHPUnitIntegration;
use MockeryPHPUnitIntegration, MocksFilesystem;

/** @test */
public function it_parses_and_update_the_trace_file()
{
$filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial();
$this->swap('files', $filesystem);

$filesystem->expects('get')
$this->files->expects('get')
->with('.blueprint')
->andReturn("created: created_file.php \nupdated: updated_file.php \nother: test.php");

$filesystem->expects('put')
$this->files->expects('delete')->with("created_file.php");

$this->files->expects('put')
->with('.blueprint', "other: test.php\n");

$this->files->expects('exists')->with('app');

$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')
$this->files->expects('get')
->with('.blueprint')
->andReturn("created:\n - created_file1.php\n - created_file2.php");

$filesystem->expects('delete')->with([
$this->files->expects('delete')->with([
"created_file1.php",
"created_file2.php",
]);

$this->files->expects('put')->with('.blueprint', '{ }');
$this->files->expects('exists')->with('app');

$this->artisan('blueprint:erase')
->assertExitCode(0)
->expectsOutput("Deleted:")
Expand All @@ -56,13 +58,13 @@ public function it_deletes_the_created_files()
/** @test */
public function it_notify_about_the_updated_files()
{
$filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial();
$this->swap('files', $filesystem);

$filesystem->expects('get')
$this->files->expects('get')
->with('.blueprint')
->andReturn("updated:\n - updated_file1.php\n - updated_file2.php");

$this->files->expects('put')->with('.blueprint', '{ }');
$this->files->expects('exists')->with('app');

$this->artisan('blueprint:erase')
->assertExitCode(0)
->expectsOutput("The updates to the following files can not be erased automatically.")
Expand All @@ -73,18 +75,15 @@ public function it_notify_about_the_updated_files()
/** @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->files->expects('get')->with('.blueprint')->andReturn("other: test.php");
$this->files->expects('put')->with('.blueprint', "other: test.php\n");

$tracer = $this->spy(Tracer::class);

$this->artisan('blueprint:erase')
->assertExitCode(0);

$tracer->shouldHaveReceived('execute')
->with(resolve(Blueprint::class), $filesystem);
->with(resolve(Blueprint::class), $this->files);
}
}
27 changes: 14 additions & 13 deletions tests/Feature/Commands/NewCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,43 +4,44 @@

use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Tests\TestCase;
use Tests\Traits\MocksFilesystem;

/**
* @covers \Blueprint\Commands\NewCommand
*/
class NewCommandTest extends TestCase
{
use MockeryPHPUnitIntegration;
use MockeryPHPUnitIntegration, MocksFilesystem;

/** @test */
/**
* @test
*/
public function it_creates_a_draft_file_from_stub_if_none_exists()
{
$filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial();
$this->swap('files', $filesystem);

$filesystem->shouldReceive('exists')
$this->files->shouldReceive('exists')
->with('draft.yaml')
->andReturnFalse();
$filesystem->shouldReceive('stub')
$this->files->shouldReceive('stub')
->with('draft.stub')
->andReturn('stub');
$filesystem->shouldReceive('put')
$this->files->shouldReceive('put')
->with('draft.yaml', 'stub');

$this->files->shouldReceive('exists')->with('app');

$this->artisan('blueprint:new')
->assertExitCode(0);
}

/** @test */
public function it_does_not_create_a_draft_file_if_one_exists_already()
{
$filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial();
$this->swap('files', $filesystem);

$filesystem->shouldReceive('exists')
$this->files->shouldReceive('exists')
->with('draft.yaml')
->andReturnTrue();
$filesystem->shouldNotReceive('put');
$this->files->shouldNotReceive('put');
$this->files->shouldReceive('exists')
->with('app');

$this->artisan('blueprint:new')
->assertExitCode(0);
Expand Down
13 changes: 4 additions & 9 deletions tests/Feature/Commands/TraceCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,24 +8,22 @@
use Blueprint\Tracer;
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Tests\TestCase;
use Tests\Traits\MocksFilesystem;

/**
* @covers \Blueprint\Commands\TraceCommand
*/
class TraceCommandTest extends TestCase
{
use MockeryPHPUnitIntegration;
use MockeryPHPUnitIntegration, MocksFilesystem;

/** @test */
public function it_shows_error_if_no_model_found()
{
$filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial();
$this->swap('files', $filesystem);

$tracer = $this->mock(Tracer::class);

$tracer->shouldReceive('execute')
->with(resolve(Blueprint::class), $filesystem)
->with(resolve(Blueprint::class), $this->files)
->andReturn([]);

$this->artisan('blueprint:trace')
Expand All @@ -36,13 +34,10 @@ public function it_shows_error_if_no_model_found()
/** @test */
public function it_shows_the_number_of_traced_models()
{
$filesystem = \Mockery::mock(\Illuminate\Filesystem\Filesystem::class)->makePartial();
$this->swap('files', $filesystem);

$tracer = $this->mock(Tracer::class);

$tracer->shouldReceive('execute')
->with(resolve(Blueprint::class), $filesystem)
->with(resolve(Blueprint::class), $this->files)
->andReturn([
"Model" => [],
"OtherModel" => [],
Expand Down
Loading