Chris@0: Chris@0: * Chris@0: * For the full copyright and license information, please view the LICENSE Chris@0: * file that was distributed with this source code. Chris@0: */ Chris@0: Chris@0: namespace Symfony\Component\Finder\Tests\Iterator; Chris@0: Chris@0: class MockSplFileInfo extends \SplFileInfo Chris@0: { Chris@0: const TYPE_DIRECTORY = 1; Chris@0: const TYPE_FILE = 2; Chris@0: const TYPE_UNKNOWN = 3; Chris@0: Chris@0: private $contents = null; Chris@0: private $mode = null; Chris@0: private $type = null; Chris@0: private $relativePath = null; Chris@0: private $relativePathname = null; Chris@0: Chris@0: public function __construct($param) Chris@0: { Chris@17: if (\is_string($param)) { Chris@0: parent::__construct($param); Chris@17: } elseif (\is_array($param)) { Chris@17: $defaults = [ Chris@17: 'name' => 'file.txt', Chris@17: 'contents' => null, Chris@17: 'mode' => null, Chris@17: 'type' => null, Chris@17: 'relativePath' => null, Chris@17: 'relativePathname' => null, Chris@17: ]; Chris@0: $defaults = array_merge($defaults, $param); Chris@0: parent::__construct($defaults['name']); Chris@0: $this->setContents($defaults['contents']); Chris@0: $this->setMode($defaults['mode']); Chris@0: $this->setType($defaults['type']); Chris@0: $this->setRelativePath($defaults['relativePath']); Chris@0: $this->setRelativePathname($defaults['relativePathname']); Chris@0: } else { Chris@0: throw new \RuntimeException(sprintf('Incorrect parameter "%s"', $param)); Chris@0: } Chris@0: } Chris@0: Chris@0: public function isFile() Chris@0: { Chris@0: if (null === $this->type) { Chris@0: return false !== strpos($this->getFilename(), 'file'); Chris@0: } Chris@0: Chris@0: return self::TYPE_FILE === $this->type; Chris@0: } Chris@0: Chris@0: public function isDir() Chris@0: { Chris@0: if (null === $this->type) { Chris@0: return false !== strpos($this->getFilename(), 'directory'); Chris@0: } Chris@0: Chris@0: return self::TYPE_DIRECTORY === $this->type; Chris@0: } Chris@0: Chris@0: public function isReadable() Chris@0: { Chris@0: if (null === $this->mode) { Chris@0: return preg_match('/r\+/', $this->getFilename()); Chris@0: } Chris@0: Chris@0: return preg_match('/r\+/', $this->mode); Chris@0: } Chris@0: Chris@0: public function getContents() Chris@0: { Chris@0: return $this->contents; Chris@0: } Chris@0: Chris@0: public function setContents($contents) Chris@0: { Chris@0: $this->contents = $contents; Chris@0: } Chris@0: Chris@0: public function setMode($mode) Chris@0: { Chris@0: $this->mode = $mode; Chris@0: } Chris@0: Chris@0: public function setType($type) Chris@0: { Chris@17: if (\is_string($type)) { Chris@0: switch ($type) { Chris@0: case 'directory': Chris@0: case 'd': Chris@0: $this->type = self::TYPE_DIRECTORY; Chris@0: break; Chris@0: case 'file': Chris@0: case 'f': Chris@0: $this->type = self::TYPE_FILE; Chris@0: break; Chris@0: default: Chris@0: $this->type = self::TYPE_UNKNOWN; Chris@0: } Chris@0: } else { Chris@0: $this->type = $type; Chris@0: } Chris@0: } Chris@0: Chris@0: public function setRelativePath($relativePath) Chris@0: { Chris@0: $this->relativePath = $relativePath; Chris@0: } Chris@0: Chris@0: public function setRelativePathname($relativePathname) Chris@0: { Chris@0: $this->relativePathname = $relativePathname; Chris@0: } Chris@0: Chris@0: public function getRelativePath() Chris@0: { Chris@0: return $this->relativePath; Chris@0: } Chris@0: Chris@0: public function getRelativePathname() Chris@0: { Chris@0: return $this->relativePathname; Chris@0: } Chris@0: }