You are here

class vfsStreamWrapperRecordingProxy in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/proxy/vfsStreamWrapperRecordingProxy.php \org\bovigo\vfs\vfsStreamWrapperRecordingProxy

Stream wrapper to mock file system requests.

@since 0.10.0

Hierarchy

Expanded class hierarchy of vfsStreamWrapperRecordingProxy

File

vendor/mikey179/vfsStream/src/test/php/org/bovigo/vfs/proxy/vfsStreamWrapperRecordingProxy.php, line 16

Namespace

org\bovigo\vfs
View source
class vfsStreamWrapperRecordingProxy extends vfsStreamWrapper {

  /**
   * list of called methods for a stream
   *
   * @var  array
   */
  protected static $calledMethods = array();

  /**
   * currently opened path
   *
   * @var  string
   */
  protected $path;

  /**
   * records method call for given path
   *
   * @param  string  $method
   * @param  string  $path
   */
  protected static function recordMethodCall($method, $path) {
    if (isset(self::$calledMethods[$path]) === false) {
      self::$calledMethods[$path] = array();
    }
    self::$calledMethods[$path][] = $method;
  }

  /**
   * returns recorded method calls for given path
   *
   * @param   string         $path
   * @return  array<string>
   */
  public static function getMethodCalls($path) {
    if (isset(self::$calledMethods[$path]) === true) {
      return self::$calledMethods[$path];
    }
    return array();
  }

  /**
   * helper method for setting up vfsStream with the proxy
   *
   * @param   string              $rootDirName  optional  name of root directory
   * @param   int                 $permissions  optional  file permissions of root directory
   * @return  vfsStreamDirectory
   * @throws  vfsStreamException
   */
  public static function setup($rootDirName = 'root', $permissions = null) {
    self::$root = vfsStream::newDirectory($rootDirName, $permissions);
    if (true === self::$registered) {
      return self::$root;
    }
    if (@stream_wrapper_register(vfsStream::SCHEME, __CLASS__) === false) {
      throw new vfsStreamException('A handler has already been registered for the ' . vfsStream::SCHEME . ' protocol.');
    }
    self::$registered = true;
    return self::$root;
  }

  /**
   * open the stream
   *
   * @param   string  $path         the path to open
   * @param   string  $mode         mode for opening
   * @param   string  $options      options for opening
   * @param   string  $opened_path  full path that was actually opened
   * @return  bool
   */
  public function stream_open($path, $mode, $options, $opened_path) {
    $this->path = $path;
    self::recordMethodCall('stream_open', $this->path);
    return parent::stream_open($path, $mode, $options, $opened_path);
  }

  /**
   * closes the stream
   */
  public function stream_close() {
    self::recordMethodCall('stream_close', $this->path);
    return parent::stream_close();
  }

  /**
   * read the stream up to $count bytes
   *
   * @param   int     $count  amount of bytes to read
   * @return  string
   */
  public function stream_read($count) {
    self::recordMethodCall('stream_read', $this->path);
    return parent::stream_read($count);
  }

  /**
   * writes data into the stream
   *
   * @param   string  $data
   * @return  int     amount of bytes written
   */
  public function stream_write($data) {
    self::recordMethodCall('stream_write', $this->path);
    return parent::stream_write($data);
  }

  /**
   * checks whether stream is at end of file
   *
   * @return  bool
   */
  public function stream_eof() {
    self::recordMethodCall('stream_eof', $this->path);
    return parent::stream_eof();
  }

  /**
   * returns the current position of the stream
   *
   * @return  int
   */
  public function stream_tell() {
    self::recordMethodCall('stream_tell', $this->path);
    return parent::stream_tell();
  }

  /**
   * seeks to the given offset
   *
   * @param   int   $offset
   * @param   int   $whence
   * @return  bool
   */
  public function stream_seek($offset, $whence) {
    self::recordMethodCall('stream_seek', $this->path);
    return parent::stream_seek($offset, $whence);
  }

  /**
   * flushes unstored data into storage
   *
   * @return  bool
   */
  public function stream_flush() {
    self::recordMethodCall('stream_flush', $this->path);
    return parent::stream_flush();
  }

