Exemplo n.º 1
0
    public function setUp()
    {
        $this->markTestSkipped('This suite is skipped until Zend\Db can be refactored.');
        
        if (!extension_loaded('pdo_sqlite')) {
            $this->markTestSkipped('Requires PDO Sqlite extension');
        }

        date_default_timezone_set('America/Los_Angeles');

        $this->_request  = new \Zend_Db_Profiler_FirebugTest_Request();
        $this->_response = new \Zend_Db_Profiler_FirebugTest_Response();

        $channel = Channel\HttpHeaders::getInstance();
        $channel->setRequest($this->_request);
        $channel->setResponse($this->_response);

        $this->_profiler = new Profiler\Firebug();
        $this->_db = \Zend\Db\DB::factory('Pdo\Sqlite',
                               array('dbname' => ':memory:',
                                     'profiler' => $this->_profiler));
        $this->_db->getConnection()->exec('CREATE TEMP TABLE foo (
                                              id      INTEGNER NOT NULL,
                                              col1    VARCHAR(10) NOT NULL
                                            )');
    }
Exemplo n.º 2
0
 /**
  * Open a new database connection
  */
 protected function _setUpAdapter()
 {
     $this->_db = \Zend\DB\DB::factory($this->getDriver(), $this->_util->getParams());
     try {
         $conn = $this->_db->getConnection();
     } catch (\Zend\Exception $e) {
         $this->_db = null;
         $this->assertType('Zend\\DB\\Adapter\\Exception', $e, 'Expecting Zend_Db_Adapter_Exception, got ' . get_class($e));
         $this->markTestSkipped($e->getMessage());
     }
 }
Exemplo n.º 3
0
 /**
  * Test AUTO_QUOTE_IDENTIFIERS option
  * Case: Zend_Db::AUTO_QUOTE_IDENTIFIERS = true
  */
 public function testAdapterAutoQuoteIdentifiersTrue()
 {
     $params = $this->_util->getParams();
     $params['options'] = array(DB\DB::AUTO_QUOTE_IDENTIFIERS => true);
     $db = DB\DB::factory($this->getDriver(), $params);
     $db->getConnection();
     $select = $this->_db->select();
     $select->from('zfproducts');
     $stmt = $this->_db->query($select);
     $result = $stmt->fetchAll();
     $this->assertEquals(3, count($result), 'Expected 3 rows in first query result');
     $this->assertEquals(1, $result[0]['product_id']);
 }
Exemplo n.º 4
0
 /**
  * Test AUTO_QUOTE_IDENTIFIERS option
  * Case: Zend_Db::AUTO_QUOTE_IDENTIFIERS = true
  *
  * SQLite actually allows delimited identifiers to remain
  * case-insensitive, so this test overrides its parent.
  */
 public function testAdapterAutoQuoteIdentifiersTrue()
 {
     $params = $this->_util->getParams();
     $params['options'] = array(DB\DB::AUTO_QUOTE_IDENTIFIERS => true);
     $db = DB\DB::factory($this->getDriver(), $params);
     $db->getConnection();
     $select = $this->_db->select();
     $select->from('zfproducts');
     $stmt = $this->_db->query($select);
     $result1 = $stmt->fetchAll();
     $this->assertEquals(1, $result1[0]['product_id']);
     $select = $this->_db->select();
     $select->from('ZFPRODUCTS');
     try {
         $stmt = $this->_db->query($select);
         $result2 = $stmt->fetchAll();
     } catch (\Zend\Exception $e) {
         $this->assertType('Zend_Db_Statement_Exception', $e, 'Expecting object of type Zend_Db_Statement_Exception, got ' . get_class($e));
         $this->fail('Unexpected exception ' . get_class($e) . ' received: ' . $e->getMessage());
     }
     $this->assertEquals($result1, $result2);
 }
Exemplo n.º 5
0
 /**
  * @group ZF-5146
  */
 public function testAdapterLobAsStringFromDriverOptions()
 {
     $params = $this->_util->getParams();
     $params['driver_options'] = array('lob_as_string' => true);
     $db = DB\DB::factory($this->getDriver(), $params);
     $this->assertTrue($db->getLobAsString());
 }
