/** * @covers ::byRepo */ public function testByRepo() { $source = [0 => new Model(), 1 => new Model(), 2 => new SoftDeleteModel(), 3 => new Model(), 4 => new SoftDeleteModel()]; $models = new Models($source); $expected = [[Model::getRepo(), [$source[0], $source[1], $source[3]]], [SoftDeleteModel::getRepo(), [$source[2], $source[4]]]]; $i = 0; $models->byRepo(function ($repo, Models $repoModels) use($expected, &$i) { $this->assertSame($expected[$i][0], $repo); $this->assertSame($expected[$i][1], Objects::toArray($repoModels->all())); $i++; }); }
/** * @covers ::all */ public function testGetLinkMany() { $model2 = new Model(); $model = $this->getMock(__NAMESPACE__ . '\\Model', ['getLink'], [], 'MockLinkMany'); $link1 = new LinkMany($model, new RelMany('test', Model::getRepo(), Model::getRepo()), []); $link2 = new LinkOne($model, new RelOne('test', Model::getRepo(), Model::getRepo()), $model2); $model->expects($this->exactly(2))->method('getLink')->with($this->equalTo('test'))->will($this->onConsecutiveCalls($link1, $link2)); $result = $model->all('test'); $this->assertSame($link1, $result); $this->setExpectedException('LogicException', 'Rel test for MockLinkMany must be a valid RelMany'); $model->all('test'); }