playerRepository = $this->objectManager->get('TomasNorre\GolfnetInvitational\Domain\Repository\PlayerRepository'); /** @var \TomasNorre\GolfnetInvitational\Domain\Repository\TeamRepository teamRepository */ $this->teamRepository = $this->objectManager->get('TomasNorre\GolfnetInvitational\Domain\Repository\TeamRepository'); // Todo: Shouldn't be needed. Ask Irene /** @var persistenceManager */ $this->persistenceManager = $this->objectManager->get('TYPO3\Flow\Persistence\PersistenceManagerInterface'); $this->createPlayers(); } /** * Tear down */ public function tearDown() { $this->playerRepository->removeAll(); $this->persistenceManager->persistAll(); unset($this->playerRepository); unset($this->persistenceManager); } /** * Can objects be instanciated ? * * @test */ public function canInstanciate() { $this->assertTrue($this->persistenceManager instanceof \TYPO3\Flow\Persistence\PersistenceManagerInterface); $this->assertTrue($this->playerRepository instanceof \TomasNorre\GolfnetInvitational\Domain\Repository\PlayerRepository); } /** * @test */ public function findAllNotCaptain() { $expectedPlayersNotCaptainArray = array( 'Bubba Watson', 'Rory McIlroy' ); $actualPlayersNotCaptainArray = array(); $playersNotCaptain = $this->playerRepository->findAllNotCaptain(); /** @var \TomasNorre\GolfnetInvitational\Domain\Model\Player $playerNotCaptain */ foreach($playersNotCaptain as $playerNotCaptain) { $actualPlayersNotCaptainArray[] = $playerNotCaptain->getName(); } sort($actualPlayersNotCaptainArray); $this->assertSame($expectedPlayersNotCaptainArray, $actualPlayersNotCaptainArray); } /** * @test */ public function findAllInTeam() { $actuallyPlayersInTeam = array(); $expectedPlayersInTeam = array( 'Luke Donald', 'Tiger Woods' ); /** @var \TomasNorre\GolfnetInvitational\Domain\Model\Team $team */ $team = $this->teamRepository->findOneByName('TeamA'); $players = $this->playerRepository->findAllInTeam($team); \TYPO3\Flow\var_dump('players count: ' . $players->count()); /** @var \TomasNorre\GolfnetInvitational\Domain\Model\Player $player */ foreach($players as $player) { $actuallyPlayersInTeam[] = $player->getName(); } sort($actuallyPlayersInTeam); $this->assertSame($expectedPlayersInTeam, $actuallyPlayersInTeam); } /** * Create Teams Data */ protected function createPlayers() { // Teams /** @var \TomasNorre\GolfnetInvitational\Domain\Model\Team $teamA */ $teamA = $this->objectManager->get('TomasNorre\GolfnetInvitational\Domain\Model\Team'); $teamA->setName('TeamA'); /** @var \TomasNorre\GolfnetInvitational\Domain\Model\Team $teamB */ $teamB = $this->objectManager->get('TomasNorre\GolfnetInvitational\Domain\Model\Team'); $teamB->setName('TeamB'); $this->teamRepository->add($teamA); $this->teamRepository->add($teamB); // Players /** @var \TomasNorre\GolfnetInvitational\Domain\Model\Player $playerA */ $playerA = $this->objectManager->get('TomasNorre\GolfnetInvitational\Domain\Model\Player'); $playerA->setName('Luke Donald'); $playerA->setTeam($teamA); $playerA->setIsCaptain(TRUE); /** @var \TomasNorre\GolfnetInvitational\Domain\Model\Player $playerB */ $playerB = $this->objectManager->get('TomasNorre\GolfnetInvitational\Domain\Model\Player'); $playerB->setName('Tiger Woods'); $playerB->setTeam($teamA); $playerB->setIsCaptain(TRUE); /** @var \TomasNorre\GolfnetInvitational\Domain\Model\Player $playerC */ $playerC = $this->objectManager->get('TomasNorre\GolfnetInvitational\Domain\Model\Player'); $playerC->setName('Adam Scott'); $playerC->setIsCaptain(TRUE); /** @var \TomasNorre\GolfnetInvitational\Domain\Model\Player $playerD */ $playerD = $this->objectManager->get('TomasNorre\GolfnetInvitational\Domain\Model\Player'); $playerD->setName('Bubba Watson'); $playerD->setTeam($teamB); /** @var \TomasNorre\GolfnetInvitational\Domain\Model\Player $playerE */ $playerE = $this->objectManager->get('TomasNorre\GolfnetInvitational\Domain\Model\Player'); $playerE->setName('Rory McIlroy'); $this->playerRepository->add($playerA); $this->playerRepository->add($playerB); $this->playerRepository->add($playerC); $this->playerRepository->add($playerD); $this->playerRepository->add($playerE); $this->persistenceManager->persistAll(); } }