Commit 33605b7d authored by Ivan Chepurnyi's avatar Ivan Chepurnyi

! Vfs fix

parent d1015750
......@@ -720,7 +720,7 @@ class EcomDev_PHPUnit_Model_Fixture
return $this->_vfs;
}
if (is_dir(Mage::getBaseDir('lib') . DS . 'vfsStream' . DS . 'main')) {
if (is_dir(Mage::getBaseDir('lib') . DS . 'vfsStream' . DS . 'src')) {
spl_autoload_register(array($this, 'vfsAutoload'), true, true);
$this->_vfs = Mage::getModel('ecomdev_phpunit/fixture_vfs');
return $this->_vfs;
......@@ -740,12 +740,11 @@ class EcomDev_PHPUnit_Model_Fixture
*/
public function vfsAutoload($className)
{
if (strpos($className, 'vfs') !== 0) {
if (strpos($className, 'org\\bovigo\\vfs') === false) {
return false;
}
$fileName = 'vfsStream' . DS . 'src'
. DS . 'main' . DS . 'php' . DS
$fileName = 'vfsStream' . DS . 'src' . DS . 'main' . DS . 'php' . DS
. strtr(trim($className, '\\'), '\\', DS) . '.php';
return include $fileName;
......
......@@ -19,6 +19,8 @@
class EcomDev_PHPUnit_Model_Fixture_Processor_Vfs implements EcomDev_PHPUnit_Model_Fixture_Processor_Interface
{
const STORAGE_KEY = 'vfs';
/**
* Does nothing
*
......@@ -41,7 +43,15 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Vfs implements EcomDev_PHPUnit_Mod
*/
public function apply(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
{
$fixture->getVfs()->apply($data, $fixture->isScopeLocal());
if ($fixture->isScopeLocal()
&& ($parentData = $fixture->getStorageData(self::STORAGE_KEY,
EcomDev_PHPUnit_Model_Fixture_Interface::SCOPE_SHARED))) {
$data = array_merge_recursive($parentData, $data);
}
$fixture->getVfs()->apply($data);
$fixture->setStorageData(self::STORAGE_KEY, $data);
return $this;
}
......@@ -57,6 +67,7 @@ class EcomDev_PHPUnit_Model_Fixture_Processor_Vfs implements EcomDev_PHPUnit_Mod
public function discard(array $data, $key, EcomDev_PHPUnit_Model_Fixture_Interface $fixture)
{
$fixture->getVfs()->discard();
$fixture->setStorageData(self::STORAGE_KEY, null);
return $this;
}
}
\ No newline at end of file
......@@ -17,6 +17,7 @@
*/
use org\bovigo\vfs\vfsStream as Stream;
use org\bovigo\vfs\vfsStreamDirectory as StreamDirectory;
use org\bovigo\vfs\vfsStreamWrapper as StreamWrapper;
use org\bovigo\vfs\visitor\vfsStreamStructureVisitor as StreamVisitor;
......@@ -30,7 +31,7 @@ class EcomDev_PHPUnit_Model_Fixture_Vfs
/**
* Current root directory stack of the VFS before apply process were started
*
* @var array
* @var StreamDirectory[]
*/
protected $_currentRoot = array();
......@@ -50,18 +51,9 @@ class EcomDev_PHPUnit_Model_Fixture_Vfs
*
* @return EcomDev_PHPUnit_Model_Fixture_Vfs
*/
public function apply($data, $cloneCurrent = false)
public function apply($data)
{
$this->_currentRoot[] = StreamWrapper::getRoot();
StreamWrapper::setRoot(Stream::newDirectory(uniqid('root')));
if ($cloneCurrent) {
$visitor = new StreamVisitor();
$visitor->visitDirectory(end($this->_currentRoot));
if ($visitor->getStructure()) {
Stream::create($visitor->getStructure());
}
}
Stream::create($data);
return $this;
}
......@@ -79,6 +71,23 @@ class EcomDev_PHPUnit_Model_Fixture_Vfs
return $this;
}
/**
* Dump current files structure
*
* @return array
*/
public function dump()
{
$currentRoot = StreamWrapper::getRoot();
if (!$currentRoot) {
return array();
}
$visitor = new StreamVisitor();
$visitor->visit($currentRoot);
return $visitor->getStructure();
}
/**
* Returns stream wrapper url for operation
* via built-in fs functions
......
......@@ -597,7 +597,6 @@ abstract class EcomDev_PHPUnit_Test_Case extends PHPUnit_Framework_TestCase
* Retrieves fixture model singleton
*
* @return EcomDev_PHPUnit_Model_Fixture
* @deprecated since 0.3.0
*/
protected static function getFixture()
{
......
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