Skip to content

Commit cdfc200

Browse files
committed
Fix VFS file stream and improve bootstrap process of EcomDev PHPUnit extension
1 parent 271a7c3 commit cdfc200

5 files changed

Lines changed: 32 additions & 22 deletions

File tree

.travis/composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
{
22
"require": {
3-
"ecomdev/mage-ci": "*"
3+
"ecomdev/mage-ci": "*",
4+
"mikey179/vfsStream": "*"
45
},
56
"config": {
67
"bin-dir": "bin"

app/code/community/EcomDev/PHPUnit/Model/Fixture.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -737,7 +737,8 @@ public function getVfs()
737737
return $this->_vfs;
738738
}
739739

740-
if (is_dir(Mage::getBaseDir('lib') . DS . 'vfsStream' . DS . 'src')) {
740+
if (!class_exists('\org\bovigo\vfs\vfsStream')
741+
&& is_dir(Mage::getBaseDir('lib') . DS . 'vfsStream' . DS . 'src')) {
741742
spl_autoload_register(array($this, 'vfsAutoload'), true, true);
742743
}
743744

app/code/community/EcomDev/PHPUnit/Model/Fixture/Vfs.php

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,6 @@ class EcomDev_PHPUnit_Model_Fixture_Vfs
3535
*/
3636
protected $_currentRoot = array();
3737

38-
/**
39-
* Initializes VFS stream wrapper/
40-
*/
41-
public function __construct()
42-
{
43-
Stream::setup();
44-
}
45-
4638
/**
4739
* Applies VFS directory structure
4840
*
@@ -53,8 +45,10 @@ public function __construct()
5345
*/
5446
public function apply($data)
5547
{
56-
$this->_currentRoot[] = StreamWrapper::getRoot();
57-
Stream::create($data);
48+
if (StreamWrapper::getRoot()) {
49+
$this->_currentRoot[] = StreamWrapper::getRoot();
50+
}
51+
Stream::setup('root', null, $data);
5852
return $this;
5953
}
6054

@@ -97,6 +91,10 @@ public function dump()
9791
*/
9892
public function url($path)
9993
{
94+
if (strpos($path, StreamWrapper::getRoot()->getName()) === false) {
95+
$path = StreamWrapper::getRoot()->getName() . '/' . $path;
96+
}
97+
10098
return Stream::url($path);
10199
}
102100
}

app/code/community/EcomDev/PHPUnit/bootstrap.php

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
$_baseDir = getcwd();
99

10-
1110
// Include Mage file by detecting app root
1211
require_once $_baseDir . DIRECTORY_SEPARATOR . 'app' . DIRECTORY_SEPARATOR . 'Mage.php';
1312

@@ -29,13 +28,25 @@
2928
Mage::app('admin');
3029
Mage::getConfig()->init();
3130

31+
// Removing Varien Autoload, to prevent errors with PHPUnit components
3232
spl_autoload_unregister(array(\Varien_Autoload::instance(), 'autoload'));
3333

34-
spl_autoload_register(function ($classname) {
35-
$classname = ltrim($classname, "\\");
36-
preg_match('/^(.+)?([^\\\\]+)$/U', $classname, $match);
37-
$classname = str_replace("\\", "/", $match[1])
38-
. str_replace(array("\\", "_"), "/", $match[2])
39-
. ".php";
40-
@include_once $classname;
41-
});
34+
// It is possible to include custom bootstrap file by specifying env variable shell
35+
// or in server
36+
if (isset($_SERVER['ECOMDEV_PHPUNIT_CUSTOM_BOOTSTRAP'])) {
37+
include $_SERVER['ECOMDEV_PHPUNIT_CUSTOM_BOOTSTRAP'];
38+
}
39+
40+
if (!defined('ECOMDEV_PHPUNIT_NO_AUTOLOADER')) {
41+
spl_autoload_register(function ($className) {
42+
$filePath = strtr(
43+
ltrim($className, '\\'),
44+
array(
45+
'\\' => '/',
46+
'_' => '/'
47+
)
48+
);
49+
50+
@include $filePath . '.php';
51+
});
52+
}

lib/EcomDev/PHPUnit/Constraint/Config/Resource/Script.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,6 @@ protected function parseVersions($directory)
140140
)
141141
);
142142

143-
144143
if (!is_dir($directory)) {
145144
return $versions;
146145
}

0 commit comments

Comments
 (0)