  /**
   * returns status of stream
   *
   * @return  array
   */
  public function stream_stat() {
    self::recordMethodCall('stream_stat', $this->path);
    return parent::stream_stat();
  }

  /**
   * retrieve the underlaying resource
   *
   * @param   int  $cast_as
   * @return  bool
   */
  public function stream_cast($cast_as) {
    self::recordMethodCall('stream_cast', $this->path);
    return parent::stream_cast($cast_as);
  }

  /**
   * set lock status for stream
   *
   * @param   int   $operation
   * @return  bool
   */
  public function stream_lock($operation) {
    self::recordMethodCall('stream_link', $this->path);
    return parent::stream_lock($operation);
  }

  /**
   * remove the data under the given path
   *
   * @param   string  $path
   * @return  bool
   */
  public function unlink($path) {
    self::recordMethodCall('unlink', $path);
    return parent::unlink($path);
  }

  /**
   * rename from one path to another
   *
   * @param   string  $path_from
   * @param   string  $path_to
   * @return  bool
   */
  public function rename($path_from, $path_to) {
    self::recordMethodCall('rename', $path_from);
    return parent::rename($path_from, $path_to);
  }

  /**
   * creates a new directory
   *
   * @param   string  $path
   * @param   int     $mode
   * @param   int     $options
   * @return  bool
   */
  public function mkdir($path, $mode, $options) {
    self::recordMethodCall('mkdir', $path);
    return parent::mkdir($path, $mode, $options);
  }

  /**
   * removes a directory
   *
   * @param   string  $path
   * @param   int     $options
   * @return  bool
   */
  public function rmdir($path, $options) {
    self::recordMethodCall('rmdir', $path);
    return parent::rmdir($path, $options);
  }

  /**
   * opens a directory
   *
   * @param   string  $path
   * @param   int     $options
   * @return  bool
   */
  public function dir_opendir($path, $options) {
    $this->path = $path;
    self::recordMethodCall('dir_opendir', $this->path);
    return parent::dir_opendir($path, $options);
  }

  /**
   * reads directory contents
   *
   * @return  string
   */
  public function dir_readdir() {
    self::recordMethodCall('dir_readdir', $this->path);
    return parent::dir_readdir();
  }

  /**
   * reset directory iteration
   *
   * @return  bool
   */
  public function dir_rewinddir() {
    self::recordMethodCall('dir_rewinddir', $this->path);
    return parent::dir_rewinddir();
  }

  /**
   * closes directory
   *
   * @return  bool
   */
  public function dir_closedir() {
    self::recordMethodCall('dir_closedir', $this->path);
    return parent::dir_closedir();
  }

  /**
   * returns status of url
   *
   * @param   string  $path   path of url to return status for
   * @param   int     $flags  flags set by the stream API
   * @return  array
   */
  public function url_stat($path, $flags) {
    self::recordMethodCall('url_stat', $path);
    return parent::url_stat($path, $flags);
  }

}

Members

