4 * This file is part of the Symfony package.
6 * (c) Fabien Potencier <fabien@symfony.com>
8 * For the full copyright and license information, please view the LICENSE
9 * file that was distributed with this source code.
12 namespace Symfony\Component\Finder\Tests\Iterator;
14 class MockSplFileInfo extends \SplFileInfo
16 const TYPE_DIRECTORY = 1;
18 const TYPE_UNKNOWN = 3;
20 private $contents = null;
23 private $relativePath = null;
24 private $relativePathname = null;
26 public function __construct($param)
28 if (is_string($param)) {
29 parent::__construct($param);
30 } elseif (is_array($param)) {
36 'relativePath' => null,
37 'relativePathname' => null,
39 $defaults = array_merge($defaults, $param);
40 parent::__construct($defaults['name']);
41 $this->setContents($defaults['contents']);
42 $this->setMode($defaults['mode']);
43 $this->setType($defaults['type']);
44 $this->setRelativePath($defaults['relativePath']);
45 $this->setRelativePathname($defaults['relativePathname']);
47 throw new \RuntimeException(sprintf('Incorrect parameter "%s"', $param));
51 public function isFile()
53 if (null === $this->type) {
54 return false !== strpos($this->getFilename(), 'file');
57 return self::TYPE_FILE === $this->type;
60 public function isDir()
62 if (null === $this->type) {
63 return false !== strpos($this->getFilename(), 'directory');
66 return self::TYPE_DIRECTORY === $this->type;
69 public function isReadable()
71 if (null === $this->mode) {
72 return preg_match('/r\+/', $this->getFilename());
75 return preg_match('/r\+/', $this->mode);
78 public function getContents()
80 return $this->contents;
83 public function setContents($contents)
85 $this->contents = $contents;
88 public function setMode($mode)
93 public function setType($type)
95 if (is_string($type)) {
99 $this->type = self::TYPE_DIRECTORY;
103 $this->type = self::TYPE_FILE;
106 $this->type = self::TYPE_UNKNOWN;
113 public function setRelativePath($relativePath)
115 $this->relativePath = $relativePath;
118 public function setRelativePathname($relativePathname)
120 $this->relativePathname = $relativePathname;
123 public function getRelativePath()
125 return $this->relativePath;
128 public function getRelativePathname()
130 return $this->relativePathname;