We will work on Apr 26th (Saturday) and will be off from Apr 30th (Wednesday) until May 2nd (Friday) for public holiday in our country

Commit 0f3ea314 authored by Ivan Chepurnyi's avatar Ivan Chepurnyi

! Commit uncomitted VFS wrapper

parent 975e184b
<?php
/**
* PHP Unit test suite for Magento
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
*
* @category EcomDev
* @package EcomDev_PHPUnit
* @copyright Copyright (c) 2012 EcomDev BV (http://www.ecomdev.org)
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* @author Ivan Chepurnyi <ivan.chepurnyi@ecomdev.org>
*/
use org\bovigo\vfs\vfsStream as Stream;
use org\bovigo\vfs\vfsStreamWrapper as StreamWrapper;
use org\bovigo\vfs\visitor\vfsStreamStructureVisitor as StreamVisitor;
/**
* VFS library wrapper, to have simple api for manipulation with virtual fs
*
*
*/
class EcomDev_PHPUnit_Model_Fixture_Vfs
{
/**
* Current root directory stack of the VFS before apply process were started
*
* @var array
*/
protected $_currentRoot = array();
/**
* Initializes VFS stream wrapper/
*/
public function __construct()
{
Stream::setup();
}
/**
* Applies VFS directory structure
*
* @param $data
* @param bool $cloneCurrent
*
* @return EcomDev_PHPUnit_Model_Fixture_Vfs
*/
public function apply($data, $cloneCurrent = false)
{
$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;
}
/**
* Discards VFS file system changes
*
* @return EcomDev_PHPUnit_Model_Fixture_Vfs
*/
public function discard()
{
if ($this->_currentRoot) {
StreamWrapper::setRoot(array_pop($this->_currentRoot));
}
return $this;
}
/**
* Returns stream wrapper url for operation
* via built-in fs functions
*
* @param string $path
* @return string
*/
public function url($path)
{
return Stream::url($path);
}
}
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