Commit 181305ac authored by Ivan Chepurnyi's avatar Ivan Chepurnyi

! New fx/dp/ex prefixes for test case fixtures/providers/expectations

parent 20b9f742
...@@ -18,6 +18,14 @@ ...@@ -18,6 +18,14 @@
abstract class EcomDev_PHPUnit_Model_Yaml_Loader_Abstract implements EcomDev_PHPUnit_Model_Yaml_Loader_Interface abstract class EcomDev_PHPUnit_Model_Yaml_Loader_Abstract implements EcomDev_PHPUnit_Model_Yaml_Loader_Interface
{ {
const DATA_DIR = '_data';
protected $_typeMap = array(
'fixtures' => 'fx',
'providers' => 'dp',
'expectations' => 'ex'
);
/** /**
* Resolves YAML file path based on its filename, * Resolves YAML file path based on its filename,
* if file is not found, it should return false * if file is not found, it should return false
...@@ -51,4 +59,36 @@ abstract class EcomDev_PHPUnit_Model_Yaml_Loader_Abstract implements EcomDev_PHP ...@@ -51,4 +59,36 @@ abstract class EcomDev_PHPUnit_Model_Yaml_Loader_Abstract implements EcomDev_PHP
* @return string * @return string
*/ */
abstract protected function _getFilePath($fileName, $relatedClassName, $type); abstract protected function _getFilePath($fileName, $relatedClassName, $type);
}
\ No newline at end of file /**
* Looks in path for possible existent fixture
*
* @param string|array $path
* @param string $fileName
* @param string $type
* @return bool|string
*/
protected function _checkFilePath($path, $fileName, $type)
{
if (is_array($path)) {
foreach ($path as $value) {
if ($filePath = $this->_checkFilePath($value, $fileName, $type)) {
return $filePath;
}
}
return false;
}
if (isset($this->_typeMap[$type])
&& file_exists($filePath = $path . DS . self::DATA_DIR . DS . $this->_typeMap[$type] . '-' . $fileName)) {
return $filePath;
}
if (file_exists($filePath = $path . DS . $type . DS . $fileName)) {
return $filePath;
}
return false;
}
}
...@@ -30,6 +30,11 @@ class EcomDev_PHPUnit_Model_Yaml_Loader_Default extends EcomDev_PHPUnit_Model_Ya ...@@ -30,6 +30,11 @@ class EcomDev_PHPUnit_Model_Yaml_Loader_Default extends EcomDev_PHPUnit_Model_Ya
{ {
$reflection = EcomDev_Utils_Reflection::getReflection($relatedClassName); $reflection = EcomDev_Utils_Reflection::getReflection($relatedClassName);
$fileObject = new SplFileInfo($reflection->getFileName()); $fileObject = new SplFileInfo($reflection->getFileName());
return $fileObject->getPath() . DS . $fileObject->getBasename('.php') . DS . $type . DS . $fileName;
return $this->_checkFilePath(array(
$fileObject->getPath(),
$fileObject->getPath() . DS . $fileObject->getBasename('.php')
), $fileName, $type);
} }
} }
\ No newline at end of file
...@@ -28,7 +28,8 @@ class EcomDev_PHPUnit_Model_Yaml_Loader_Module extends EcomDev_PHPUnit_Model_Yam ...@@ -28,7 +28,8 @@ class EcomDev_PHPUnit_Model_Yaml_Loader_Module extends EcomDev_PHPUnit_Model_Yam
*/ */
protected function _getFilePath($fileName, $relatedClassName, $type) protected function _getFilePath($fileName, $relatedClassName, $type)
{ {
$moduleName = EcomDev_PHPUnit_Test_Case_Util::getModuleNameByClassName($relatedClassName); $moduleName = false;
if (preg_match('#^~(?<module>[^/]*)/(?<fileName>.*)$#', $fileName, $matches)) { if (preg_match('#^~(?<module>[^/]*)/(?<fileName>.*)$#', $fileName, $matches)) {
$fileName = $matches['fileName']; $fileName = $matches['fileName'];
if(!empty($matches['module'])) { if(!empty($matches['module'])) {
...@@ -36,7 +37,23 @@ class EcomDev_PHPUnit_Model_Yaml_Loader_Module extends EcomDev_PHPUnit_Model_Yam ...@@ -36,7 +37,23 @@ class EcomDev_PHPUnit_Model_Yaml_Loader_Module extends EcomDev_PHPUnit_Model_Yam
} }
} }
$filePath = Mage::getModuleDir('', $moduleName) . DS . 'Test' . DS . $type . DS . $fileName; if (!$moduleName) {
return false; try {
$moduleName = EcomDev_PHPUnit_Test_Case_Util::getModuleNameByClassName($relatedClassName);
} catch (RuntimeException $e) {
return false;
}
}
$basePath = array();
if ($prefixPosition = strpos($relatedClassName, $moduleName . '_Test_')) {
$testType = substr($relatedClassName, $prefixPosition, strpos($relatedClassName, '_', $prefixPosition));
$basePath[] = Mage::getModuleDir('', $moduleName) . DS . 'Test' . DS . $testType;
}
$basePath[] = Mage::getModuleDir('', $moduleName) . DS . 'Test';
return $this->_checkFilePath($basePath, $fileName, $type);
} }
} }
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