From 0ed8142e4ffc2453135743c7d9923a85c1ec77fd Mon Sep 17 00:00:00 2001 From: Colin Mollenhour Date: Wed, 22 May 2013 17:23:12 -0400 Subject: [PATCH 1/4] Delete from tables in reverse order to avoid foreign key constraint errors. --- app/code/community/EcomDev/PHPUnit/Model/Fixture.php | 2 +- .../PHPUnit/Model/Fixture/Processor/Tables.php | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/app/code/community/EcomDev/PHPUnit/Model/Fixture.php b/app/code/community/EcomDev/PHPUnit/Model/Fixture.php index b5dd07dc..b00d8eea 100644 --- a/app/code/community/EcomDev/PHPUnit/Model/Fixture.php +++ b/app/code/community/EcomDev/PHPUnit/Model/Fixture.php @@ -389,7 +389,7 @@ protected function _loadFixtureFiles(array $fixtures, $classOrInstance) ->resolveFilePath($className, EcomDev_PHPUnit_Model_Yaml_Loader::TYPE_FIXTURE, $fixture); if (!$filePath) { - throw new RuntimeException('Unable to load fixture for test'); + throw new RuntimeException('Unable to load fixture for test: '.$fixture); } $this->loadYaml($filePath); diff --git a/app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Tables.php b/app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Tables.php index 10fa0ea3..a3929611 100644 --- a/app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Tables.php +++ b/app/code/community/EcomDev/PHPUnit/Model/Fixture/Processor/Tables.php @@ -66,11 +66,12 @@ public function apply(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface } $this->getResource()->beginTransaction(); - foreach ($data as $tableEntity => $tableData) { + foreach (array_reverse(array_keys($data)) as $tableEntity) { if (!in_array($tableEntity, $ignoreCleanUp)) { $this->getResource()->cleanTable($tableEntity); } - + } + foreach ($data as $tableEntity => $tableData) { if (!empty($tableData)) { $this->getResource()->loadTableData($tableEntity, $tableData); } @@ -102,9 +103,10 @@ public function discard(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interfa } $this->getResource()->beginTransaction(); - foreach (array_keys($data) as $tableEntity) { + foreach (array_reverse(array_keys($data)) as $tableEntity) { $this->getResource()->cleanTable($tableEntity); - + } + foreach (array_keys($data) as $tableEntity) { if (isset($restoreTableData[$tableEntity])) { $this->getResource()->loadTableData($tableEntity, $restoreTableData[$tableEntity]); } @@ -114,4 +116,4 @@ public function discard(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interfa $fixture->setStorageData(self::STORAGE_KEY, null); return $this; } -} \ No newline at end of file +} From bb476f1c50658cde14340db72cfa64e6816aa59f Mon Sep 17 00:00:00 2001 From: Colin Mollenhour Date: Wed, 22 May 2013 18:23:07 -0400 Subject: [PATCH 2/4] Fix using tables in fixtures that don't have entity configs. --- app/code/community/EcomDev/PHPUnit/Model/Mysql4/Fixture.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/app/code/community/EcomDev/PHPUnit/Model/Mysql4/Fixture.php b/app/code/community/EcomDev/PHPUnit/Model/Mysql4/Fixture.php index d10834c4..68c61fe1 100644 --- a/app/code/community/EcomDev/PHPUnit/Model/Mysql4/Fixture.php +++ b/app/code/community/EcomDev/PHPUnit/Model/Mysql4/Fixture.php @@ -27,6 +27,7 @@ class EcomDev_PHPUnit_Model_Mysql4_Fixture extends Mage_Core_Model_Mysql4_Abstra protected function _construct() { $this->_setResource('ecomdev_phpunit'); + $this->_resourceModel = NULL; } /** @@ -131,4 +132,4 @@ protected function _getTableRecordValue($value) throw new InvalidArgumentException('Unrecognized type for DB column'); } -} \ No newline at end of file +} From fba074625d52a1aeb5d3b0d7bf69be609ae0d3d7 Mon Sep 17 00:00:00 2001 From: Colin Mollenhour Date: Wed, 22 May 2013 18:34:42 -0400 Subject: [PATCH 3/4] Make error messages more helpful for debugging. --- app/code/community/EcomDev/PHPUnit/Model/Mysql4/Fixture.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/community/EcomDev/PHPUnit/Model/Mysql4/Fixture.php b/app/code/community/EcomDev/PHPUnit/Model/Mysql4/Fixture.php index 68c61fe1..f3ca3c7a 100644 --- a/app/code/community/EcomDev/PHPUnit/Model/Mysql4/Fixture.php +++ b/app/code/community/EcomDev/PHPUnit/Model/Mysql4/Fixture.php @@ -130,6 +130,6 @@ protected function _getTableRecordValue($value) return serialize($value['serialized']); } - throw new InvalidArgumentException('Unrecognized type for DB column'); + throw new InvalidArgumentException('Unrecognized type for DB column: '.print_r($value, 1)); } } From 59d0ccaf76fc308ee93b11271b3110f3a6036674 Mon Sep 17 00:00:00 2001 From: Colin Mollenhour Date: Thu, 23 May 2013 11:41:38 -0400 Subject: [PATCH 4/4] Prevent fatal error when indexer is not present. --- .../PHPUnit/Model/Mysql4/Fixture/Eav/Abstract.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/app/code/community/EcomDev/PHPUnit/Model/Mysql4/Fixture/Eav/Abstract.php b/app/code/community/EcomDev/PHPUnit/Model/Mysql4/Fixture/Eav/Abstract.php index 4f547ca7..c767258d 100644 --- a/app/code/community/EcomDev/PHPUnit/Model/Mysql4/Fixture/Eav/Abstract.php +++ b/app/code/community/EcomDev/PHPUnit/Model/Mysql4/Fixture/Eav/Abstract.php @@ -57,10 +57,11 @@ public function runRequiredIndexers() if (empty($this->_options['doNotIndexAll'])) { $indexer = Mage::getSingleton('index/indexer'); foreach ($this->getRequiredIndexers() as $indexerCode) { - if (empty($this->_options['doNotIndex']) - || !in_array($indexerCode, $this->_options['doNotIndex'])) { - $indexer->getProcessByCode($indexerCode) - ->reindexAll(); + if (empty($this->_options['doNotIndex']) || !in_array($indexerCode, $this->_options['doNotIndex'])) { + $process = $indexer->getProcessByCode($indexerCode); + if ($process) { + $process->reindexAll(); + } } } }