Exemple #1
0
 public function testDbMysql()
 {
     require 'unit-tests/config.db.php';
     if (empty($configMysql)) {
         $this->markTestSkipped("Skipped");
         return;
     }
     $connection = new Phalcon\Db\Adapter\Pdo\Mysql($configMysql);
     //List tables
     $expectedTables = array('albums', 'artists', 'customers', 'issue_11036', 'issue_1534', 'issue_2019', 'm2m_parts', 'm2m_robots', 'm2m_robots_parts', 'parts', 'personas', 'personnes', 'prueba', 'robots', 'robots_parts', 'songs', 'subscriptores', 'tipo_documento');
     $tables = $connection->listTables();
     $this->assertEquals($tables, $expectedTables);
     $tables = $connection->listTables('phalcon_test');
     $this->assertEquals($tables, $expectedTables);
     //Table exist
     $this->assertEquals($connection->tableExists('personas'), 1);
     $this->assertEquals($connection->tableExists('noexist'), 0);
     $this->assertEquals($connection->tableExists('personas', 'phalcon_test'), 1);
     $this->assertEquals($connection->tableExists('personas', 'test'), 0);
     $expectedDescribe = $this->getExpectedColumnsMysql();
     $describe = $connection->describeColumns('personas');
     $this->assertEquals($describe, $expectedDescribe);
     $describe = $connection->describeColumns('personas', 'phalcon_test');
     $this->assertEquals($describe, $expectedDescribe);
     //Table Options
     $expectedOptions = array('table_type' => 'BASE TABLE', 'auto_increment' => NULL, 'engine' => 'InnoDB', 'table_collation' => 'utf8_unicode_ci');
     $options = $connection->tableOptions('personas', 'phalcon_test');
     $this->assertEquals($options, $expectedOptions);
     //Indexes
     $expectedIndexes = array('PRIMARY' => Phalcon\Db\Index::__set_state(array('_name' => 'PRIMARY', '_columns' => array('id'), '_type' => 'PRIMARY')), 'robots_id' => Phalcon\Db\Index::__set_state(array('_name' => 'robots_id', '_columns' => array('robots_id'))), 'parts_id' => Phalcon\Db\Index::__set_state(array('_name' => 'parts_id', '_columns' => array('parts_id'))));
     $describeIndexes = $connection->describeIndexes('robots_parts');
     $this->assertEquals($describeIndexes, $expectedIndexes);
     $describeIndexes = $connection->describeIndexes('robots_parts', 'phalcon_test');
     $this->assertEquals($describeIndexes, $expectedIndexes);
     //Indexes
     $expectedIndexes = array('PRIMARY' => Phalcon\Db\Index::__set_state(array('_name' => 'PRIMARY', '_columns' => array('id'), '_type' => 'PRIMARY')), 'issue_11036_token_UNIQUE' => Phalcon\Db\Index::__set_state(array('_name' => 'issue_11036_token_UNIQUE', '_columns' => array('token'), '_type' => 'UNIQUE')));
     $describeIndexes = $connection->describeIndexes('issue_11036');
     $this->assertEquals($describeIndexes, $expectedIndexes);
     $describeIndexes = $connection->describeIndexes('issue_11036', 'phalcon_test');
     $this->assertEquals($describeIndexes, $expectedIndexes);
     //References
     $expectedReferences = array('robots_parts_ibfk_1' => Phalcon\Db\Reference::__set_state(array('_referenceName' => 'robots_parts_ibfk_1', '_referencedTable' => 'robots', '_columns' => array('robots_id'), '_referencedColumns' => array('id'), '_referencedSchema' => 'phalcon_test')), 'robots_parts_ibfk_2' => Phalcon\Db\Reference::__set_state(array('_referenceName' => 'robots_parts_ibfk_2', '_referencedTable' => 'parts', '_columns' => array('parts_id'), '_referencedColumns' => array('id'), '_referencedSchema' => 'phalcon_test')));
     $describeReferences = $connection->describeReferences('robots_parts');
     $this->assertEquals($describeReferences, $expectedReferences);
     $describeReferences = $connection->describeReferences('robots_parts', 'phalcon_test');
     $this->assertEquals($describeReferences, $expectedReferences);
 }