Namesort descending Modifiers Type Description Overrides
vfsStreamWrapper::$content protected property shortcut to file container
vfsStreamWrapper::$dir protected property shortcut to directory container
vfsStreamWrapper::$dirIterator protected property shortcut to directory container iterator
vfsStreamWrapper::$mode protected property file mode: read only, write only, all
vfsStreamWrapper::$quota private static property disk space quota
vfsStreamWrapper::$registered protected static property switch whether class has already been registered as stream wrapper or not
vfsStreamWrapper::$root protected static property root content
vfsStreamWrapper::ALL constant file mode: read and write
vfsStreamWrapper::APPEND constant set file pointer to end, append new data
vfsStreamWrapper::calculateMode protected function calculates the file mode
vfsStreamWrapper::createFile private function creates a file at given path
vfsStreamWrapper::doPermChange private function executes given permission change when necessary rights allow such a change
vfsStreamWrapper::doUnlink protected function removes a path
vfsStreamWrapper::getContent protected function returns content for given path
vfsStreamWrapper::getContentOfType protected function returns content for given path but only when it is of given type
vfsStreamWrapper::getRoot public static function returns the root content
vfsStreamWrapper::isInRoot private function helper method to detect whether given path is in root path
vfsStreamWrapper::READ constant open file for reading
vfsStreamWrapper::READONLY constant file mode: read only
vfsStreamWrapper::register public static function method to register the stream wrapper
vfsStreamWrapper::resolvePath protected function helper method to resolve a path from /foo/bar/. to /foo/bar
vfsStreamWrapper::setQuota public static function sets quota for disk space
vfsStreamWrapper::setRoot public static function sets the root content
vfsStreamWrapper::splitPath protected function splits path into its dirname and the basename
vfsStreamWrapper::stream_metadata public function sets metadata like owner, user or permissions
vfsStreamWrapper::stream_set_option public function sets options on the stream
vfsStreamWrapper::stream_truncate public function truncates a file to a given length
vfsStreamWrapper::TRUNCATE constant truncate file
vfsStreamWrapper::unregister public static function Unregisters a previously registered URL wrapper for the vfs scheme. 1
vfsStreamWrapper::WRITE constant set file pointer to start, overwrite existing data
vfsStreamWrapper::WRITEONLY constant file mode: write only
vfsStreamWrapper::WRITE_NEW constant set file pointer to start, overwrite existing data; or create file if does not exist
vfsStreamWrapperRecordingProxy::$calledMethods protected static property list of called methods for a stream
vfsStreamWrapperRecordingProxy::$path protected property currently opened path
vfsStreamWrapperRecordingProxy::dir_closedir public function closes directory Overrides vfsStreamWrapper::dir_closedir
vfsStreamWrapperRecordingProxy::dir_opendir public function opens a directory Overrides vfsStreamWrapper::dir_opendir
vfsStreamWrapperRecordingProxy::dir_readdir public function reads directory contents Overrides vfsStreamWrapper::dir_readdir
vfsStreamWrapperRecordingProxy::dir_rewinddir public function reset directory iteration Overrides vfsStreamWrapper::dir_rewinddir
vfsStreamWrapperRecordingProxy::getMethodCalls public static function returns recorded method calls for given path
vfsStreamWrapperRecordingProxy::mkdir public function creates a new directory Overrides vfsStreamWrapper::mkdir
vfsStreamWrapperRecordingProxy::recordMethodCall protected static function records method call for given path
vfsStreamWrapperRecordingProxy::rename public function rename from one path to another Overrides vfsStreamWrapper::rename
vfsStreamWrapperRecordingProxy::rmdir public function removes a directory Overrides vfsStreamWrapper::rmdir
vfsStreamWrapperRecordingProxy::setup public static function helper method for setting up vfsStream with the proxy
vfsStreamWrapperRecordingProxy::stream_cast public function retrieve the underlaying resource Overrides vfsStreamWrapper::stream_cast
vfsStreamWrapperRecordingProxy::stream_close public function closes the stream Overrides vfsStreamWrapper::stream_close
vfsStreamWrapperRecordingProxy::stream_eof public function checks whether stream is at end of file Overrides vfsStreamWrapper::stream_eof
vfsStreamWrapperRecordingProxy::stream_flush public function flushes unstored data into storage Overrides vfsStreamWrapper::stream_flush
vfsStreamWrapperRecordingProxy::stream_lock public function set lock status for stream Overrides vfsStreamWrapper::stream_lock
vfsStreamWrapperRecordingProxy::stream_open public function open the stream Overrides vfsStreamWrapper::stream_open
vfsStreamWrapperRecordingProxy::stream_read public function read the stream up to $count bytes Overrides vfsStreamWrapper::stream_read
vfsStreamWrapperRecordingProxy::stream_seek public function seeks to the given offset Overrides vfsStreamWrapper::stream_seek
vfsStreamWrapperRecordingProxy::stream_stat public function returns status of stream Overrides vfsStreamWrapper::stream_stat
vfsStreamWrapperRecordingProxy::stream_tell public function returns the current position of the stream Overrides vfsStreamWrapper::stream_tell
vfsStreamWrapperRecordingProxy::stream_write public function writes data into the stream Overrides vfsStreamWrapper::stream_write
vfsStreamWrapperRecordingProxy::unlink public function remove the data under the given path Overrides vfsStreamWrapper::unlink
vfsStreamWrapperRecordingProxy::url_stat public function returns status of url Overrides vfsStreamWrapper::url_stat