Exemple #1
0
 public function test()
 {
     $rows = [['id' => 2, 'name' => 'foo'], ['id' => 3, 'name' => 'bar']];
     $stmt = $this->getMock('stmt', ['fetchAll']);
     $stmt->expects($this->once())->method('fetchAll')->with(\PDO::FETCH_ASSOC)->willReturn($rows);
     $connection = $this->getMock('Sloths\\Db\\Connection', ['query'], ['dsn']);
     $connection->expects($this->once())->method('query')->with("SELECT roles.id, roles.name, user_roles.user_id FROM roles INNER JOIN user_roles ON ((user_roles.role_id = roles.id) AND (user_roles.user_id = 1))")->willReturn($stmt);
     $connectionManager = new ConnectionManager();
     $connectionManager->setConnection($connection);
     $user = new User(['id' => 1]);
     $user->setDefaultConnectionManager($connectionManager);
     $roles = $user->getHasMany('Roles');
     $this->assertSame($rows, $roles->toArray());
 }
Exemple #2
0
 public function test()
 {
     $rows = [['id' => 2, 'user_id' => 1], ['id' => 3, 'user_id' => 1]];
     $stmt = $this->getMock('stmt', ['fetchAll']);
     $stmt->expects($this->once())->method('fetchAll')->with(\PDO::FETCH_ASSOC)->willReturn($rows);
     $connection = $this->getMock('Sloths\\Db\\Connection', ['query'], ['dsn']);
     $connection->expects($this->once())->method('query')->with("SELECT posts.id, posts.user_id, posts.title FROM posts WHERE (posts.user_id = 1)")->willReturn($stmt);
     $connectionManager = new ConnectionManager();
     $connectionManager->setConnection($connection);
     $user = new User(['id' => 1]);
     $user->setDefaultConnectionManager($connectionManager);
     $posts = $user->getHasMany('Posts');
     $this->assertSame($rows, $posts->toArray());
     $this->assertTrue($user->hasHasMany('Posts'));
 }
Exemple #3
0
 public function test()
 {
     $rows = [['id' => 2, 'name' => 'foo']];
     $stmt = $this->getMock('stmt', ['fetchAll']);
     $stmt->expects($this->once())->method('fetchAll')->with(\PDO::FETCH_ASSOC)->willReturn($rows);
     $connection = $this->getMock('Sloths\\Db\\Connection', ['query'], ['dsn']);
     $connection->expects($this->once())->method('query')->with("SELECT profiles.* FROM profiles WHERE (profiles.user_id = 1) LIMIT 1")->willReturn($stmt);
     $connectionManager = new ConnectionManager();
     $connectionManager->setConnection($connection);
     $user = new User(['id' => 1]);
     $user->setDefaultConnectionManager($connectionManager);
     $profile = $user->getHasOne('Profile');
     $this->assertSame($rows[0], $profile->toArray());
     $this->assertTrue($user->hasHasOne('Profile'));
 }