Beispiel #1
0
 public function testTest()
 {
     $user1 = User::find(1);
     $address1 = $user1->getAddress();
     $post1 = $user1->getPosts()->getFirst();
     $user2 = User::find(1);
     $address2 = $user2->getAddress();
     $post2 = $user2->getPosts()->getFirst();
     $address3 = Address::find(1);
     $post3 = Post::find(1);
     $this->assertSame($user1, $user2);
     $this->assertSame($address1, $address2);
     $this->assertSame($post1, $post2);
     $this->assertSame($address1, $address3);
     $this->assertSame($post1, $post3);
 }
Beispiel #2
0
 /**
  * @covers ::join
  */
 public function testJoinSoftDelete()
 {
     $rel = new BelongsTo('user', Address::getRepo()->getConfig(), 'Harp\\Harp\\Test\\TestModel\\User');
     $select = new Select(Address::getRepo());
     $rel->join($select, 'Address');
     $this->assertEquals('SELECT `Address`.* FROM `Address` JOIN `User` AS `user` ON `user`.`id` = `Address`.`userId` AND `user`.`deletedAt` IS NULL', $select->humanize());
 }
Beispiel #3
0
 /**
  * @coversNothing
  */
 public function testJoinRels()
 {
     $users = User::findAll()->joinRels(['posts' => 'tags'])->group('User.id')->load();
     $expected = User::find(1);
     $this->assertSame($expected, $users->getFirst());
     $addresses = Address::findAll()->joinRels(['user' => 'posts'])->load();
     $expected = Address::find(1);
     $this->assertSame($expected, $addresses->getFirst());
     $this->assertQueries(['SELECT `User`.* FROM `User` JOIN `Post` AS `posts` ON `posts`.`userId` = `User`.`id` JOIN `PostTag` AS `postTags` ON `postTags`.`postId` = `posts`.`id` JOIN `Tag` AS `tags` ON `tags`.`id` = `postTags`.`tagId` WHERE (`User`.`deletedAt` IS NULL) GROUP BY `User`.`id`', 'SELECT `User`.* FROM `User` WHERE (`id` = 1) AND (`User`.`deletedAt` IS NULL) LIMIT 1', 'SELECT `Address`.* FROM `Address` JOIN `User` AS `user` ON `user`.`addressId` = `Address`.`id` AND `user`.`deletedAt` IS NULL JOIN `Post` AS `posts` ON `posts`.`userId` = `user`.`id`', 'SELECT `Address`.* FROM `Address` WHERE (`id` = 1) LIMIT 1']);
 }
Beispiel #4
0
 /**
  * @covers ::getLink
  */
 public function testGetLink()
 {
     $user = User::find(1);
     $link = $user->getLink('address');
     $this->assertSame($user, $link->getModel());
     $this->assertSame(Address::getRepo(), $link->getRel()->getRepo());
 }