Commit 4fb73ae6 authored by Ivan Chepurnyi's avatar Ivan Chepurnyi

! Fixed issue #36

parent 350ca36f
...@@ -50,11 +50,71 @@ class EcomDev_PHPUnit_Model_Mysql4_Fixture extends Mage_Core_Model_Mysql4_Abstra ...@@ -50,11 +50,71 @@ class EcomDev_PHPUnit_Model_Mysql4_Fixture extends Mage_Core_Model_Mysql4_Abstra
*/ */
public function loadTableData($tableEntity, $tableData) public function loadTableData($tableEntity, $tableData)
{ {
$tableColumns = $this->_getWriteAdapter()
->describeTable($this->getTable($tableEntity));
$records = array();
foreach ($tableData as $row) {
$records[] = $this->_getTableRecord($row, $tableColumns);
}
$this->_getWriteAdapter()->insertMultiple( $this->_getWriteAdapter()->insertMultiple(
$this->getTable($tableEntity), $this->getTable($tableEntity),
$tableData $records
); );
return $this; return $this;
} }
/**
* Prepares entity table record from array
*
* @param array $row
* @param array $tableColumns list of entity_table columns
* @return array
*/
protected function _getTableRecord($row, $tableColumns)
{
$record = array();
// Fullfil table records with data
foreach ($tableColumns as $columnName => $definition) {
if (isset($row[$columnName])) {
$record[$columnName] = $this->_getTableRecordValue($row[$columnName]);
} elseif ($definition['DEFAULT'] !== null) {
$record[$columnName] = $definition['DEFAULT'];
} else {
$record[$columnName] = (($definition['NULLABLE']) ? null : '');
}
}
return $record;
}
/**
* Processes table record values,
* used for transforming custom values like serialized
* or JSON data
*
*
* @param mixed $value
* @return string
*/
protected function _getTableRecordValue($value)
{
// If it is scalar php type, then just return itself
if (!is_array($value)) {
return $value;
}
if (isset($value['json'])) {
return Mage::helper('core')->jsonEncode($value['json']);
}
if (isset($value['serialized'])) {
return serialize($value['serialized']);
}
throw new InvalidArgumentException('Unrecognized type for DB column');
}
} }
\ No newline at end of file
...@@ -266,31 +266,6 @@ abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract extends EcomDev ...@@ -266,31 +266,6 @@ abstract class EcomDev_PHPUnit_Model_Mysql4_Fixture_Eav_Abstract extends EcomDev
} }
/**
* Prepares entity table record from array
*
* @param array $row
* @param array $tableColumns list of entity_table columns
* @return array
*/
protected function _getTableRecord($row, $tableColumns)
{
$record = array();
// Fullfil table records with data
foreach ($tableColumns as $columnName => $definition) {
if (isset($row[$columnName])) {
$record[$columnName] = $row[$columnName];
} elseif ($definition['DEFAULT'] !== null) {
$record[$columnName] = $definition['DEFAULT'];
} else {
$record[$columnName] = (($definition['NULLABLE']) ? null : '');
}
}
return $record;
}
/** /**
* Retrieves attribute records for single entity * Retrieves attribute records for single entity
* *
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org> * @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/ */
/** /**
* Test suite for Magento * Test suite for Magento
* *
...@@ -29,6 +30,7 @@ class EcomDev_PHPUnit_Test_Suite extends PHPUnit_Framework_TestSuite ...@@ -29,6 +30,7 @@ class EcomDev_PHPUnit_Test_Suite extends PHPUnit_Framework_TestSuite
const XML_PATH_UNIT_TEST_GROUPS = 'phpunit/suite/groups'; const XML_PATH_UNIT_TEST_GROUPS = 'phpunit/suite/groups';
const XML_PATH_UNIT_TEST_MODULES = 'phpunit/suite/modules'; const XML_PATH_UNIT_TEST_MODULES = 'phpunit/suite/modules';
const XML_PATH_UNIT_TEST_APP = 'phpunit/suite/app'; const XML_PATH_UNIT_TEST_APP = 'phpunit/suite/app';
const XML_PATH_UNIT_TEST_SUITE = 'phpunit/suite/test_suite';
const CACHE_TAG = 'ECOMDEV_PHPUNIT'; const CACHE_TAG = 'ECOMDEV_PHPUNIT';
const CACHE_TYPE = 'ecomdev_phpunit'; const CACHE_TYPE = 'ecomdev_phpunit';
...@@ -71,7 +73,14 @@ class EcomDev_PHPUnit_Test_Suite extends PHPUnit_Framework_TestSuite ...@@ -71,7 +73,14 @@ class EcomDev_PHPUnit_Test_Suite extends PHPUnit_Framework_TestSuite
{ {
$groups = Mage::getConfig()->getNode(self::XML_PATH_UNIT_TEST_GROUPS); $groups = Mage::getConfig()->getNode(self::XML_PATH_UNIT_TEST_GROUPS);
$modules = Mage::getConfig()->getNode(self::XML_PATH_UNIT_TEST_MODULES); $modules = Mage::getConfig()->getNode(self::XML_PATH_UNIT_TEST_MODULES);
$testSuiteClass = EcomDev_Utils_Reflection::getRelflection((string) Mage::getConfig()->getNode(self::XML_PATH_UNIT_TEST_SUITE));
if (!$testSuiteClass->isSubclassOf('EcomDev_PHPUnit_Test_Suite_Group')) {
new RuntimeException('Test Suite class should be extended from EcomDev_PHPUnit_Test_Suite_Group');
}
$suite = new self('Magento Test Suite'); $suite = new self('Magento Test Suite');
// Walk through different groups in modules for finding test cases // Walk through different groups in modules for finding test cases
foreach ($groups->children() as $group) { foreach ($groups->children() as $group) {
foreach ($modules->children() as $module) { foreach ($modules->children() as $module) {
...@@ -96,8 +105,7 @@ class EcomDev_PHPUnit_Test_Suite extends PHPUnit_Framework_TestSuite ...@@ -96,8 +105,7 @@ class EcomDev_PHPUnit_Test_Suite extends PHPUnit_Framework_TestSuite
$testCases = self::_loadTestCases($searchPath, $moduleCodeDir); $testCases = self::_loadTestCases($searchPath, $moduleCodeDir);
foreach ($testCases as $className) { foreach ($testCases as $className) {
$classReflection = EcomDev_Utils_Reflection::getRelflection($className); $suite->addTest($testSuiteClass->newInstance($className, $currentGroups));
$suite->addTest(new PHPUnit_Framework_TestSuite($classReflection), $currentGroups);
} }
} }
} }
......
...@@ -51,6 +51,8 @@ ...@@ -51,6 +51,8 @@
<helpers>Helper</helpers> <helpers>Helper</helpers>
<blocks>Block</blocks> <blocks>Block</blocks>
</groups> </groups>
<!-- Test suite that will be used for creation of each of the tests -->
<test_suite>EcomDev_PHPUnit_Test_Suite_Group</test_suite>
<fixture> <fixture>
<eav> <eav>
<!-- Here goes the list of fixture loaders for EAV <!-- Here goes the list of fixture loaders for EAV
......
...@@ -67,7 +67,7 @@ class EcomDev_Utils_Reflection ...@@ -67,7 +67,7 @@ class EcomDev_Utils_Reflection
$reflectionMethod->setAccessible(true); $reflectionMethod->setAccessible(true);
if (!empty($args)) { if (!empty($args)) {
return $reflectionMethod->invokeArgs($reflectionObject, $args); return $reflectionMethod->invokeArgs((is_string($object) ? null : $object), $args);
} }
return $reflectionMethod->invoke((is_string($object) ? null : $object)); return $reflectionMethod->invoke((is_string($object) ? null : $object));
...@@ -96,7 +96,7 @@ class EcomDev_Utils_Reflection ...@@ -96,7 +96,7 @@ class EcomDev_Utils_Reflection
if (isset(self::$_reflectionCache[$objectHash])) { if (isset(self::$_reflectionCache[$objectHash])) {
return self::$_reflectionCache[$objectHash]; return self::$_reflectionCache[$objectHash];
} }
$reflection = new ReflectionClass($object); $reflection = new ReflectionObject($object);
self::$_reflectionCache[$objectHash] = $reflection; self::$_reflectionCache[$objectHash] = $reflection;
return $reflection; return $reflection;
} }
......
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