Last active
August 29, 2015 14:23
-
-
Save tomasnorre/f074be14116e944d9ee7 to your computer and use it in GitHub Desktop.
$playerRepository->findAllInTeam()
This file contains hidden or 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
<?php | |
namespace TomasNorre\GolfnetInvitational\Domain\Model; | |
use TYPO3\Flow\Annotations as Flow; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* Class Player | |
* @package TomasNorre\GolfnetInvitational | |
* | |
* @Flow\Entity | |
*/ | |
class Player { | |
/** | |
* @var string Name | |
*/ | |
protected $name; | |
/** | |
* @var boolean isCaptain | |
*/ | |
protected $isCaptain = FALSE; | |
/** | |
* @var \TomasNorre\GolfnetInvitational\Domain\Model\Team | |
* @ORM\ManyToOne | |
*/ | |
protected $team; | |
/** | |
* @param string $name | |
*/ | |
public function setName($name) { | |
$this->name = $name; | |
} | |
/** | |
* @return string | |
*/ | |
public function getName() { | |
return $this->name; | |
} | |
/** | |
* @return \TomasNorre\GolfnetInvitational\Domain\Model\Team | |
*/ | |
public function getTeam() { | |
return $this->team; | |
} | |
/** | |
* @param \TomasNorre\GolfnetInvitational\Domain\Model\Team $team | |
* @return void | |
*/ | |
public function setTeam($team) { | |
$this->team = $team; | |
} | |
/** | |
* @return boolean | |
*/ | |
public function getIsCaptain() { | |
return $this->isCaptain; | |
} | |
/** | |
* @param boolean $isCaptain | |
*/ | |
public function setIsCaptain($isCaptain) { | |
$this->isCaptain = $isCaptain; | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace TomasNorre\GolfnetInvitational\Domain\Repository; | |
use TYPO3\Flow\Annotations as Flow; | |
use TYPO3\Flow\Reflection\ObjectAccess; | |
/** | |
* Class PlayerRepository | |
* @package TomasNorre\GolfnetInvitational\Domain\Repository | |
* @Flow\Scope("singleton") | |
*/ | |
class PlayerRepository extends \TYPO3\Flow\Persistence\Repository { | |
/** | |
* @Flow\Inject | |
* @var \TomasNorre\GolfnetInvitational\Domain\Repository\TeamRepository | |
*/ | |
protected $teamRepository; | |
/** | |
* @return \TYPO3\Flow\Persistence\QueryResultInterface | |
*/ | |
public function findAllNotCaptain() { | |
$query = $this->createQuery(); | |
$query->matching( | |
$query->logicalNot($query->equals('isCaptain', TRUE)) | |
); | |
return $query->execute(); | |
} | |
/** | |
* @param \TomasNorre\GolfnetInvitational\Domain\Model\Team $team | |
* | |
* @return \TYPO3\Flow\Persistence\QueryResultInterface | |
*/ | |
public function findAllInTeam(\TomasNorre\GolfnetInvitational\Domain\Model\Team $team ) { | |
$query = $this->createQuery(); | |
$query->matching( | |
$query->equals('team', $team) | |
); | |
return $query->execute(); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace TomasNorre\GolfnetInvitational\Tests\Functional\Domain\Repository; | |
use TomasNorre\GolfnetInvitational\Domain\Repository\PlayerRepository; | |
use TYPO3\Flow\Annotations as Flow; | |
/** | |
* Class PlayerRespositoryTest | |
* @package TomasNorre\GolfnetInvitational | |
*/ | |
class PlayerRespositoryTest extends \TYPO3\Flow\Tests\FunctionalTestCase { | |
/** | |
* @Flow\Inject | |
* @var \TomasNorre\GolfnetInvitational\Domain\Repository\PlayerRepository | |
*/ | |
protected $playerRepository; | |
/** | |
* @Flow\Inject | |
* @var \TomasNorre\GolfnetInvitational\Domain\Repository\TeamRepository | |
*/ | |
protected $teamRepository; | |
/** | |
* @Flow\Inject | |
* @var \TYPO3\Flow\Persistence\PersistenceManagerInterface | |
*/ | |
protected $persistenceManager; | |
/** | |
* @var boolean | |
*/ | |
static protected $testablePersistenceEnabled = TRUE; | |
/** | |
* Set up | |
*/ | |
public function setUp() { | |
parent::setUp(); | |
/** @var \TomasNorre\GolfnetInvitational\Domain\Repository\PlayerRepository playerRepository */ | |
$this->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(); | |
} | |
} |
This file contains hidden or 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
<?php | |
namespace TomasNorre\GolfnetInvitational\Domain\Model; | |
use TYPO3\Flow\Annotations as Flow; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* Class Team | |
* @package TomasNorre\GolfnetInvitational | |
* | |
* @Flow\Entity | |
*/ | |
class Team { | |
/** | |
* @var string | |
*/ | |
protected $name; | |
/** | |
* @var \Doctrine\Common\Collections\Collection<\TomasNorre\GolfnetInvitational\Domain\Model\Player> $players | |
* @ORM\OneToMany(mappedBy="\TomasNorre\GolfnetInvitational\Domain\Model\Player") | |
*/ | |
protected $players; | |
/** | |
* @param string $name | |
*/ | |
public function setName($name) { | |
$this->name = $name; | |
} | |
/** | |
* @return string | |
*/ | |
public function getName() { | |
return $this->name; | |
} | |
/** | |
* @return \Doctrine\Common\Collections\Collection | |
*/ | |
public function getPlayers() { | |
return $this->players; | |
} | |
/** | |
* @param \Doctrine\Common\Collections\Collection $players | |
*/ | |
public function setPlayers($players) { | |
$this->players = $players; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment