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