/**
  * @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());
 }
 /**
  * @covers ::initialize
  */
 public function testInitialize()
 {
     $repo = Category::getRepo();
     $this->assertInstanceOf('Harp\\Harp\\Rel\\BelongsTo', $repo->getRel('parent'));
     $this->assertInstanceOf('Harp\\Harp\\Rel\\HasMany', $repo->getRel('children'));
 }