reference() public static method

The normal semantics of get() apply. Normally this means that the field gets a fresh instance of the named entity. If a singleton has been defined, get() will return that.
public static reference ( string $name ) : callable
$name string The name of the entity to get.
return callable
 /**
  * @test
  */
 public function whenTheOneSideIsASingletonItMayGetSeveralChildObjects()
 {
     $this->factory->defineEntity('SpaceShip');
     $this->factory->defineEntity('Person', array('spaceShip' => FieldDef::reference('SpaceShip')));
     $ship = $this->factory->getAsSingleton('SpaceShip');
     $p1 = $this->factory->get('Person');
     $p2 = $this->factory->get('Person');
     $this->assertTrue($ship->getCrew()->contains($p1));
     $this->assertTrue($ship->getCrew()->contains($p2));
 }
 /**
  * @test
  */
 public function arrayElementsAreMappedToCollectionAsscociationFields()
 {
     $this->factory->defineEntity('SpaceShip');
     $this->factory->defineEntity('Person', array('spaceShip' => FieldDef::reference('SpaceShip')));
     $p1 = $this->factory->get('Person');
     $p2 = $this->factory->get('Person');
     $ship = $this->factory->get('SpaceShip', array('name' => 'Battlestar Galaxy', 'crew' => array($p1, $p2)));
     $this->assertTrue($ship->getCrew() instanceof ArrayCollection);
     $this->assertTrue($ship->getCrew()->contains($p1));
     $this->assertTrue($ship->getCrew()->contains($p2));
 }
 private function simpleSetup()
 {
     $this->factory->defineEntity('Person', array('spaceShip' => FieldDef::reference('SpaceShip')));
     $this->factory->defineEntity('Badge', array('owner' => FieldDef::reference('Person')));
     $this->factory->defineEntity('SpaceShip');
 }
Esempio n. 4
0
 public function setUp()
 {
     parent::setUp();
     $this->factory->defineEntity('SpaceShip');
     $this->factory->defineEntity('Person', array('name' => 'Eve', 'spaceShip' => FieldDef::reference('SpaceShip')));
 }