Exemplo n.º 6
0
 /**
  * @group ZF-1541
  */
 public function testCharacterSetUtf8()
 {
     // Create a new adapter
     $params = $this->_util->getParams();
     $params['charset'] = 'utf8';
     $db = DB\DB::factory($this->getDriver(), $params);
     // create a new util object, with the new db adapter
     $driver = $this->getDriver();
     $utilClass = '\\ZendTest\\DB\\TestUtil\\' . $driver;
     $util = new $utilClass();
     $util->setAdapter($db);
     // create test table using no identifier quoting
     $util->createTable('charsetutf8', array('id' => 'IDENTITY', 'stuff' => 'VARCHAR(32)'));
     $tableName = $this->_util->getTableName('charsetutf8');
     // insert into the table
     $numRows = $db->insert($tableName, array('id' => 1, 'stuff' => 'äöüß'));
     // check if the row was inserted as expected
     $select = $db->select()->from($tableName, array('id', 'stuff'));
     $stmt = $db->query($select);
     $fetched = $stmt->fetchAll(DB\DB::FETCH_NUM);
     $a = array(0 => array(0 => 1, 1 => 'äöüß'));
     $this->assertEquals($a, $fetched, 'result of query not as expected');
     // clean up
     unset($stmt);
     $util->dropTable($tableName);
 }
Exemplo n.º 7
0
 /**
  * Initialize DB adapter using 'driverOptions' section of the _options array
  *
  * Throws an exception if the adapter cannot connect to DB.
  *
  * @return \Zend\DB\Adapter\AbstractAdapter
  * @throws \Zend\Queue\Exception
  */
 protected function _initDBAdapter()
 {
     $options =& $this->_options['driverOptions'];
     if (!array_key_exists('type', $options)) {
         throw new Queue\Exception("Configuration array must have a key for 'type' for the database type to use");
     }
     if (!array_key_exists('host', $options)) {
         throw new Queue\Exception("Configuration array must have a key for 'host' for the host to use");
     }
     if (!array_key_exists('username', $options)) {
         throw new Queue\Exception("Configuration array must have a key for 'username' for the username to use");
     }
     if (!array_key_exists('password', $options)) {
         throw new Queue\Exception("Configuration array must have a key for 'password' for the password to use");
     }
     if (!array_key_exists('dbname', $options)) {
         throw new Queue\Exception("Configuration array must have a key for 'dbname' for the database to use");
     }
     $type = $options['type'];
     unset($options['type']);
     try {
         $db = DB_ns\DB::factory($type, $options);
     } catch (DB_ns\Exception $e) {
         throw new Queue\Exception('Error connecting to database: ' . $e->getMessage(), $e->getCode(), $e);
     }
     return $db;
 }
Exemplo n.º 8
0
 /**
  * Sets up the database connection and creates the table for session data
  *
  * @param  array $primary
  * @return void
  */
 protected function _setupDb(array $primary)
 {
     if (!extension_loaded('pdo_sqlite')) {
         $this->markTestSkipped('The pdo_sqlite extension must be available and enabled for this test');
     }
     $this->_db = DB::factory('PDO\\SQLite', array('dbname' => ':memory:'));
     AbstractTable::setDefaultAdapter($this->_db);
     $query = array();
     $query[] = 'CREATE TABLE `Sessions` ( ';
     $query[] = '`id` varchar(32) NOT NULL, ';
     if (in_array('save_path', $primary)) {
         $query[] = '`save_path` varchar(32) NOT NULL, ';
     }
     if (in_array('name', $primary)) {
         $query[] = '`name` varchar(32) NOT NULL, ';
     }
     $query[] = '`modified` int(11) default NULL, ';
     $query[] = '`lifetime` int(11) default NULL, ';
     $query[] = '`data` text, ';
     $query[] = 'PRIMARY KEY  (' . implode(', ', $primary) . ') ';
     $query[] = ');';
     $this->_db->query(implode("\n", $query));
 }
