Example #1
0
 public function testDataIsLoadedOnlyOnce()
 {
     $fixtureSql = "SELECT * FROM foo";
     $statementMock = new Zend_Test_DbStatement();
     $statementMock->append(array('foo' => 'bar'));
     $adapterMock = $this->getMock('Zend_Test_DbAdapter');
     $adapterMock->expects($this->once())->method('query')->with($fixtureSql)->will($this->returnValue($statementMock));
     $this->decorateConnectionGetConnectionWith($adapterMock);
     $queryTable = new Zend_Test_PHPUnit_Db_DataSet_QueryTable("foo", $fixtureSql, $this->connectionMock);
     $this->assertEquals(1, $queryTable->getRowCount());
     $this->assertEquals(1, $queryTable->getRowCount());
     $row = $queryTable->getRow(0);
     $this->assertEquals(array('foo' => 'bar'), $row);
 }
Example #2
0
 public function testIsInstalled()
 {
     $installer = new Installer_Default($this->db);
     $this->assertFalse($installer->isInstalled());
     $this->dbAdapter->appendStatementToStack(Zend_Test_DbStatement::createSelectStatement(array('omeka_options')));
     $this->assertTrue($installer->isInstalled());
     $this->profilerHelper->assertDbQuery("SHOW TABLES LIKE 'omeka_options'");
 }
Example #3
0
 public function testAppendStatementToStack()
 {
     $stmt1 = Zend_Test_DbStatement::createSelectStatement(array());
     $this->_adapter->appendStatementToStack($stmt1);
     $stmt2 = Zend_Test_DbStatement::createSelectStatement(array());
     $this->_adapter->appendStatementToStack($stmt2);
     $this->assertSame($stmt2, $this->_adapter->query("foo"));
     $this->assertSame($stmt1, $this->_adapter->query("foo"));
 }
Example #4
0
 public function testSetRecordUsingIntegerId()
 {
     $builder = new DummyRecordBuilder($this->db);
     $this->dbAdapter->appendStatementToStack(Zend_Test_DbStatement::createSelectStatement(array(array('id' => self::DUMMY_RECORD_ID, 'description' => 'foobar'))));
     $builder->setRecord(self::DUMMY_RECORD_ID);
     $record = $builder->getRecord();
     $this->assertThat($record, $this->isInstanceOf('DummyRecordBuilderRecord'));
     $this->assertTrue($record->exists());
 }
Example #5
0
 public function testTotalItems()
 {
     $collectionId = 1;
     $this->dbAdapter = new Zend_Test_DbAdapter();
     $this->dbAdapter->appendLastInsertIdToStack($collectionId);
     $this->db = new Omeka_Db($this->dbAdapter);
     $this->collection = new Collection($this->db);
     $this->profilerHelper = new Omeka_Test_Helper_DbProfiler($this->db->getAdapter()->getProfiler(), $this);
     $this->dbAdapter->appendStatementToStack(Zend_Test_DbStatement::createSelectStatement(array(array(3))));
     $this->assertEquals(3, $this->collection->totalItems());
 }
 public function testFetchObject_ClassNotExists_ThrowsException()
 {
     $this->setExpectedException("Zend_Db_Statement_Exception");
     $row = array("foo" => "bar", "bar" => "baz");
     $stmt = new Zend_Test_DbStatement();
     $stmt->append($row);
     $object = $stmt->fetchObject("anInvalidClassName");
 }
 /**
  * Prepare a statement and return a PDOStatement-like object.
  *
  * @param string|Zend_Db_Select $sql SQL query
  * @return Zend_Db_Statment|PDOStatement
  */
 public function prepare($sql)
 {
     $queryId = $this->getProfiler()->queryStart($sql);
     if (count($this->_statementStack)) {
         $stmt = array_pop($this->_statementStack);
     } else {
         $stmt = new Zend_Test_DbStatement();
     }
     if ($this->getProfiler()->getEnabled() == true) {
         $qp = $this->getProfiler()->getQueryProfile($queryId);
         $stmt->setQueryProfile($qp);
     }
     return $stmt;
 }
 /**
  * Create a Row Count Statement
  *
  * @param  int $affectedRows
  * @return Zend_Test_DbStatement
  */
 protected static function _createRowCountStatement($affectedRows)
 {
     $stmt = new Zend_Test_DbStatement();
     $stmt->setRowCount($affectedRows);
     return $stmt;
 }