Пример #1
0
 public function testFetchAll()
 {
     $queryResult = array('super');
     $preparedQuery = $this->getMockBuilder('\\Sindri\\Database\\Query\\PreparedQuery')->disableOriginalConstructor()->getMock();
     $preparedQuery->expects($this->once())->method('fetchAll')->with($this->equalTo(PDO::FETCH_ASSOC))->will($this->returnValue($queryResult));
     $queryMock = $this->getQueryMock();
     $queryMock->expects($this->once())->method('execute')->will($this->returnValue($preparedQuery));
     /** @var $queryMock QueryInterface */
     $proxyQuery = new ProxyQuery($queryMock);
     $result = $proxyQuery->fetchAll();
     $this->assertSame($queryResult, $result);
 }
Пример #2
0
 /**
  * issue: statement->execute() called twice
  *
  * @see https://github.com/sindriphp/Database/issues/1
  */
 public function testStatementExecuteShouldNotCalledTwice()
 {
     $pdoStatmentMock = $this->getMockBuilder('\\PDOStatement')->getMock();
     $pdoStatmentMock->expects($this->once())->method('execute')->will($this->returnValue(''));
     $pdoMock = $this->getMockBuilder('\\PDO')->setConstructorArgs(array('sqlite::memory:'))->getMock();
     $pdoMock->expects($this->once())->method('prepare')->will($this->returnValue($pdoStatmentMock));
     $actionQueue = new ActionQueue();
     $connectionMock = $this->getMockBuilder('\\Sindri\\Database\\Connection')->setMethods(array('connect'))->setConstructorArgs(array('', '', 'sqlite::memory:', array(), $actionQueue))->getMock();
     $connectionMock->expects($this->any())->method('connect')->will($this->returnValue($pdoMock));
     $openQuery = new OpenQuery(1, $connectionMock, 'SELECT * FROM users', 'Y-m-d H:i:s');
     $query = new ProxyQuery($openQuery);
     $query->fetchAll();
 }