/** * @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'); }
/** * @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 ::getErrors * @covers ::isEmptyErrors * @covers ::validate */ public function testErrors() { $model = new Model(); $this->assertInstanceOf('Harp\\Validate\\Errors', $model->getErrors()); $this->assertCount(0, $model->getErrors()); $this->assertTrue($model->isEmptyErrors()); $model->name = null; $model->other = null; $result = $model->validate(); $this->assertFalse($result); $this->assertInstanceOf('Harp\\Validate\\Errors', $model->getErrors()); $this->assertCount(2, $model->getErrors()); $this->assertFalse($model->isEmptyErrors()); $this->assertCount(1, $model->getErrors()->onlyFor('name')); $this->assertCount(1, $model->getErrors()->onlyFor('other')); }