Commit cdfc200a authored by Ivan Chepurnyi's avatar Ivan Chepurnyi

Fix VFS file stream and improve bootstrap process of EcomDev PHPUnit extension

parent 271a7c30
{
"require": {
"ecomdev/mage-ci": "*"
"ecomdev/mage-ci": "*",
"mikey179/vfsStream": "*"
},
"config": {
"bin-dir": "bin"
......
......@@ -737,7 +737,8 @@ class EcomDev_PHPUnit_Model_Fixture
return $this->_vfs;
}
if (is_dir(Mage::getBaseDir('lib') . DS . 'vfsStream' . DS . 'src')) {
if (!class_exists('\org\bovigo\vfs\vfsStream')
&& is_dir(Mage::getBaseDir('lib') . DS . 'vfsStream' . DS . 'src')) {
spl_autoload_register(array($this, 'vfsAutoload'), true, true);
}
......
......@@ -35,14 +35,6 @@ class EcomDev_PHPUnit_Model_Fixture_Vfs
*/
protected $_currentRoot = array();
/**
* Initializes VFS stream wrapper/
*/
public function __construct()
{
Stream::setup();
}
/**
* Applies VFS directory structure
*
......@@ -53,8 +45,10 @@ class EcomDev_PHPUnit_Model_Fixture_Vfs
*/
public function apply($data)
{
$this->_currentRoot[] = StreamWrapper::getRoot();
Stream::create($data);
if (StreamWrapper::getRoot()) {
$this->_currentRoot[] = StreamWrapper::getRoot();
}
Stream::setup('root', null, $data);
return $this;
}
......@@ -97,6 +91,10 @@ class EcomDev_PHPUnit_Model_Fixture_Vfs
*/
public function url($path)
{
if (strpos($path, StreamWrapper::getRoot()->getName()) === false) {
$path = StreamWrapper::getRoot()->getName() . '/' . $path;
}
return Stream::url($path);
}
}
......@@ -7,7 +7,6 @@ if (version_compare(PHP_VERSION, '5.3', '<')) {
$_baseDir = getcwd();
// Include Mage file by detecting app root
require_once $_baseDir . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Mage.php';
......@@ -29,13 +28,25 @@ if (!empty($_GET)) {
Mage::app('admin');
Mage::getConfig()->init();
// Removing Varien Autoload, to prevent errors with PHPUnit components
spl_autoload_unregister(array(\Varien_Autoload::instance(), 'autoload'));
spl_autoload_register(function ($classname) {
$classname = ltrim($classname, "\\");
preg_match('/^(.+)?([^\\\\]+)$/U', $classname, $match);
$classname = str_replace("\\", "/", $match[1])
. str_replace(array("\\", "_"), "/", $match[2])
. ".php";
@include_once $classname;
});
// It is possible to include custom bootstrap file by specifying env variable shell
// or in server
if (isset($_SERVER['ECOMDEV_PHPUNIT_CUSTOM_BOOTSTRAP'])) {
include $_SERVER['ECOMDEV_PHPUNIT_CUSTOM_BOOTSTRAP'];
}
if (!defined('ECOMDEV_PHPUNIT_NO_AUTOLOADER')) {
spl_autoload_register(function ($className) {
$filePath = strtr(
ltrim($className, '\\'),
array(
'\\' => '/',
'_' => '/'
)
);
@include $filePath . '.php';
});
}
......@@ -140,7 +140,6 @@ class EcomDev_PHPUnit_Constraint_Config_Resource_Script
)
);
if (!is_dir($directory)) {
return $versions;
}
......
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