Skip to content

Commit

Permalink
Backfill tests for blueprint:erase (#320)
Browse files Browse the repository at this point in the history
  • Loading branch information
jasonmccreary authored Aug 13, 2020
1 parent a2cde81 commit 94d8078
Show file tree
Hide file tree
Showing 5 changed files with 93 additions and 11 deletions.
1 change: 0 additions & 1 deletion src/Commands/BuildCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
7 changes: 4 additions & 3 deletions src/Commands/EraseCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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) {
Expand All @@ -60,7 +61,7 @@ public function handle()
}

collect($files)->each(function ($file) {
$this->line('- ' . $file);
$this->line('- '.$file);
});

$this->line('');
Expand Down
3 changes: 3 additions & 0 deletions tests/Feature/Commands/BuildCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@
use Mockery\Adapter\Phpunit\MockeryPHPUnitIntegration;
use Tests\TestCase;

/**
* @covers \Blueprint\Commands\BuildCommand
*/
class BuildCommandTest extends TestCase
{
use MockeryPHPUnitIntegration;
Expand Down
83 changes: 83 additions & 0 deletions tests/Feature/Commands/EraseCommandTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
<?php

namespace Tests\Feature\Commands;

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

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

/** @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')
->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);
}
}
10 changes: 3 additions & 7 deletions tests/Feature/Commands/NewCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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();
Expand Down

0 comments on commit 94d8078

Please sign in to comment.