예제 #1
0
파일: HasOneTest.php 프로젝트: lytc/sloths
 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'));
 }