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')); }