Exemplo n.º 9
0
 /**
  * Ensures that the PDO Buffered Query does not throw the error
  * 2014 General error
  *
  * @link   http://framework.zend.com/issues/browse/ZF-2101
  * @return void
  */
 public function testZF2101()
 {
     $params = $this->_util->getParams();
     $params['driver_options'] = array(\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true);
     $db = DB\DB::factory($this->getDriver(), $params);
     // Set default bound value
     $customerId = 1;
     // Stored procedure returns a single row
     $stmt = $db->prepare('CALL zf_test_procedure(:customerId)');
     $stmt->bindParam('customerId', $customerId, \PDO::PARAM_INT);
     $stmt->execute();
     $result = $stmt->fetchAll();
     $this->assertEquals(1, $result[0]['product_id']);
     // Reset statement
     $stmt->closeCursor();
     // Stored procedure returns a single row
     $stmt = $db->prepare('CALL zf_test_procedure(:customerId)');
     $stmt->bindParam('customerId', $customerId, \PDO::PARAM_INT);
     $stmt->execute();
     $result = $stmt->fetchAll();
     $this->assertEquals(1, $result[0]['product_id']);
 }
Exemplo n.º 10
0
 public function testMySqliInitCommand()
 {
     $params = $this->_util->getParams();
     $params['driver_options'] = array('mysqli_init_command' => 'SET AUTOCOMMIT=0;');
     $db = DB\DB::factory($this->getDriver(), $params);
     $sql = 'SELECT @@AUTOCOMMIT as autocommit';
     $row = $db->fetchRow($sql);
     $this->assertEquals(0, $row['autocommit']);
 }
Exemplo n.º 11
0
Arquivo: Db2Test.php Projeto: hjr3/zf2
 /**
  * This is "related" to the issue.  It appears the fix for
  * describeTable is relatively untestable due to the fact that
  * its primary focus is to reduce the query time, not the result
  * set.
  *
  * @group ZF-5169
  */
 public function testAdapterSchemaOptionInListTables()
 {
     $params = $this->_util->getParams();
     unset($params['schema']);
     $connection = DB\DB::factory($this->getDriver(), $params);
     $tableCountNoSchema = count($connection->listTables());
     $dbConfig = $this->_db->getConfig();
     if ($this->_db->isI5()) {
         if (isset($dbConfig['driver_options']['i5_lib'])) {
             $schema = $dbConfig['driver_options']['i5_lib'];
         }
     } elseif (!$this->_db->isI5()) {
         $schema = $this->_util->getSchema();
     } else {
         $this->markTestSkipped('No valid schema to test against.');
         return;
     }
     $params = $this->_util->getParams();
     $params['schema'] = $schema;
     $connection = DB\DB::factory($this->getDriver(), $params);
     $tableCountSchema = count($connection->listTables());
     $this->assertGreaterThan(0, $tableCountNoSchema, 'Adapter without schema should produce large result');
     $this->assertGreaterThan(0, $tableCountSchema, 'Adapter with schema should produce large result');
     $this->assertTrue($tableCountNoSchema > $tableCountSchema, 'Table count with schema provided should be less than without.');
 }
Exemplo n.º 12
0
 /**
  * Ensures that a provided instance overrides a class definition
  *
  * @return void
  */
 public function testProfilerFactoryInstanceOverridesClass()
 {
     $profiler = new \Zend_Db_Profiler_ProfilerCustom();
     $db = DB\DB::factory('Static', array('dbname' => 'dummy', 'profiler' => array('instance' => $profiler, 'class' => 'stdClass')));
     $this->assertType('Zend_Db_Adapter_Abstract', $db, 'Expected object of type Zend_Db_Adapter_Abstract, got ' . get_class($db));
     $profiler2 = $db->getProfiler();
     $this->assertSame($profiler, $profiler2);
     $this->assertFalse($profiler->getEnabled());
 }
Exemplo n.º 13
0
 /**
  * @group ZF-7924
  */
 public function testDbFactoryWillLoadCaseInsensitiveAdapterName()
 {
     $this->markTestSkipped('Invalid due to autoload requirement.');
     try {
         $adapter = DB\DB::factory('DB_ADAPTER', array('dbname' => 'dummy', 'adapterNamespace' => '\\ZendTest\\DB\\Adapter\\TestAsset\\Test\\MyCompany1'));
     } catch (\Exception $e) {
         $this->fail('Could not load file for reason: ' . $e->getMessage());
     }
     $this->assertEquals('\\ZendTest\\DB\\Adapter\\TestAsset\\Test\\MyCompany1\\Db\\Adapter', get_class($adapter));
 }