/** * @covers ::update */ public function testUpdate() { $repo = Category::getRepo(); $model1 = $this->getMock(__NAMESPACE__ . '\\Category', ['setPathAndUpdateDescendants']); $model2 = new Category(['id' => 6, 'path' => '1/4']); $models = new Models([$model2]); $model1->expects($this->once())->method('setPathAndUpdateDescendants')->with('1/4/6')->will($this->returnValue($models)); $rel = new BelongsTo('test', $repo->getConfig(), $repo); $link = new LinkOne($model1, $rel, $model1); $result = $rel->update($link); $this->assertNull($result); $link->set($model2); $result = $rel->update($link); $this->assertSame($models, $result); }
/** * @covers ::update */ public function testUpdate() { $repo = Category::getRepo(); $model = new Category(['id' => 6, 'path' => '1/4']); $model1 = $this->getMock(__NAMESPACE__ . '\\Category', ['setPathAndUpdateDescendants'], [['id' => 1]]); $model2 = $this->getMock(__NAMESPACE__ . '\\Category', ['setPathAndUpdateDescendants'], [['id' => 2]]); $added = new Models([$model1]); $removed = new Models([$model2]); $model1->expects($this->once())->method('setPathAndUpdateDescendants')->with('1/4/6')->will($this->returnValue($added)); $model2->expects($this->once())->method('setPathAndUpdateDescendants')->with('')->will($this->returnValue($removed)); $rel = new HasMany('test', $repo->getConfig(), $repo); $link = new LinkMany($model, $rel, [$model2]); $result = $rel->update($link); $this->assertCount(0, $result); $link->add($model1)->remove($model2); $result = $rel->update($link); $this->assertSame([$model2, $model1], $result->toArray()); }
public static function initialize($config) { parent::initialize($config); }
/** * @covers ::getAnsestors */ public function testGetAnsestors() { $cat1 = Category::find(1); $cat2 = Category::find(2); $cat3 = Category::find(4); $parents = $cat3->getAnsestors(); $this->assertInstanceOf('Harp\\Harp\\Model\\Models', $parents); $this->assertSame([$cat1, $cat2], $parents->toArray()); $parents = $cat1->getAnsestors(); $this->assertInstanceOf('Harp\\Harp\\Model\\Models', $parents); $this->assertCount(0, $parents->toArray()); }