Esempio n. 1
0
 /**
  * @covers ::loadRelFor
  */
 public function testLoadRelFor()
 {
     $repo = new Repo(__NAMESPACE__ . '\\Model');
     Model::$repo = $repo;
     $modelsSource = [new Model(), new Model()];
     $foreignSource = [new Model(), new Model()];
     $models = new Models($modelsSource);
     $foreign = new Models($foreignSource);
     $rel = $this->getMock(__NAMESPACE__ . '\\RelOne', ['loadForeignModels', 'areLinked'], ['test', $repo, $repo]);
     $repo->addRels([$rel]);
     $rel->expects($this->once())->method('loadForeignModels')->with($this->identicalTo($models), $this->equalTo(State::DELETED))->will($this->returnValue($foreign));
     $map = [[$modelsSource[0], $foreignSource[0], true], [$modelsSource[1], $foreignSource[0], false], [$modelsSource[0], $foreignSource[1], false], [$modelsSource[1], $foreignSource[1], true]];
     $rel->expects($this->exactly(4))->method('areLinked')->will($this->returnValueMap($map));
     $result = $repo->loadRelFor($models, 'test', State::DELETED);
     $this->assertSame($foreign, $result);
     $link1 = $repo->loadLink($modelsSource[0], 'test');
     $link2 = $repo->loadLink($modelsSource[1], 'test');
     $this->assertSame($foreignSource[0], $link1->get());
     $this->assertSame($foreignSource[1], $link2->get());
     Model::$repo = null;
 }
Esempio n. 2
0
 /**
  * @covers ::onlyDeleted
  * @covers ::onlySaved
  * @covers ::deletedAndSaved
  */
 public function testFlagSetters()
 {
     $repo = new Repo(__NAMESPACE__ . '\\Model');
     $repo->setSoftDelete(true);
     $find = new Find($repo);
     $find->onlyDeleted();
     $this->assertSame(State::DELETED, $find->getFlags());
     $find->onlySaved();
     $this->assertSame(State::SAVED, $find->getFlags());
     $find->deletedAndSaved();
     $this->assertSame(State::DELETED | State::SAVED, $find->getFlags());
 }