clientRepository ->createQueryBuilder('c') ->delete() ->getQuery() ->execute(); $this->clients = []; } /** * @Given /^there exist following clients:$/ */ public function thereExistFollowingClients(TableNode $table) { foreach ($table as $row) { $client = $this->getClient($row['clientId']); if (!$client) { $client = new Client( clientId: Uuid::fromRfc4122($row['clientId']), name: $row['name'], initialBalance: intval($row['initialBalance']), currentBalance: intval($row['currentBalance']), lockedAt: $row['locked'] === 'yes' ? new \DateTimeImmutable() : null, ); $this->clientRepository->save($client); } $this->clients[$client->getClientId()->toRfc4122()] = $client; } } public function getClient(string $id): ?Client { return $this->clients[$id] ??= $this->clientRepository->find(Uuid::fromRfc4122($id)); } /** * @Given /^client with id "([^"]+)" should exist$/ */ public function clientWithIdShouldExist(string $clientId) { Assert::assertNotNull($this->getClient($clientId)); } /** * @Given /^client with id "([^"]+)" should be locked$/ */ public function clientWithIdIsLocked(string $clientId) { Assert::assertTrue($this->getClient($clientId)->isLocked()); } /** * @Given /^client with id "([^"]+)" should not be locked$/ */ public function clientWithIdIsNotLocked(string $clientId) { Assert::assertFalse($this->getClient($clientId)->isLocked()); } /** * @Given /^client with id "([^"]+)" should have balance of (\d+)$/ */ public function clientWithIdShouldHaveBalanceOf(string $clientId, int $balance) { $client = $this->getClient($clientId); Assert::assertEquals($balance, $client->getBalance()); } }