function print_deck(Deck $deck) { echo "Deck ID: {$deck->getId()}\n"; echo "Cards: \n"; foreach ($deck->getCards() as $card) { print_card($card); } }
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_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";
/** * @param CreateDeck $command */ public function handle(CreateDeck $command) { $id = $command->getId(); $deck = Deck::standard($id); $this->decks->add($deck); }
/** * @param Deck $deck */ public function add(Deck $deck) { $key = (string) $deck->getId(); $this->items[$key] = $deck; }