Ejemplo n.º 1
0
 public function test_drawing_card_removes_card_from_deck()
 {
     $deck = Deck::standard(DeckId::generate());
     $this->assertCount(52, $deck->getCards());
     $deck->drawCard();
     $this->assertCount(51, $deck->getCards());
 }
 public function test_it_adds_new_deck_into_repository()
 {
     $deckId = DeckId::generate();
     $this->assertNull($this->repository->findById($deckId));
     $command = new CreateDeck($deckId);
     $this->handler->handle($command);
     $this->assertInstanceOf(Deck::class, $this->repository->findById($deckId));
 }
 public function test_it_shuffles_the_cards_within_the_deck()
 {
     $deckId = DeckId::generate();
     $deck = Deck::standard($deckId);
     $cards = $deck->getCards();
     $this->repository->add($deck);
     $this->handler->handle(new ShuffleDeck($deckId));
     $deck = $this->repository->findById($deckId);
     $this->assertNotEquals($cards, $deck->getCards());
 }
<?php

require_once __DIR__ . '/../bootstrap.php';
use DeckOfCards\Domain\Deck;
use DeckOfCards\Domain\DeckId;
use DeckOfCards\Application\Commands\ShuffleDeck;
use DeckOfCards\Application\Commands\ShuffleDeckHandler;
use DeckOfCards\Infrastructure\Repositories\InMemoryDeckRepository;
$decks = new InMemoryDeckRepository();
$deckId = DeckId::generate();
$decks->add(Deck::standard($deckId));
$locator->addHandler(new ShuffleDeckHandler($decks), ShuffleDeck::class);
$bus->handle(new ShuffleDeck((string) $deckId));
print_deck($decks->findById($deckId));
echo "\n";
Ejemplo n.º 5
0
 /**
  * @return DeckId
  */
 public function getId()
 {
     return DeckId::fromString($this->id);
 }