-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
37 changed files
with
920 additions
and
172 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
90 changes: 90 additions & 0 deletions
90
spec/EricksonReyes/DomainDrivenDesign/Application/CommandHandlerSpec.php
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,90 @@ | ||
<?php | ||
|
||
namespace spec\EricksonReyes\DomainDrivenDesign\Application; | ||
|
||
use EricksonReyes\DomainDrivenDesign\Application\CommandHandler; | ||
use EricksonReyes\DomainDrivenDesign\Application\Exception\DuplicateCommandHandlerException; | ||
use EricksonReyes\DomainDrivenDesign\Application\Exception\MissingHandlerMethodException; | ||
use EricksonReyes\DomainDrivenDesign\Application\Exception\UnhandledCommandException; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class CommandHandlerSpec extends ObjectBehavior | ||
{ | ||
/** | ||
* @var Handler | ||
*/ | ||
private $handler; | ||
|
||
/** | ||
* @var Command | ||
*/ | ||
private $command; | ||
|
||
public function let() | ||
{ | ||
$this->command = new Command(); | ||
$this->handler = new Handler(); | ||
} | ||
|
||
public function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(CommandHandler::class); | ||
} | ||
|
||
public function it_accepts_handlers() | ||
{ | ||
$this->addHandler(new Handler(), Command::class)->shouldBeNull(); | ||
} | ||
|
||
public function it_executes_commands() | ||
{ | ||
$this->addHandler(new Handler(), Command::class); | ||
$this->execute(new Command())->shouldReturn([Handler::class => Command::name()]); | ||
} | ||
|
||
public function it_requires_a_handler_for_commands() | ||
{ | ||
$this->shouldThrow(UnhandledCommandException::class)->during('execute', [ | ||
new Command() | ||
]); | ||
} | ||
|
||
public function it_requires_handler_to_have_handler_methods() | ||
{ | ||
$this->shouldThrow(MissingHandlerMethodException::class)->during('addHandler', [ | ||
new EmptyHandler(), | ||
Command::class | ||
]); | ||
} | ||
|
||
public function it_prevents_duplicate_handler_for_a_command() | ||
{ | ||
$handler = new Handler(); | ||
$this->addHandler($handler, Command::class); | ||
$this->shouldThrow(DuplicateCommandHandlerException::class)->during('addHandler', [ | ||
$handler, | ||
Command::class | ||
]); | ||
} | ||
} | ||
|
||
class Command | ||
{ | ||
public static function name() | ||
{ | ||
return __CLASS__; | ||
} | ||
} | ||
|
||
class Handler | ||
{ | ||
public function handleThis(Command $command) | ||
{ | ||
return $command::name(); | ||
} | ||
} | ||
|
||
class EmptyHandler | ||
{ | ||
|
||
} |
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
34 changes: 34 additions & 0 deletions
34
spec/EricksonReyes/DomainDrivenDesign/Domain/DomainEntityUnitTest.php
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,34 @@ | ||
<?php | ||
|
||
namespace spec\EricksonReyes\DomainDrivenDesign\Domain; | ||
|
||
use EricksonReyes\DomainDrivenDesign\Domain\ValueObject\Identifier; | ||
use Faker\Factory; | ||
use Faker\Generator; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
abstract class DomainEntityUnitTest extends ObjectBehavior | ||
{ | ||
/** | ||
* @var Identifier | ||
*/ | ||
protected $id; | ||
|
||
/** | ||
* @var Generator | ||
*/ | ||
protected $seeder; | ||
|
||
public function __construct() | ||
{ | ||
$this->seeder = Factory::create(); | ||
} | ||
|
||
|
||
public function it_has_identity() | ||
{ | ||
$this->id()->shouldReturn($this->id); | ||
} | ||
|
||
abstract public function it_can_be_mark_as_deleted(); | ||
} |
Oops, something went wrong.