You are here

class RealisticDummyContentDummyEnvironment in Realistic Dummy Content 8.2

Same name and namespace in other branches
  1. 7.2 api/src/includes/RealisticDummyContentDummyEnvironment.php \Drupal\realistic_dummy_content_api\includes\RealisticDummyContentDummyEnvironment

The dummy environment.

During normal execution, we want to do things like interact with the file- system and such. However during testing we want to abstract that away. This class represents the dummy environment which can be used during unit tests.


Expanded class hierarchy of RealisticDummyContentDummyEnvironment


api/src/includes/RealisticDummyContentDummyEnvironment.php, line 12


View source
class RealisticDummyContentDummyEnvironment extends RealisticDummyContentEnvironment {
  private $files;

   * {@inheritdoc}
  public function createFile($path, $data) {
    if (!is_array($this->files)) {
      $this->files = array();
    $this->files[$path] = $data;

   * {@inheritdoc}
  public function fileGetContents($filename) {
    if (isset($this->files[$filename])) {
      return $this->files[$filename];
    trigger_error('file_get_contents(): failed to open stream');
    return NULL;

   * {@inheritdoc}
  public function fileSaveData($data, $destination = NULL) {
    if (!$destination) {
      throw new \Exception('the dummy file system is not designed to use null destination');
    $parsed = parse_url($destination);
    $return_array = array(
      'fid' => 1,
      'uri' => $destination,
      'filename' => $parsed['host'],
    return (object) $return_array;

   * {@inheritdoc}
  public function fileSave(stdClass $file) {



Namesort descending Modifiers Type Description Overrides
RealisticDummyContentDummyEnvironment::$files private property
RealisticDummyContentDummyEnvironment::createFile public function
RealisticDummyContentDummyEnvironment::fileGetContents public function Get the contents of a file. Overrides RealisticDummyContentEnvironment::fileGetContents
RealisticDummyContentDummyEnvironment::fileSave public function Saves a file. Overrides RealisticDummyContentEnvironment::fileSave
RealisticDummyContentDummyEnvironment::fileSaveData public function Save the file data to the real or test environment. Overrides RealisticDummyContentEnvironment::fileSaveData
RealisticDummyContentEnvironment::$env private static property Private variable containing the environment to use.
RealisticDummyContentEnvironment::addFileToArray public static function Adds a file to an array of file group parts.
RealisticDummyContentEnvironment::attributeName public static function Returns the attribute of a filename if one exists.
RealisticDummyContentEnvironment::filenameRadical public static function Returns the name radical of a filename.
RealisticDummyContentEnvironment::get public static function Get the current environment.
RealisticDummyContentEnvironment::getAllFileGroups public static function Returns all files with a given extension for a given filepath.
RealisticDummyContentEnvironment::getFileContents public static function Returns the trimmed contents of a Drpual file object, or NULL if empty.
RealisticDummyContentEnvironment::getFileParts public static function Retrieves the parts constituting a filename.
RealisticDummyContentEnvironment::implementFileGetContents abstract public function Internal function used to get the contents of a file. 1
RealisticDummyContentEnvironment::implementFileSave abstract public function Implements $this->fileSave(). 1
RealisticDummyContentEnvironment::implementFileSaveData abstract public function Implements $this->fileSaveData(). 1
RealisticDummyContentEnvironment::implementSortCandidateFiles public static function Given a list of candidate files, sort them by names and parts.
RealisticDummyContentEnvironment::lowercaseRadicalNoExtension public static function Returns the part of a string before the extension, in lowercase.
RealisticDummyContentEnvironment::replace public static function Returns part of a filename.
RealisticDummyContentEnvironment::set public static function Set the current environment.
RealisticDummyContentEnvironment::sortCandidateFiles public static function Given a list of candidate files, sort them by names and parts.
RealisticDummyContentEnvironment::strToLower public static function Wrapper around drupal_strtolower(if it exists) or strtolower.
RealisticDummyContentEnvironment::validCandidateFilename public static function Checks if a filename is valid.