Commit c8821f04 authored by Ivan Chepurnyi's avatar Ivan Chepurnyi

Refactor unit tests for db info retrieval

parent 02690886
......@@ -8,7 +8,6 @@ class EcomDev_PHPUnit_Model_Mysql4_Db_Info implements EcomDev_PHPUnit_Model_Mysq
/** @var array Information about the magento database [table => [...]]. */
protected $_information;
/**
* Before fetching information about a table.
*
......@@ -22,25 +21,30 @@ class EcomDev_PHPUnit_Model_Mysql4_Db_Info implements EcomDev_PHPUnit_Model_Mysq
// iterate over each available table
$listTables = $this->getAdapter()->listTables();
foreach ($listTables as $tableName)
{
foreach ($listTables as $tableName) {
// describe the table
$data = new Varien_Object();
$data->setData($this->getAdapter()->describeTable($tableName));
$columns = array();
foreach ($this->getAdapter()->describeTable($tableName) as $column => $info) {
$columns[$column]['type'] = $info['DATA_TYPE'];
$columns[$column]['length'] = $info['LENGTH'];
$columns[$column]['unsigned'] = (bool)$info['UNSIGNED'];
$columns[$column]['primary'] = (bool)$info['PRIMARY'];
$columns[$column]['default'] = $info['DEFAULT'];
}
$data->setColumns($columns);
$foreignKeys = $this->getAdapter()->getForeignKeys($tableName);
$dependency = array();
if (is_array($foreignKeys))
{
if (is_array($foreignKeys)) {
// add each depending table
foreach ($foreignKeys as $keyData)
{
foreach ($foreignKeys as $keyData) {
$dependency[] = $keyData['REF_TABLE_NAME'];
}
}
$data->setDependencies($dependency);
$this->_information[$tableName] = $data;
}
......@@ -102,9 +106,8 @@ class EcomDev_PHPUnit_Model_Mysql4_Db_Info implements EcomDev_PHPUnit_Model_Mysq
*/
public function setAdapter($adapter)
{
if (!($adapter instanceof Zend_Db_Adapter_Abstract))
{
throw new InvalidArgumentException('Unsupported adapter ' . get_class($adapter));
if (!($adapter instanceof Zend_Db_Adapter_Abstract)) {
throw new InvalidArgumentException('Adapter should be an instance of Zend_Db_Adapter_Abstract');
}
$this->_adapter = $adapter;
......
-
- child:
columns:
child_id:
SCHEMA_NAME: test
TABLE_NAME: child
COLUMN_NAME: child_id
COLUMN_POSITION: 0
DATA_TYPE: int
DEFAULT: ''
LENGTH: 10
UNSIGNED: true
PRIMARY: true
PRIMARY_POSITION: 0
IDENTITY: true
parent_id:
SCHEMA_NAME: test
TABLE_NAME: child
COLUMN_NAME: parent_id
COLUMN_POSITION: 0
DATA_TYPE: int
DEFAULT: ''
LENGTH: 10
UNSIGNED: true
PRIMARY: false
PRIMARY_POSITION: 0
IDENTITY: false
foreign_keys:
fk_mother:
FK_NAME: fk_mother
SCHEMA_NAME: test
TABLE_NAME: child
COLUMN_NAME: parent_id
REF_SHEMA_NAME: test
REF_TABLE_NAME: mother
REF_COLUMN_NAME: mother_id
ON_DELETE: ''
ON_UPDATE: ''
mother:
columns:
mother_id:
SCHEMA_NAME: test
TABLE_NAME: mother
COLUMN_NAME: mother_id
COLUMN_POSITION: 0
DATA_TYPE: int
DEFAULT: ''
LENGTH: 10
UNSIGNED: true
PRIMARY: true
PRIMARY_POSITION: 0
IDENTITY: true
name:
SCHEMA_NAME: test
TABLE_NAME: mother
COLUMN_NAME: name
COLUMN_POSITION: 0
DATA_TYPE: varchar
DEFAULT: ''
LENGTH: 255
UNSIGNED: false
PRIMARY: false
PRIMARY_POSITION: 0
IDENTITY: false
foreign_keys: [ ]
\ No newline at end of file
tables:
mother:
columns:
mother_id:
type: int
length: 10
unsigned: true
primary: true
default: ''
name:
type: varchar
length: 255
unsigned: false
primary: false
default: ''
dependencies: []
child:
columns:
child_id:
type: int
length: 10
unsigned: true
primary: true
default: ''
parent_id:
type: int
length: 10
unsigned: true
primary: false
default: ''
dependencies:
- mother
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment