コード例 #1
0
 /**
  * @covers ::update
  */
 public function testUpdate()
 {
     $rel = new HasManyExclusive('cities', Country::getRepo()->getConfig(), 'Harp\\Harp\\Test\\TestModel\\City');
     $model = new Country(['id' => 2]);
     $foreign1 = new City(['countryId' => 2]);
     $foreign2 = new City(['countryId' => 2]);
     $foreign3 = new City(['countryId' => 8]);
     $link = new LinkMany($model, $rel, [$foreign1, $foreign2]);
     $link->remove($foreign1);
     $link->add($foreign3);
     $rel->update($link);
     $this->assertEquals(2, $foreign2->countryId);
     $this->assertEquals(2, $foreign3->countryId);
 }
コード例 #2
0
ファイル: SaveTest.php プロジェクト: harp-orm/harp
 /**
  * @covers ::add
  */
 public function testAdd()
 {
     $save = new Save();
     $models = [0 => new User(), 1 => new Address(), 2 => new Country(), 3 => new City(), 4 => new City(), 5 => new City(), 6 => new Address()];
     $link1 = new LinkOne($models[0], User::getRepo()->getRel('address'), $models[1]);
     $link1->set($models[6]);
     $link2 = new LinkMany($models[2], Country::getRepo()->getRel('cities'), [$models[3], $models[4]]);
     $link2->remove($models[3]);
     $link2->add($models[5]);
     User::getRepo()->addLink($link1);
     Country::getRepo()->addLink($link2);
     $save->add($models[0])->add($models[2]);
     $this->assertCount(count($models), $save);
     foreach ($models as $model) {
         $this->assertTrue($save->has($model));
     }
 }
コード例 #3
0
ファイル: HasManyThroughTest.php プロジェクト: harp-orm/harp
 /**
  * @covers ::delete
  * @covers ::insert
  */
 public function testUpdate()
 {
     $rel = new HasManyThrough('tags', Post::getRepo()->getConfig(), 'Harp\\Harp\\Test\\TestModel\\Tag', 'postTags');
     $model = new Post(['id' => 2]);
     $foreign1 = new Tag(['id' => 5]);
     $foreign2 = new Tag(['id' => 6]);
     $foreign3 = new Tag(['id' => 7]);
     $link1 = new PostTag(['tagId' => 5, 'postId' => 2], State::SAVED);
     $link2 = new PostTag(['tagId' => 6, 'postId' => 2], State::SAVED);
     $postTagsLink = new LinkMany($model, Post::getRepo()->getRel('postTags'), [$link1, $link2]);
     Post::getRepo()->addLink($postTagsLink);
     $link = new LinkMany($model, $rel, [$foreign1, $foreign2]);
     $link->remove($foreign1);
     $link->add($foreign3);
     $result = $rel->delete($link);
     $this->assertCount(1, $result);
     $this->assertSame($link1, $result->getFirst());
     $this->assertTrue($result->getFirst()->isDeleted());
     $this->assertFalse($postTagsLink->has($link1));
     $this->assertTrue($postTagsLink->has($link2));
     $result = $rel->insert($link);
     $this->assertCount(1, $result);
     $this->assertInstanceOf('Harp\\Harp\\Test\\TestModel\\PostTag', $result->getFirst());
     $this->assertTrue($result->getFirst()->isPending());
     $this->assertEquals(['postId' => 2, 'tagId' => 7, 'id' => null], $result->getFirst()->getProperties());
     $this->assertTrue($postTagsLink->has($result->getFirst()));
 }
コード例 #4
0
ファイル: HasManyAsTest.php プロジェクト: harp-orm/harp
 /**
  * @covers ::update
  */
 public function testUpdate()
 {
     $rel = new HasManyAs('users', City::getRepo()->getConfig(), 'Harp\\Harp\\Test\\TestModel\\User', 'location');
     $model = new City(['id' => 2]);
     $foreign1 = new User(['locationId' => 2, 'locationClass' => 'Harp\\Harp\\Test\\TestModel\\City']);
     $foreign2 = new User(['locationId' => 2, 'locationClass' => 'Harp\\Harp\\Test\\TestModel\\City']);
     $foreign3 = new User(['locationId' => 8, 'locationClass' => 'Harp\\Harp\\Test\\TestModel\\Country']);
     $link = new LinkMany($model, $rel, [$foreign1, $foreign2]);
     $link->remove($foreign1);
     $link->add($foreign3);
     $rel->update($link);
     $this->assertEquals(null, $foreign1->locationId);
     $this->assertEquals(null, $foreign1->locationClass);
     $this->assertEquals(2, $foreign2->locationId);
     $this->assertEquals('Harp\\Harp\\Test\\TestModel\\City', $foreign2->locationClass);
     $this->assertEquals(2, $foreign3->locationId);
     $this->assertEquals('Harp\\Harp\\Test\\TestModel\\City', $foreign3->locationClass);
 }
コード例 #5
0
ファイル: LinkManyTest.php プロジェクト: harp-orm/harp
 /**
  * @covers ::remove
  */
 public function testRemove()
 {
     $city = new City();
     $link = new LinkMany(new Country(), Country::getRepo()->getRel('cities'), [$city]);
     $link->remove($city);
     $this->assertCount(0, $link);
     $this->assertFalse($link->has($city));
     $link->remove($city);
     $this->assertCount(0, $link);
     $this->assertFalse($link->has($city));
 }