-
Notifications
You must be signed in to change notification settings - Fork 281
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #44 from laravel-shift/extensible
Register Blueprint as singleton for extensibility
- Loading branch information
Showing
4 changed files
with
82 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
<?php | ||
|
||
namespace Blueprint; | ||
|
||
class Builder | ||
{ | ||
public static function execute(Blueprint $blueprint, string $draft) | ||
{ | ||
// TODO: read in previous models... | ||
|
||
$tokens = $blueprint->parse($draft); | ||
$registry = $blueprint->analyze($tokens); | ||
$generated = $blueprint->generate($registry); | ||
|
||
// TODO: save to .blueprint | ||
|
||
return $generated; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Tests\Unit; | ||
|
||
use Blueprint\Blueprint; | ||
use Blueprint\Builder; | ||
use Tests\TestCase; | ||
|
||
class BuilderTest extends TestCase | ||
{ | ||
/** | ||
* @test | ||
*/ | ||
public function execute_uses_blueprint_to_build_draft() | ||
{ | ||
$digits = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]; | ||
shuffle($digits); | ||
|
||
$draft = implode($digits); | ||
$tokens = $digits; | ||
$registry = array_rand($digits, 9); | ||
$generated = array_rand($digits, 9); | ||
|
||
$blueprint = \Mockery::mock(Blueprint::class); | ||
$blueprint->expects('parse') | ||
->with($draft) | ||
->andReturn($tokens); | ||
$blueprint->expects('analyze') | ||
->with($tokens) | ||
->andReturn($registry); | ||
$blueprint->expects('generate') | ||
->with($registry) | ||
->andReturn($generated); | ||
|
||
$actual = Builder::execute($blueprint, $draft); | ||
|
||
$this->assertSame($generated, $actual); | ||
} | ||
} |