Exemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function __construct($configuration)
 {
     parent::__construct($configuration);
     $this->email = $configuration['email'];
     $this->dateAdded = new \DateTime($configuration['date_added']);
     $this->person = PersonModel::create($configuration['person']);
 }
$p1->addRelatives($a1);
$p1->addRelatives($a2);
$test->addResult(!$p1->findRelatives('Account')->contains($a1));
$test->addResult(!$a1->findRelatives('Person')->contains($p1));
$test->addResult($p1->findRelatives('Account')->contains($a2));
$test->addResult($a2->findRelatives('Person')->contains($p1));
$test->end();
/* ---------------------------------------------------------------------- M:M */
$test = $this->startTest('M:M, non-composite keys, non-recursive');
// Add relative from both sides
$p1 = PersonModel::create();
$b1 = Model::create('Book');
$p1->addRelatives($b1);
$test->addResult($p1->findRelatives('Book')->contains($b1));
$test->addResult($b1->findRelatives('Person')->contains($p1));
$p2 = PersonModel::create();
$b2 = Model::create('Book');
$b2->addRelatives($p2);
$test->addResult($p2->findRelatives('Book')->contains($b2));
$test->addResult($b2->findRelatives('Person')->contains($p2));
// Disown relative from both sides
$b2->disownRelatives($p2);
$test->addResult($p2->findRelatives('Book')->isEmpty());
$test->addResult($b2->findRelatives('Person')->isEmpty());
$p1->disownRelatives($b1);
$test->addResult($p1->findRelatives('Book')->isEmpty());
$test->addResult($b1->findRelatives('Person')->isEmpty());
// Add multiple relatives via a collection
$c = new ModelCollection(array($b1, $b2));
$p1->addRelatives($c);
$test->addResult($p1->findRelatives('Book')->contains($b1));