From 8f117f5f9e1297a46595ed2a01868312eeb3f429 Mon Sep 17 00:00:00 2001 From: Frank Kleine Date: Thu, 5 Mar 2020 12:55:48 +0100 Subject: [PATCH 1/2] introduce class name changes in new namespace This introduces the class name changes proposed with #213 into the v1.x series according to the migration strategy detailed in #221. --- CHANGELOG.md | 14 + .../vfs/content/SeekableFileContent.php | 4 +- org/bovigo/vfs/vfsStreamAbstractContent.php | 8 +- org/bovigo/vfs/vfsStreamBlock.php | 8 +- org/bovigo/vfs/vfsStreamContainer.php | 4 +- org/bovigo/vfs/vfsStreamContainerIterator.php | 8 +- org/bovigo/vfs/vfsStreamDirectory.php | 8 +- org/bovigo/vfs/vfsStreamFile.php | 8 +- org/bovigo/vfs/vfsStreamWrapper.php | 8 +- .../vfs/visitor/vfsStreamAbstractVisitor.php | 10 +- .../vfs/visitor/vfsStreamPrintVisitor.php | 8 +- .../vfs/visitor/vfsStreamStructureVisitor.php | 8 +- ...treamAbstractContent.php => BasicFile.php} | 4 +- src/DotDirectory.php | 4 +- ...vfsStreamWrapper.php => StreamWrapper.php} | 16 +- src/content/SeekableFileContent.php | 1 + src/{vfsStreamBlock.php => vfsBlock.php} | 4 +- ...fsStreamDirectory.php => vfsDirectory.php} | 8 +- ...rIterator.php => vfsDirectoryIterator.php} | 4 +- src/{vfsStreamFile.php => vfsFile.php} | 20 +- src/vfsStream.php | 60 +- src/vfsStreamContainer.php | 2 + src/vfsStreamContent.php | 2 + ...eamAbstractVisitor.php => BaseVisitor.php} | 14 +- ...{vfsStreamPrintVisitor.php => Printer.php} | 28 +- ...tureVisitor.php => StructureInspector.php} | 30 +- src/visitor/vfsStreamVisitor.php | 18 +- tests/phpunit/BasicFileTestCase.php | 1067 +++++++++++++++++ tests/phpunit/PermissionsTestCase.php | 4 +- tests/phpunit/UmaskTestCase.php | 205 ++++ tests/phpunit/vfsBlockTestCase.php | 103 ++ ...e.php => vfsDirectoryIteratorTestCase.php} | 10 +- tests/phpunit/vfsDirectoryTestCase.php | 351 ++++++ .../vfsStreamAbstractContentTestCase.php | 2 +- tests/phpunit/vfsStreamBlockTestCase.php | 2 +- .../vfsStreamDirectoryIssue134TestCase.php | 2 +- .../vfsStreamDirectoryIssue18TestCase.php | 2 +- tests/phpunit/vfsStreamDirectoryTestCase.php | 2 +- tests/phpunit/vfsStreamFileTestCase.php | 2 +- tests/phpunit/vfsStreamTestCase.php | 30 +- tests/phpunit/vfsStreamUmaskTestCase.php | 4 +- ...StreamWrapperAlreadyRegisteredTestCase.php | 8 +- .../phpunit/vfsStreamWrapperBaseTestCase.php | 18 +- tests/phpunit/vfsStreamWrapperDirTestCase.php | 66 +- .../phpunit/vfsStreamWrapperFileTestCase.php | 34 +- .../vfsStreamWrapperFileTimesTestCase.php | 29 +- .../vfsStreamWrapperLargeFileTestCase.php | 4 +- .../phpunit/vfsStreamWrapperQuotaTestCase.php | 6 +- tests/phpunit/vfsStreamWrapperTestCase.php | 18 +- .../vfsStreamWrapperUnregisterTestCase.php | 20 +- .../vfsStreamWrapperWithoutRootTestCase.php | 6 +- tests/phpunit/vfsStreamZipTestCase.php | 6 +- tests/phpunit/visitor/BaseVisitorTestCase.php | 108 ++ tests/phpunit/visitor/PrinterTestCase.php | 112 ++ .../visitor/StructureInspectorTestCase.php | 92 ++ .../vfsStreamAbstractVisitorTestCase.php | 8 +- .../visitor/vfsStreamPrintVisitorTestCase.php | 2 +- .../vfsStreamStructureVisitorTestCase.php | 2 +- 58 files changed, 2346 insertions(+), 290 deletions(-) rename src/{vfsStreamAbstractContent.php => BasicFile.php} (98%) rename src/{vfsStreamWrapper.php => StreamWrapper.php} (98%) rename src/{vfsStreamBlock.php => vfsBlock.php} (85%) rename src/{vfsStreamDirectory.php => vfsDirectory.php} (95%) rename src/{vfsStreamContainerIterator.php => vfsDirectoryIterator.php} (92%) rename src/{vfsStreamFile.php => vfsFile.php} (94%) rename src/visitor/{vfsStreamAbstractVisitor.php => BaseVisitor.php} (80%) rename src/visitor/{vfsStreamPrintVisitor.php => Printer.php} (76%) rename src/visitor/{vfsStreamStructureVisitor.php => StructureInspector.php} (72%) create mode 100644 tests/phpunit/BasicFileTestCase.php create mode 100644 tests/phpunit/UmaskTestCase.php create mode 100644 tests/phpunit/vfsBlockTestCase.php rename tests/phpunit/{vfsStreamContainerIteratorTestCase.php => vfsDirectoryIteratorTestCase.php} (92%) create mode 100644 tests/phpunit/vfsDirectoryTestCase.php create mode 100644 tests/phpunit/visitor/BaseVisitorTestCase.php create mode 100644 tests/phpunit/visitor/PrinterTestCase.php create mode 100644 tests/phpunit/visitor/StructureInspectorTestCase.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 9e9c70bd..4da24c58 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,20 @@ * Namespace changed from `org\bovigo\vfs` to `bovigo\vfs` - The old namespace still works, but has been deprecated. It will be removed in version 2. + * Renamed some classes in the new namespace. When moving your code to the new namespace please be aware of the following name changes: + - `org\bovigo\vfs\vfsStreamBlock` => `bovigo\vfs\vfsBlock` + - `org\bovigo\vfs\vfsStreamContainerIterator` => `bovigo\vfs\vfsDirectoryIterator` + - `org\bovigo\vfs\vfsStreamDirectory` => `bovigo\vfs\vfsDirectory` + - `org\bovigo\vfs\vfsStreamFile` => `bovigo\vfs\vfsFile` + - `org\bovigo\vfs\vfsStreamWrapper` => `bovigo\vfs\StreamWrapper` + - `org\bovigo\vfs\visitor\vfsStreamAbstractVisitor` => `bovigo\vfs\visitor\BaseVisitor` + - `org\bovigo\vfs\visitor\vfsStreamPrintVisitor` => `bovigo\vfs\visitor\Printer` + - `org\bovigo\vfs\visitor\vfsStreamStructureVisitor` => `bovigo\vfs\visitor\StructureInspector` + - `org\bovigo\vfs\vfsStreamAbstractContent` => `bovigo\vfs\BasicFile` + * Deprecated (internal) classes and interfaces, they will be removed in version 2. + - `org\bovigo\vfs\vfsStreamContent` + - `org\bovigo\vfs\vfsStreamContainer` + - `org\bovigo\vfs\content\SeekableFileContent` * raised requirement for minimum PHP version to 5.6.0 diff --git a/org/bovigo/vfs/content/SeekableFileContent.php b/org/bovigo/vfs/content/SeekableFileContent.php index 579f66f7..b7a039c2 100644 --- a/org/bovigo/vfs/content/SeekableFileContent.php +++ b/org/bovigo/vfs/content/SeekableFileContent.php @@ -6,10 +6,10 @@ class_exists('bovigo\vfs\content\SeekableFileContent'); -@trigger_error('Using the "org\bovigo\vfs\content\SeekableFileContent" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\content\SeekableFileContent" instead.', E_USER_DEPRECATED); +@trigger_error('Using the "org\bovigo\vfs\content\SeekableFileContent" class is deprecated since version 1.7 and will be removed in version 2.', E_USER_DEPRECATED); if (\false) { - /** @deprecated since 1.7, use "bovigo\vfs\SeekableFileContent" instead */ + /** @deprecated since 1.7, will be removed in version 2 */ abstract class SeekableFileContent extends Base { } diff --git a/org/bovigo/vfs/vfsStreamAbstractContent.php b/org/bovigo/vfs/vfsStreamAbstractContent.php index d4fc8816..4d79f0dc 100644 --- a/org/bovigo/vfs/vfsStreamAbstractContent.php +++ b/org/bovigo/vfs/vfsStreamAbstractContent.php @@ -2,14 +2,14 @@ namespace org\bovigo\vfs; -use bovigo\vfs\vfsStreamAbstractContent as Base; +use bovigo\vfs\BasicFile as Base; -class_exists('bovigo\vfs\vfsStreamAbstractContent'); +class_exists('bovigo\vfs\BasicFile'); -@trigger_error('Using the "org\bovigo\vfs\vfsStreamAbstractContent" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\vfsStreamAbstractContent" instead.', E_USER_DEPRECATED); +@trigger_error('Using the "org\bovigo\vfs\vfsStreamAbstractContent" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\BasicFile" instead.', E_USER_DEPRECATED); if (\false) { - /** @deprecated since 1.7, use "bovigo\vfs\vfsStreamAbstractContent" instead */ + /** @deprecated since 1.7, use "bovigo\vfs\BasicFile" instead */ abstract class vfsStreamAbstractContent extends Base { } diff --git a/org/bovigo/vfs/vfsStreamBlock.php b/org/bovigo/vfs/vfsStreamBlock.php index 9b2f3a9b..0394a0d9 100644 --- a/org/bovigo/vfs/vfsStreamBlock.php +++ b/org/bovigo/vfs/vfsStreamBlock.php @@ -2,14 +2,14 @@ namespace org\bovigo\vfs; -use bovigo\vfs\vfsStreamBlock as Base; +use bovigo\vfs\vfsBlock as Base; -class_exists('bovigo\vfs\vfsStreamBlock'); +class_exists('bovigo\vfs\vfsBlock'); -@trigger_error('Using the "org\bovigo\vfs\vfsStreamBlock" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\vfsStreamBlock" instead.', E_USER_DEPRECATED); +@trigger_error('Using the "org\bovigo\vfs\vfsStreamBlock" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\vfsBlock" instead.', E_USER_DEPRECATED); if (\false) { - /** @deprecated since 1.7, use "bovigo\vfs\vfsStreamBlock" instead */ + /** @deprecated since 1.7, use "bovigo\vfs\vfsBlock" instead */ class vfsStreamBlock extends Base { } diff --git a/org/bovigo/vfs/vfsStreamContainer.php b/org/bovigo/vfs/vfsStreamContainer.php index 1fedeb1f..6afc0f48 100644 --- a/org/bovigo/vfs/vfsStreamContainer.php +++ b/org/bovigo/vfs/vfsStreamContainer.php @@ -6,10 +6,10 @@ interface_exists('bovigo\vfs\vfsStreamContainer'); -@trigger_error('Using the "org\bovigo\vfs\vfsStreamContainer" interface is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\vfsStreamContainer" instead.', E_USER_DEPRECATED); +@trigger_error('Using the "org\bovigo\vfs\vfsStreamContainer" interface is deprecated since version 1.7 and will be removed in version 2.', E_USER_DEPRECATED); if (\false) { - /** @deprecated since 1.7, use "bovigo\vfs\vfsStreamContainer" instead */ + /** @deprecated since 1.7, will be removed in version 2 */ interface vfsStreamContainer extends Base { } diff --git a/org/bovigo/vfs/vfsStreamContainerIterator.php b/org/bovigo/vfs/vfsStreamContainerIterator.php index fa20048d..c00796b2 100644 --- a/org/bovigo/vfs/vfsStreamContainerIterator.php +++ b/org/bovigo/vfs/vfsStreamContainerIterator.php @@ -2,14 +2,14 @@ namespace org\bovigo\vfs; -use bovigo\vfs\vfsStreamContainerIterator as Base; +use bovigo\vfs\vfsDirectoryIterator as Base; -class_exists('bovigo\vfs\vfsStreamContainerIterator'); +class_exists('bovigo\vfs\vfsDirectoryIterator'); -@trigger_error('Using the "org\bovigo\vfs\vfsStreamContainerIterator" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\vfsStreamContainerIterator" instead.', E_USER_DEPRECATED); +@trigger_error('Using the "org\bovigo\vfs\vfsStreamContainerIterator" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\vfsDirectoryIterator" instead.', E_USER_DEPRECATED); if (\false) { - /** @deprecated since 1.7, use "bovigo\vfs\vfsStreamContainerIterator" instead */ + /** @deprecated since 1.7, use "bovigo\vfs\vfsDirectoryIterator" instead */ class vfsStreamContainerIterator extends Base { } diff --git a/org/bovigo/vfs/vfsStreamDirectory.php b/org/bovigo/vfs/vfsStreamDirectory.php index 1dfd38e4..6e143e52 100644 --- a/org/bovigo/vfs/vfsStreamDirectory.php +++ b/org/bovigo/vfs/vfsStreamDirectory.php @@ -2,14 +2,14 @@ namespace org\bovigo\vfs; -use bovigo\vfs\vfsStreamDirectory as Base; +use bovigo\vfs\vfsDirectory as Base; -class_exists('bovigo\vfs\vfsStreamDirectory'); +class_exists('bovigo\vfs\vfsDirectory'); -@trigger_error('Using the "org\bovigo\vfs\vfsStreamDirectory" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\vfsStreamDirectory" instead.', E_USER_DEPRECATED); +@trigger_error('Using the "org\bovigo\vfs\vfsStreamDirectory" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\vfsDirectory" instead.', E_USER_DEPRECATED); if (\false) { - /** @deprecated since 1.7, use "bovigo\vfs\vfsStreamDirectory" instead */ + /** @deprecated since 1.7, use "bovigo\vfs\vfsDirectory" instead */ class vfsStreamDirectory extends Base { } diff --git a/org/bovigo/vfs/vfsStreamFile.php b/org/bovigo/vfs/vfsStreamFile.php index 9da3244a..05ac3555 100644 --- a/org/bovigo/vfs/vfsStreamFile.php +++ b/org/bovigo/vfs/vfsStreamFile.php @@ -2,14 +2,14 @@ namespace org\bovigo\vfs; -use bovigo\vfs\vfsStreamFile as Base; +use bovigo\vfs\vfsFile as Base; -class_exists('bovigo\vfs\vfsStreamFile'); +class_exists('bovigo\vfs\vfsFile'); -@trigger_error('Using the "org\bovigo\vfs\vfsStreamFile" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\vfsStreamFile" instead.', E_USER_DEPRECATED); +@trigger_error('Using the "org\bovigo\vfs\vfsStreamFile" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\vfsFile" instead.', E_USER_DEPRECATED); if (\false) { - /** @deprecated since 1.7, use "bovigo\vfs\vfsStreamFile" instead */ + /** @deprecated since 1.7, use "bovigo\vfs\vfsFile" instead */ class vfsStreamFile extends Base { } diff --git a/org/bovigo/vfs/vfsStreamWrapper.php b/org/bovigo/vfs/vfsStreamWrapper.php index 0d51ab69..f92da99e 100644 --- a/org/bovigo/vfs/vfsStreamWrapper.php +++ b/org/bovigo/vfs/vfsStreamWrapper.php @@ -2,14 +2,14 @@ namespace org\bovigo\vfs; -use bovigo\vfs\vfsStreamWrapper as Base; +use bovigo\vfs\StreamWrapper as Base; -class_exists('bovigo\vfs\vfsStreamWrapper'); +class_exists('bovigo\vfs\StreamWrapper'); -@trigger_error('Using the "org\bovigo\vfs\vfsStreamWrapper" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\vfsStreamWrapper" instead.', E_USER_DEPRECATED); +@trigger_error('Using the "org\bovigo\vfs\vfsStreamWrapper" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\StreamWrapper" instead.', E_USER_DEPRECATED); if (\false) { - /** @deprecated since 1.7, use "bovigo\vfs\vfsStreamWrapper" instead */ + /** @deprecated since 1.7, use "bovigo\vfs\StreamWrapper" instead */ class vfsStreamWrapper extends Base { } diff --git a/org/bovigo/vfs/visitor/vfsStreamAbstractVisitor.php b/org/bovigo/vfs/visitor/vfsStreamAbstractVisitor.php index 790fd6a4..6ee8e3c1 100644 --- a/org/bovigo/vfs/visitor/vfsStreamAbstractVisitor.php +++ b/org/bovigo/vfs/visitor/vfsStreamAbstractVisitor.php @@ -2,15 +2,15 @@ namespace org\bovigo\vfs\visitor; -use bovigo\vfs\visitor\vfsStreamAbstractVisitor as Base; +use bovigo\vfs\visitor\BaseVisitor; -class_exists('bovigo\vfs\visitor\vfsStreamAbstractVisitor'); +class_exists('bovigo\vfs\visitor\BaseVisitor'); -@trigger_error('Using the "org\bovigo\vfs\visitor\vfsStreamAbstractVisitor" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\visitor\vfsStreamAbstractVisitor" instead.', E_USER_DEPRECATED); +@trigger_error('Using the "org\bovigo\vfs\visitor\vfsStreamAbstractVisitor" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\visitor\BaseVisitor" instead.', E_USER_DEPRECATED); if (\false) { - /** @deprecated since 1.7, use "bovigo\vfs\vfsStreamAbstractVisitor" instead */ - abstract class vfsStreamAbstractVisitor extends Base + /** @deprecated since 1.7, use "bovigo\vfs\BaseVisitor" instead */ + abstract class vfsStreamAbstractVisitor extends BaseVisitor { } } diff --git a/org/bovigo/vfs/visitor/vfsStreamPrintVisitor.php b/org/bovigo/vfs/visitor/vfsStreamPrintVisitor.php index d6493780..4ae14e44 100644 --- a/org/bovigo/vfs/visitor/vfsStreamPrintVisitor.php +++ b/org/bovigo/vfs/visitor/vfsStreamPrintVisitor.php @@ -2,14 +2,14 @@ namespace org\bovigo\vfs\visitor; -use bovigo\vfs\visitor\vfsStreamPrintVisitor as Base; +use bovigo\vfs\visitor\Printer as Base; -class_exists('bovigo\vfs\visitor\vfsStreamPrintVisitor'); +class_exists('bovigo\vfs\visitor\Printer'); -@trigger_error('Using the "org\bovigo\vfs\visitor\vfsStreamPrintVisitor" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\visitor\vfsStreamPrintVisitor" instead.', E_USER_DEPRECATED); +@trigger_error('Using the "org\bovigo\vfs\visitor\vfsStreamPrintVisitor" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\visitor\Printer" instead.', E_USER_DEPRECATED); if (\false) { - /** @deprecated since 1.7, use "bovigo\vfs\vfsStreamPrintVisitor" instead */ + /** @deprecated since 1.7, use "bovigo\vfs\Printer" instead */ class vfsStreamPrintVisitor extends Base { } diff --git a/org/bovigo/vfs/visitor/vfsStreamStructureVisitor.php b/org/bovigo/vfs/visitor/vfsStreamStructureVisitor.php index d4b08f65..08e1e0f0 100644 --- a/org/bovigo/vfs/visitor/vfsStreamStructureVisitor.php +++ b/org/bovigo/vfs/visitor/vfsStreamStructureVisitor.php @@ -2,14 +2,14 @@ namespace org\bovigo\vfs\visitor; -use bovigo\vfs\visitor\vfsStreamStructureVisitor as Base; +use bovigo\vfs\visitor\StructureInspector as Base; -class_exists('bovigo\vfs\visitor\vfsStreamStructureVisitor'); +class_exists('bovigo\vfs\visitor\StructureInspector'); -@trigger_error('Using the "org\bovigo\vfs\visitor\vfsStreamStructureVisitor" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\visitor\vfsStreamStructureVisitor" instead.', E_USER_DEPRECATED); +@trigger_error('Using the "org\bovigo\vfs\visitor\vfsStreamStructureVisitor" class is deprecated since version 1.7 and will be removed in version 2, use "bovigo\vfs\visitor\StructureInspector" instead.', E_USER_DEPRECATED); if (\false) { - /** @deprecated since 1.7, use "bovigo\vfs\vfsStreamStructureVisitor" instead */ + /** @deprecated since 1.7, use "bovigo\vfs\StructureInspector" instead */ class vfsStreamStructureVisitor extends Base { } diff --git a/src/vfsStreamAbstractContent.php b/src/BasicFile.php similarity index 98% rename from src/vfsStreamAbstractContent.php rename to src/BasicFile.php index cf6e6245..da872b1c 100644 --- a/src/vfsStreamAbstractContent.php +++ b/src/BasicFile.php @@ -20,7 +20,7 @@ /** * Base stream contents container. */ -abstract class vfsStreamAbstractContent implements vfsStreamContent +abstract class BasicFile implements vfsStreamContent { /** * name of the container @@ -426,4 +426,4 @@ public function url() } } -class_alias('bovigo\vfs\vfsStreamAbstractContent', 'org\bovigo\vfs\vfsStreamAbstractContent'); +class_alias('bovigo\vfs\BasicFile', 'org\bovigo\vfs\vfsStreamAbstractContent'); diff --git a/src/DotDirectory.php b/src/DotDirectory.php index bde269b3..30f513bb 100644 --- a/src/DotDirectory.php +++ b/src/DotDirectory.php @@ -17,12 +17,12 @@ /** * Directory container. */ -class DotDirectory extends vfsStreamDirectory +class DotDirectory extends vfsDirectory { /** * returns iterator for the children * - * @return vfsStreamContainerIterator + * @return vfsDirectoryIterator */ public function getIterator() { diff --git a/src/vfsStreamWrapper.php b/src/StreamWrapper.php similarity index 98% rename from src/vfsStreamWrapper.php rename to src/StreamWrapper.php index 4e18343b..a109a891 100644 --- a/src/vfsStreamWrapper.php +++ b/src/StreamWrapper.php @@ -49,7 +49,7 @@ /** * Stream wrapper to mock file system requests. */ -class vfsStreamWrapper +class StreamWrapper { /** * open file for reading @@ -117,13 +117,13 @@ class vfsStreamWrapper /** * shortcut to directory container * - * @type vfsStreamDirectory + * @type vfsDirectory */ protected $dir; /** * shortcut to directory container iterator * - * @type vfsStreamDirectory + * @type vfsDirectory */ protected $dirIterator; @@ -612,12 +612,12 @@ function() use ($content, $var) /** * executes given permission change when necessary rights allow such a change * - * @param string $path - * @param vfsStreamAbstractContent $content - * @param \Closure $change + * @param string $path + * @param BasicFile $content + * @param \Closure $change * @return bool */ - private function doPermChange($path, vfsStreamAbstractContent $content, \Closure $change) + private function doPermChange($path, BasicFile $content, \Closure $change) { if (!$content->isOwnedByUser(vfsStream::getCurrentUser())) { return false; @@ -1049,4 +1049,4 @@ public function url_stat($path, $flags) } } -class_alias('bovigo\vfs\vfsStreamWrapper', 'org\bovigo\vfs\vfsStreamWrapper'); +class_alias('bovigo\vfs\StreamWrapper', 'org\bovigo\vfs\vfsStreamWrapper'); diff --git a/src/content/SeekableFileContent.php b/src/content/SeekableFileContent.php index 0c266592..f04af91c 100644 --- a/src/content/SeekableFileContent.php +++ b/src/content/SeekableFileContent.php @@ -21,6 +21,7 @@ * Default implementation for file contents based on simple strings. * * @since 1.3.0 + * @deprecated since 1.7, will be removed in version 2 */ abstract class SeekableFileContent implements FileContent { diff --git a/src/vfsStreamBlock.php b/src/vfsBlock.php similarity index 85% rename from src/vfsStreamBlock.php rename to src/vfsBlock.php index 2deed4cf..a610f6b1 100644 --- a/src/vfsStreamBlock.php +++ b/src/vfsBlock.php @@ -17,7 +17,7 @@ * * @api */ -class vfsStreamBlock extends vfsStreamFile +class vfsBlock extends vfsFile { /** * constructor @@ -36,4 +36,4 @@ public function __construct($name, $permissions = null) } } -class_alias('bovigo\vfs\vfsStreamBlock', 'org\bovigo\vfs\vfsStreamBlock'); +class_alias('bovigo\vfs\vfsBlock', 'org\bovigo\vfs\vfsStreamBlock'); diff --git a/src/vfsStreamDirectory.php b/src/vfsDirectory.php similarity index 95% rename from src/vfsStreamDirectory.php rename to src/vfsDirectory.php index e1507748..700f251c 100644 --- a/src/vfsStreamDirectory.php +++ b/src/vfsDirectory.php @@ -23,7 +23,7 @@ * * @api */ -class vfsStreamDirectory extends vfsStreamAbstractContent implements vfsStreamContainer +class vfsDirectory extends BasicFile implements vfsStreamContainer { /** * list of directory children @@ -253,11 +253,11 @@ public function getChildren() /** * returns iterator for the children * - * @return vfsStreamContainerIterator + * @return vfsDirectoryIterator */ public function getIterator() { - return new vfsStreamContainerIterator($this->children); + return new vfsDirectoryIterator($this->children); } /** @@ -275,4 +275,4 @@ public function isDot() } } -class_alias('bovigo\vfs\vfsStreamDirectory', 'org\bovigo\vfs\vfsStreamDirectory'); +class_alias('bovigo\vfs\vfsDirectory', 'org\bovigo\vfs\vfsStreamDirectory'); diff --git a/src/vfsStreamContainerIterator.php b/src/vfsDirectoryIterator.php similarity index 92% rename from src/vfsStreamContainerIterator.php rename to src/vfsDirectoryIterator.php index abe5808c..18892565 100644 --- a/src/vfsStreamContainerIterator.php +++ b/src/vfsDirectoryIterator.php @@ -20,7 +20,7 @@ /** * Iterator for children of a directory container. */ -class vfsStreamContainerIterator implements \Iterator +class vfsDirectoryIterator implements \Iterator { /** * list of children from container to iterate over @@ -101,4 +101,4 @@ public function valid() } } -class_alias('bovigo\vfs\vfsStreamContainerIterator', 'org\bovigo\vfs\vfsStreamContainerIterator'); +class_alias('bovigo\vfs\vfsDirectoryIterator', 'org\bovigo\vfs\vfsStreamContainerIterator'); diff --git a/src/vfsStreamFile.php b/src/vfsFile.php similarity index 94% rename from src/vfsStreamFile.php rename to src/vfsFile.php index c3d6df04..12017948 100644 --- a/src/vfsStreamFile.php +++ b/src/vfsFile.php @@ -31,7 +31,7 @@ * * @api */ -class vfsStreamFile extends vfsStreamAbstractContent +class vfsFile extends BasicFile { /** * content of the file @@ -279,7 +279,7 @@ public function size() /** * locks file for * - * @param resource|vfsStreamWrapper $resource + * @param resource|StreamWrapper $resource * @param int $operation * @return bool * @since 0.10.0 @@ -315,7 +315,7 @@ public function lock($resource, $operation) /** * Removes lock from file acquired by given resource * - * @param resource|vfsStreamWrapper $resource + * @param resource|StreamWrapper $resource * @see https://github.com/mikey179/vfsStream/issues/40 */ public function unlock($resource) { @@ -330,7 +330,7 @@ public function unlock($resource) { /** * Set exlusive lock on file by given resource * - * @param resource|vfsStreamWrapper $resource + * @param resource|StreamWrapper $resource * @see https://github.com/mikey179/vfsStream/issues/40 */ protected function setExclusiveLock($resource) { @@ -340,7 +340,7 @@ protected function setExclusiveLock($resource) { /** * Add shared lock on file by given resource * - * @param resource|vfsStreamWrapper $resource + * @param resource|StreamWrapper $resource * @see https://github.com/mikey179/vfsStream/issues/40 */ protected function addSharedLock($resource) { @@ -350,7 +350,7 @@ protected function addSharedLock($resource) { /** * checks whether file is locked * - * @param resource|vfsStreamWrapper $resource + * @param resource|StreamWrapper $resource * @return bool * @since 0.10.0 * @see https://github.com/mikey179/vfsStream/issues/6 @@ -364,7 +364,7 @@ public function isLocked($resource = null) /** * checks whether file is locked in shared mode * - * @param resource|vfsStreamWrapper $resource + * @param resource|StreamWrapper $resource * @return bool * @since 0.10.0 * @see https://github.com/mikey179/vfsStream/issues/6 @@ -382,7 +382,7 @@ public function hasSharedLock($resource = null) /** * Returns unique resource id * - * @param resource|vfsStreamWrapper $resource + * @param resource|StreamWrapper $resource * @return string * @see https://github.com/mikey179/vfsStream/issues/40 */ @@ -398,7 +398,7 @@ public function getResourceId($resource) { /** * checks whether file is locked in exclusive mode * - * @param resource|vfsStreamWrapper $resource + * @param resource|StreamWrapper $resource * @return bool * @since 0.10.0 * @see https://github.com/mikey179/vfsStream/issues/6 @@ -414,4 +414,4 @@ public function hasExclusiveLock($resource = null) } } -class_alias('bovigo\vfs\vfsStreamFile', 'org\bovigo\vfs\vfsStreamFile'); +class_alias('bovigo\vfs\vfsFile', 'org\bovigo\vfs\vfsStreamFile'); diff --git a/src/vfsStream.php b/src/vfsStream.php index 1ccae6ab..663db41a 100644 --- a/src/vfsStream.php +++ b/src/vfsStream.php @@ -144,8 +144,8 @@ public static function umask($umask = null) * helper method for setting up vfsStream in unit tests * * Instead of - * vfsStreamWrapper::register(); - * vfsStreamWrapper::setRoot(vfsStream::newDirectory('root')); + * StreamWrapper::register(); + * StreamWrapper::setRoot(vfsStream::newDirectory('root')); * you can simply do * vfsStream::setup() * which yields the same result. Additionally, the method returns the @@ -181,15 +181,15 @@ public static function umask($umask = null) * @param string $rootDirName name of root directory * @param int $permissions file permissions of root directory * @param array $structure directory structure to add under root directory - * @return \org\bovigo\vfs\vfsStreamDirectory + * @return vfsDirectory * @since 0.7.0 * @see https://github.com/mikey179/vfsStream/issues/14 * @see https://github.com/mikey179/vfsStream/issues/20 */ public static function setup($rootDirName = 'root', $permissions = null, array $structure = array()) { - vfsStreamWrapper::register(); - return self::create($structure, vfsStreamWrapper::setRoot(self::newDirectory($rootDirName, $permissions))); + StreamWrapper::register(); + return self::create($structure, StreamWrapper::setRoot(self::newDirectory($rootDirName, $permissions))); } /** @@ -225,18 +225,18 @@ public static function setup($rootDirName = 'root', $permissions = null, array $ * root directory without replacing existing childs except those with equal * names. * - * @param array $structure directory structure to add under root directory - * @param vfsStreamDirectory $baseDir base directory to add structure to - * @return vfsStreamDirectory + * @param array $structure directory structure to add under root directory + * @param vfsDirectory $baseDir base directory to add structure to + * @return vfsDirectory * @throws \InvalidArgumentException * @since 0.10.0 * @see https://github.com/mikey179/vfsStream/issues/14 * @see https://github.com/mikey179/vfsStream/issues/20 */ - public static function create(array $structure, vfsStreamDirectory $baseDir = null) + public static function create(array $structure, vfsDirectory $baseDir = null) { if (null === $baseDir) { - $baseDir = vfsStreamWrapper::getRoot(); + $baseDir = StreamWrapper::getRoot(); } if (null === $baseDir) { @@ -249,11 +249,11 @@ public static function create(array $structure, vfsStreamDirectory $baseDir = nu /** * helper method to create subdirectories recursively * - * @param array $structure subdirectory structure to add - * @param vfsStreamDirectory $baseDir directory to add the structure to - * @return vfsStreamDirectory + * @param array $structure subdirectory structure to add + * @param vfsDirectory $baseDir directory to add the structure to + * @return vfsDirectory */ - protected static function addStructure(array $structure, vfsStreamDirectory $baseDir) + protected static function addStructure(array $structure, vfsDirectory $baseDir) { foreach ($structure as $name => $data) { $name = (string) $name; @@ -269,7 +269,7 @@ protected static function addStructure(array $structure, vfsStreamDirectory $bas } } elseif ($data instanceof FileContent) { self::newFile($name)->withContent($data)->at($baseDir); - } elseif ($data instanceof vfsStreamFile) { + } elseif ($data instanceof vfsFile) { $baseDir->addChild($data); } } @@ -289,18 +289,18 @@ protected static function addStructure(array $structure, vfsStreamDirectory $bas * the file is larger file content will be mocked, see * https://github.com/mikey179/vfsStream/wiki/MockingLargeFiles. * - * @param string $path path to copy the structure from - * @param vfsStreamDirectory $baseDir directory to add the structure to - * @param int $maxFileSize maximum file size of files to copy content from - * @return vfsStreamDirectory + * @param string $path path to copy the structure from + * @param vfsDirectory $baseDir directory to add the structure to + * @param int $maxFileSize maximum file size of files to copy content from + * @return vfsDirectory * @throws \InvalidArgumentException * @since 0.11.0 * @see https://github.com/mikey179/vfsStream/issues/4 */ - public static function copyFromFileSystem($path, vfsStreamDirectory $baseDir = null, $maxFileSize = 1048576) + public static function copyFromFileSystem($path, vfsDirectory $baseDir = null, $maxFileSize = 1048576) { if (null === $baseDir) { - $baseDir = vfsStreamWrapper::getRoot(); + $baseDir = StreamWrapper::getRoot(); } if (null === $baseDir) { @@ -356,11 +356,11 @@ public static function copyFromFileSystem($path, vfsStreamDirectory $baseDir = n * * @param string $name name of file to create * @param int $permissions permissions of file to create - * @return vfsStreamFile + * @return vfsFile */ public static function newFile($name, $permissions = null) { - return new vfsStreamFile($name, $permissions); + return new vfsFile($name, $permissions); } /** @@ -372,7 +372,7 @@ public static function newFile($name, $permissions = null) * * @param string $name name of directory to create * @param int $permissions permissions of directory to create - * @return vfsStreamDirectory + * @return vfsDirectory */ public static function newDirectory($name, $permissions = null) { @@ -382,12 +382,12 @@ public static function newDirectory($name, $permissions = null) $firstSlash = strpos($name, '/'); if (false === $firstSlash) { - return new vfsStreamDirectory($name, $permissions); + return new vfsDirectory($name, $permissions); } $ownName = substr($name, 0, $firstSlash); $subDirs = substr($name, $firstSlash + 1); - $directory = new vfsStreamDirectory($ownName, $permissions); + $directory = new vfsDirectory($ownName, $permissions); if (is_string($subDirs) && strlen($subDirs) > 0) { self::newDirectory($subDirs, $permissions)->at($directory); } @@ -400,11 +400,11 @@ public static function newDirectory($name, $permissions = null) * * @param string $name name of the block device * @param int $permissions permissions of block to create - * @return vfsStreamBlock + * @return vfsBlock */ public static function newBlock($name, $permissions = null) { - return new vfsStreamBlock($name, $permissions); + return new vfsBlock($name, $permissions); } /** @@ -452,7 +452,7 @@ public static function inspect(vfsStreamVisitor $visitor, vfsStreamContent $cont return $visitor->visit($content); } - $root = vfsStreamWrapper::getRoot(); + $root = StreamWrapper::getRoot(); if (null === $root) { throw new \InvalidArgumentException('No content given and no root directory set.'); } @@ -468,7 +468,7 @@ public static function inspect(vfsStreamVisitor $visitor, vfsStreamContent $cont */ public static function setQuota($bytes) { - vfsStreamWrapper::setQuota(new Quota($bytes)); + StreamWrapper::setQuota(new Quota($bytes)); } /** diff --git a/src/vfsStreamContainer.php b/src/vfsStreamContainer.php index cceb59e3..9a623b7b 100644 --- a/src/vfsStreamContainer.php +++ b/src/vfsStreamContainer.php @@ -15,6 +15,8 @@ /** * Interface for stream contents that are able to store other stream contents. + * + * @deprecated since 1.7, will be removed in version 2 */ interface vfsStreamContainer extends \IteratorAggregate { diff --git a/src/vfsStreamContent.php b/src/vfsStreamContent.php index 688fde6c..5c5a6fcc 100644 --- a/src/vfsStreamContent.php +++ b/src/vfsStreamContent.php @@ -14,6 +14,8 @@ /** * Interface for stream contents. + * + * @deprecated since 1.7, will be removed in version 2 */ interface vfsStreamContent { diff --git a/src/visitor/vfsStreamAbstractVisitor.php b/src/visitor/BaseVisitor.php similarity index 80% rename from src/visitor/vfsStreamAbstractVisitor.php rename to src/visitor/BaseVisitor.php index 44e1f093..171c13d0 100644 --- a/src/visitor/vfsStreamAbstractVisitor.php +++ b/src/visitor/BaseVisitor.php @@ -10,10 +10,10 @@ namespace bovigo\vfs\visitor; -use bovigo\vfs\vfsStreamBlock; +use bovigo\vfs\vfsBlock; +use bovigo\vfs\vfsDirectory; +use bovigo\vfs\vfsFile; use bovigo\vfs\vfsStreamContent; -use bovigo\vfs\vfsStreamDirectory; -use bovigo\vfs\vfsStreamFile; use InvalidArgumentException; use function class_alias; @@ -23,7 +23,7 @@ * @since 0.10.0 * @see https://github.com/mikey179/vfsStream/issues/10 */ -abstract class vfsStreamAbstractVisitor implements vfsStreamVisitor +abstract class BaseVisitor implements vfsStreamVisitor { /** * visit a content and process it @@ -60,13 +60,13 @@ public function visit(vfsStreamContent $content) /** * visit a block device and process it * - * @param vfsStreamBlock $block + * @param vfsBlock $block * @return vfsStreamVisitor */ - public function visitBlockDevice(vfsStreamBlock $block) + public function visitBlockDevice(vfsBlock $block) { return $this->visitFile($block); } } -class_alias('bovigo\vfs\visitor\vfsStreamAbstractVisitor', 'org\bovigo\vfs\visitor\vfsStreamAbstractVisitor'); +class_alias('bovigo\vfs\visitor\BaseVisitor', 'org\bovigo\vfs\visitor\vfsStreamAbstractVisitor'); diff --git a/src/visitor/vfsStreamPrintVisitor.php b/src/visitor/Printer.php similarity index 76% rename from src/visitor/vfsStreamPrintVisitor.php rename to src/visitor/Printer.php index cac81520..04ca011a 100644 --- a/src/visitor/vfsStreamPrintVisitor.php +++ b/src/visitor/Printer.php @@ -10,9 +10,9 @@ namespace bovigo\vfs\visitor; -use bovigo\vfs\vfsStreamBlock; -use bovigo\vfs\vfsStreamDirectory; -use bovigo\vfs\vfsStreamFile; +use bovigo\vfs\vfsBlock; +use bovigo\vfs\vfsDirectory; +use bovigo\vfs\vfsFile; use InvalidArgumentException; use const STDOUT; use function class_alias; @@ -27,7 +27,7 @@ * @since 0.10.0 * @see https://github.com/mikey179/vfsStream/issues/10 */ -class vfsStreamPrintVisitor extends vfsStreamAbstractVisitor +class Printer extends BaseVisitor { /** * target to write output to @@ -63,10 +63,10 @@ public function __construct($out = STDOUT) /** * visit a file and process it * - * @param vfsStreamFile $file - * @return vfsStreamPrintVisitor + * @param vfsFile $file + * @return Printer */ - public function visitFile(vfsStreamFile $file) + public function visitFile(vfsFile $file) { $this->printContent($file->getName()); return $this; @@ -75,10 +75,10 @@ public function visitFile(vfsStreamFile $file) /** * visit a block device and process it * - * @param vfsStreamBlock $block - * @return vfsStreamPrintVisitor + * @param vfsBlock $block + * @return Printer */ - public function visitBlockDevice(vfsStreamBlock $block) + public function visitBlockDevice(vfsBlock $block) { $name = '[' . $block->getName() . ']'; $this->printContent($name); @@ -88,10 +88,10 @@ public function visitBlockDevice(vfsStreamBlock $block) /** * visit a directory and process it * - * @param vfsStreamDirectory $dir - * @return vfsStreamPrintVisitor + * @param vfsDirectory $dir + * @return Printer */ - public function visitDirectory(vfsStreamDirectory $dir) + public function visitDirectory(vfsDirectory $dir) { $this->printContent($dir->getName()); $this->depth++; @@ -114,4 +114,4 @@ protected function printContent($name) } } -class_alias('bovigo\vfs\visitor\vfsStreamPrintVisitor', 'org\bovigo\vfs\visitor\vfsStreamPrintVisitor'); +class_alias('bovigo\vfs\visitor\Printer', 'org\bovigo\vfs\visitor\vfsStreamPrintVisitor'); diff --git a/src/visitor/vfsStreamStructureVisitor.php b/src/visitor/StructureInspector.php similarity index 72% rename from src/visitor/vfsStreamStructureVisitor.php rename to src/visitor/StructureInspector.php index 6617367d..d6e07845 100644 --- a/src/visitor/vfsStreamStructureVisitor.php +++ b/src/visitor/StructureInspector.php @@ -10,9 +10,9 @@ namespace bovigo\vfs\visitor; -use bovigo\vfs\vfsStreamBlock; -use bovigo\vfs\vfsStreamDirectory; -use bovigo\vfs\vfsStreamFile; +use bovigo\vfs\vfsBlock; +use bovigo\vfs\vfsDirectory; +use bovigo\vfs\vfsFile; use function class_alias; /** @@ -21,7 +21,7 @@ * @since 0.10.0 * @see https://github.com/mikey179/vfsStream/issues/10 */ -class vfsStreamStructureVisitor extends vfsStreamAbstractVisitor +class StructureInspector extends BaseVisitor { /** * collected structure @@ -49,10 +49,10 @@ public function __construct() /** * visit a file and process it * - * @param vfsStreamFile $file - * @return vfsStreamStructureVisitor + * @param vfsFile $file + * @return StructureInspector */ - public function visitFile(vfsStreamFile $file) + public function visitFile(vfsFile $file) { $this->current[$file->getName()] = $file->getContent(); return $this; @@ -61,10 +61,10 @@ public function visitFile(vfsStreamFile $file) /** * visit a block device and process it * - * @param vfsStreamBlock $block - * @return vfsStreamStructureVisitor + * @param vfsBlock $block + * @return StructureInspector */ - public function visitBlockDevice(vfsStreamBlock $block) + public function visitBlockDevice(vfsBlock $block) { $this->current['[' . $block->getName() . ']'] = $block->getContent(); return $this; @@ -73,10 +73,10 @@ public function visitBlockDevice(vfsStreamBlock $block) /** * visit a directory and process it * - * @param vfsStreamDirectory $dir - * @return vfsStreamStructureVisitor + * @param vfsDirectory $dir + * @return StructureInspector */ - public function visitDirectory(vfsStreamDirectory $dir) + public function visitDirectory(vfsDirectory $dir) { $this->current[$dir->getName()] = array(); $tmp =& $this->current; @@ -103,7 +103,7 @@ public function getStructure() /** * resets structure so visitor could be reused * - * @return vfsStreamStructureVisitor + * @return StructureInspector */ public function reset() { @@ -113,4 +113,4 @@ public function reset() } } -class_alias('bovigo\vfs\visitor\vfsStreamStructureVisitor', 'org\bovigo\vfs\visitor\vfsStreamStructureVisitor'); +class_alias('bovigo\vfs\visitor\StructureInspector', 'org\bovigo\vfs\visitor\vfsStreamStructureVisitor'); diff --git a/src/visitor/vfsStreamVisitor.php b/src/visitor/vfsStreamVisitor.php index 5b2c0640..4f54d2ba 100644 --- a/src/visitor/vfsStreamVisitor.php +++ b/src/visitor/vfsStreamVisitor.php @@ -10,10 +10,10 @@ namespace bovigo\vfs\visitor; -use bovigo\vfs\vfsStreamBlock; +use bovigo\vfs\vfsBlock; +use bovigo\vfs\vfsDirectory; +use bovigo\vfs\vfsFile; use bovigo\vfs\vfsStreamContent; -use bovigo\vfs\vfsStreamDirectory; -use bovigo\vfs\vfsStreamFile; use function class_alias; /** @@ -35,26 +35,26 @@ public function visit(vfsStreamContent $content); /** * visit a file and process it * - * @param vfsStreamFile $file + * @param vfsFile $file * @return vfsStreamVisitor */ - public function visitFile(vfsStreamFile $file); + public function visitFile(vfsFile $file); /** * visit a directory and process it * - * @param vfsStreamDirectory $dir + * @param vfsDirectory $dir * @return vfsStreamVisitor */ - public function visitDirectory(vfsStreamDirectory $dir); + public function visitDirectory(vfsDirectory $dir); /** * visit a block device and process it * - * @param vfsStreamBlock $block + * @param vfsBlock $block * @return vfsStreamVisitor */ - public function visitBlockDevice(vfsStreamBlock $block); + public function visitBlockDevice(vfsBlock $block); } class_alias('bovigo\vfs\visitor\vfsStreamVisitor', 'org\bovigo\vfs\visitor\vfsStreamVisitor'); diff --git a/tests/phpunit/BasicFileTestCase.php b/tests/phpunit/BasicFileTestCase.php new file mode 100644 index 00000000..80c31693 --- /dev/null +++ b/tests/phpunit/BasicFileTestCase.php @@ -0,0 +1,1067 @@ +assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function executePermissionsForUser() + { + $abstractContent = new TestBasicFile('foo', 0100); + $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertTrue($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function executePermissionsForGroup() + { + $abstractContent = new TestBasicFile('foo', 0010); + $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function executePermissionsForOther() + { + $abstractContent = new TestBasicFile('foo', 0001); + $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function writePermissionsForUser() + { + $abstractContent = new TestBasicFile('foo', 0200); + $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertTrue($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function writePermissionsForGroup() + { + $abstractContent = new TestBasicFile('foo', 0020); + $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function writePermissionsForOther() + { + $abstractContent = new TestBasicFile('foo', 0002); + $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function executeAndWritePermissionsForUser() + { + $abstractContent = new TestBasicFile('foo', 0300); + $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertTrue($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertTrue($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function executeAndWritePermissionsForGroup() + { + $abstractContent = new TestBasicFile('foo', 0030); + $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function executeAndWritePermissionsForOther() + { + $abstractContent = new TestBasicFile('foo', 0003); + $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function readPermissionsForUser() + { + $abstractContent = new TestBasicFile('foo', 0400); + $this->assertTrue($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function readPermissionsForGroup() + { + $abstractContent = new TestBasicFile('foo', 0040); + $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function readPermissionsForOther() + { + $abstractContent = new TestBasicFile('foo', 0004); + $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function readAndExecutePermissionsForUser() + { + $abstractContent = new TestBasicFile('foo', 0500); + $this->assertTrue($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertTrue($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function readAndExecutePermissionsForGroup() + { + $abstractContent = new TestBasicFile('foo', 0050); + $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function readAndExecutePermissionsForOther() + { + $abstractContent = new TestBasicFile('foo', 0005); + $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function readAndWritePermissionsForUser() + { + $abstractContent = new TestBasicFile('foo', 0600); + $this->assertTrue($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertTrue($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function readAndWritePermissionsForGroup() + { + $abstractContent = new TestBasicFile('foo', 0060); + $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function readAndWritePermissionsForOther() + { + $abstractContent = new TestBasicFile('foo', 0006); + $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function allPermissionsForUser() + { + $abstractContent = new TestBasicFile('foo', 0700); + $this->assertTrue($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertTrue($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertTrue($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function allPermissionsForGroup() + { + $abstractContent = new TestBasicFile('foo', 0070); + $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + -1 + ) + ); + } + + /** + * @test + * @group permissions + * @group bug_15 + */ + public function allPermissionsForOther() + { + $abstractContent = new TestBasicFile('foo', 0007); + $this->assertFalse($abstractContent->isReadable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isReadable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isReadable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isWritable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isWritable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isWritable(-1, + -1 + ) + ); + $this->assertFalse($abstractContent->isExecutable(vfsStream::getCurrentUser(), + vfsStream::getCurrentGroup() + ) + ); + $this->assertFalse($abstractContent->isExecutable(-1, + vfsStream::getCurrentGroup() + ) + ); + $this->assertTrue($abstractContent->isExecutable(-1, + -1 + ) + ); + } +} diff --git a/tests/phpunit/PermissionsTestCase.php b/tests/phpunit/PermissionsTestCase.php index 145b7a32..3d45724c 100644 --- a/tests/phpunit/PermissionsTestCase.php +++ b/tests/phpunit/PermissionsTestCase.php @@ -11,7 +11,7 @@ namespace bovigo\vfs\tests; use bovigo\vfs\vfsStream; -use bovigo\vfs\vfsStreamDirectory; +use bovigo\vfs\vfsDirectory; use PHPUnit\Framework\TestCase; use function bovigo\assert\assertFalse; use function bovigo\assert\expect; @@ -28,7 +28,7 @@ class PermissionsTestCase extends \BC_PHPUnit_Framework_TestCase { /** - * @type vfsStreamDirectory + * @type vfsDirectory */ private $root; diff --git a/tests/phpunit/UmaskTestCase.php b/tests/phpunit/UmaskTestCase.php new file mode 100644 index 00000000..2b14588f --- /dev/null +++ b/tests/phpunit/UmaskTestCase.php @@ -0,0 +1,205 @@ +assertEquals(vfsStream::umask(), + vfsStream::umask() + ); + $this->assertEquals(0000, + vfsStream::umask() + ); + } + + /** + * @test + */ + public function changingUmaskSettingReturnsOldUmaskSetting() + { + $this->assertEquals(0000, + vfsStream::umask(0022) + ); + $this->assertEquals(0022, + vfsStream::umask() + ); + } + + /** + * @test + */ + public function createFileWithDefaultUmaskSetting() + { + $file = new vfsFile('foo'); + $this->assertEquals(0666, $file->getPermissions()); + } + + /** + * @test + */ + public function createFileWithDifferentUmaskSetting() + { + vfsStream::umask(0022); + $file = new vfsFile('foo'); + $this->assertEquals(0644, $file->getPermissions()); + } + + /** + * @test + */ + public function createDirectoryWithDefaultUmaskSetting() + { + $directory = new vfsDirectory('foo'); + $this->assertEquals(0777, $directory->getPermissions()); + } + + /** + * @test + */ + public function createDirectoryWithDifferentUmaskSetting() + { + vfsStream::umask(0022); + $directory = new vfsDirectory('foo'); + $this->assertEquals(0755, $directory->getPermissions()); + } + + /** + * @test + */ + public function createFileUsingStreamWithDefaultUmaskSetting() + { + $root = vfsStream::setup(); + file_put_contents(vfsStream::url('root/newfile.txt'), 'file content'); + $this->assertEquals(0666, $root->getChild('newfile.txt')->getPermissions()); + } + + /** + * @test + */ + public function createFileUsingStreamWithDifferentUmaskSetting() + { + $root = vfsStream::setup(); + vfsStream::umask(0022); + file_put_contents(vfsStream::url('root/newfile.txt'), 'file content'); + $this->assertEquals(0644, $root->getChild('newfile.txt')->getPermissions()); + } + + /** + * @test + */ + public function createDirectoryUsingStreamWithDefaultUmaskSetting() + { + $root = vfsStream::setup(); + mkdir(vfsStream::url('root/newdir')); + $this->assertEquals(0777, $root->getChild('newdir')->getPermissions()); + } + + /** + * @test + */ + public function createDirectoryUsingStreamWithDifferentUmaskSetting() + { + $root = vfsStream::setup(); + vfsStream::umask(0022); + mkdir(vfsStream::url('root/newdir')); + $this->assertEquals(0755, $root->getChild('newdir')->getPermissions()); + } + + /** + * @test + */ + public function createDirectoryUsingStreamWithExplicit0() + { + $root = vfsStream::setup(); + vfsStream::umask(0022); + mkdir(vfsStream::url('root/newdir'), null); + $this->assertEquals(0000, $root->getChild('newdir')->getPermissions()); + } + + /** + * @test + * + */ + public function createDirectoryUsingStreamWithDifferentUmaskSettingButExplicit0777() + { + $root = vfsStream::setup(); + vfsStream::umask(0022); + mkdir(vfsStream::url('root/newdir'), 0777); + $this->assertEquals(0755, $root->getChild('newdir')->getPermissions()); + } + + /** + * @test + */ + public function createDirectoryUsingStreamWithDifferentUmaskSettingButExplicitModeRequestedByCall() + { + $root = vfsStream::setup(); + vfsStream::umask(0022); + mkdir(vfsStream::url('root/newdir'), 0700); + $this->assertEquals(0700, $root->getChild('newdir')->getPermissions()); + } + + /** + * @test + */ + public function defaultUmaskSettingDoesNotInfluenceSetup() + { + $root = vfsStream::setup(); + $this->assertEquals(0777, $root->getPermissions()); + } + + /** + * @test + */ + public function umaskSettingShouldBeRespectedBySetup() + { + vfsStream::umask(0022); + $root = vfsStream::setup(); + $this->assertEquals(0755, $root->getPermissions()); + } +} diff --git a/tests/phpunit/vfsBlockTestCase.php b/tests/phpunit/vfsBlockTestCase.php new file mode 100644 index 00000000..e86685a4 --- /dev/null +++ b/tests/phpunit/vfsBlockTestCase.php @@ -0,0 +1,103 @@ +block = new vfsBlock('foo'); + } + + /** + * test default values and methods + * + * @test + */ + public function defaultValues() + { + $this->assertEquals(vfsStreamContent::TYPE_BLOCK, $this->block->getType()); + $this->assertEquals('foo', $this->block->getName()); + $this->assertTrue($this->block->appliesTo('foo')); + $this->assertFalse($this->block->appliesTo('foo/bar')); + $this->assertFalse($this->block->appliesTo('bar')); + } + + /** + * tests how external functions see this object + * + * @test + */ + public function external() + { + $root = vfsStream::setup('root'); + $root->addChild(vfsStream::newBlock('foo')); + $this->assertEquals('block', filetype(vfsStream::url('root/foo'))); + } + + /** + * tests adding a complex structure + * + * @test + */ + public function addStructure() + { + $structure = array( + 'topLevel' => array( + 'thisIsAFile' => 'file contents', + '[blockDevice]' => 'block contents' + ) + ); + + $root = vfsStream::create($structure); + + $this->assertSame('block', filetype(vfsStream::url('root/topLevel/blockDevice'))); + } + + /** + * tests that a blank name for a block device throws an exception + * @test + * @expectedException org\bovigo\vfs\vfsStreamException + */ + public function createWithEmptyName() + { + $structure = array( + 'topLevel' => array( + 'thisIsAFile' => 'file contents', + '[]' => 'block contents' + ) + ); + + $root = vfsStream::create($structure); + } +} diff --git a/tests/phpunit/vfsStreamContainerIteratorTestCase.php b/tests/phpunit/vfsDirectoryIteratorTestCase.php similarity index 92% rename from tests/phpunit/vfsStreamContainerIteratorTestCase.php rename to tests/phpunit/vfsDirectoryIteratorTestCase.php index 17c51e80..ec53a1a0 100644 --- a/tests/phpunit/vfsStreamContainerIteratorTestCase.php +++ b/tests/phpunit/vfsDirectoryIteratorTestCase.php @@ -13,7 +13,7 @@ use bovigo\callmap\NewInstance; use bovigo\vfs\vfsStream; use bovigo\vfs\vfsStreamContent; -use bovigo\vfs\vfsStreamDirectory; +use bovigo\vfs\vfsDirectory; use PHPUnit\Framework\TestCase; use function bovigo\assert\assertFalse; use function bovigo\assert\assertNull; @@ -24,14 +24,14 @@ use function is_string; /** - * Test for bovigo\vfs\vfsStreamContainerIterator. + * Test for bovigo\vfs\vfsDirectoryIterator. */ -class vfsStreamContainerIteratorTestCase extends \BC_PHPUnit_Framework_TestCase +class vfsDirectoryIteratorTestCase extends \BC_PHPUnit_Framework_TestCase { /** * instance to test * - * @type vfsStreamDirectory + * @type vfsDirectory */ private $dir; /** @@ -52,7 +52,7 @@ class vfsStreamContainerIteratorTestCase extends \BC_PHPUnit_Framework_TestCase */ public function setUp() { - $this->dir = new vfsStreamDirectory('foo'); + $this->dir = new vfsDirectory('foo'); $this->mockChild1 = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); $this->mockChild1->expects($this->any()) ->method('getName') diff --git a/tests/phpunit/vfsDirectoryTestCase.php b/tests/phpunit/vfsDirectoryTestCase.php new file mode 100644 index 00000000..d03d790d --- /dev/null +++ b/tests/phpunit/vfsDirectoryTestCase.php @@ -0,0 +1,351 @@ +dir = new vfsDirectory('foo'); + } + + /** + * assure that a directory seperator inside the name throws an exception + * + * @test + * @expectedException org\bovigo\vfs\vfsStreamException + */ + public function invalidCharacterInName() + { + $dir = new vfsDirectory('foo/bar'); + } + + /** + * test default values and methods + * + * @test + */ + public function defaultValues() + { + $this->assertEquals(vfsStreamContent::TYPE_DIR, $this->dir->getType()); + $this->assertEquals('foo', $this->dir->getName()); + $this->assertTrue($this->dir->appliesTo('foo')); + $this->assertTrue($this->dir->appliesTo('foo/bar')); + $this->assertFalse($this->dir->appliesTo('bar')); + $this->assertEquals(array(), $this->dir->getChildren()); + } + + /** + * test renaming the directory + * + * @test + */ + public function rename() + { + $this->dir->rename('bar'); + $this->assertEquals('bar', $this->dir->getName()); + $this->assertFalse($this->dir->appliesTo('foo')); + $this->assertFalse($this->dir->appliesTo('foo/bar')); + $this->assertTrue($this->dir->appliesTo('bar')); + } + + /** + * renaming the directory to an invalid name throws a vfsStreamException + * + * @test + * @expectedException org\bovigo\vfs\vfsStreamException + */ + public function renameToInvalidNameThrowsvfsStreamException() + { + $this->dir->rename('foo/baz'); + } + + /** + * @test + * @since 0.10.0 + */ + public function hasNoChildrenByDefault() + { + $this->assertFalse($this->dir->hasChildren()); + } + + /** + * @test + * @since 0.10.0 + */ + public function hasChildrenReturnsTrueIfAtLeastOneChildPresent() + { + $mockChild = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); + $mockChild->expects($this->any()) + ->method('appliesTo') + ->will($this->returnValue(false)); + $mockChild->expects($this->any()) + ->method('getName') + ->will($this->returnValue('baz')); + $this->dir->addChild($mockChild); + $this->assertTrue($this->dir->hasChildren()); + } + + /** + * @test + */ + public function hasChildReturnsFalseForNonExistingChild() + { + $this->assertFalse($this->dir->hasChild('bar')); + } + + /** + * @test + */ + public function getChildReturnsNullForNonExistingChild() + { + $this->assertNull($this->dir->getChild('bar')); + } + + /** + * @test + */ + public function removeChildReturnsFalseForNonExistingChild() + { + $this->assertFalse($this->dir->removeChild('bar')); + } + + /** + * @test + */ + public function nonExistingChild() + { + $mockChild = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); + $mockChild->expects($this->any()) + ->method('appliesTo') + ->will($this->returnValue(false)); + $mockChild->expects($this->any()) + ->method('getName') + ->will($this->returnValue('baz')); + $this->dir->addChild($mockChild); + $this->assertFalse($this->dir->removeChild('bar')); + } + + /** + * test that adding, handling and removing of a child works as expected + * + * @test + */ + public function childHandling() + { + $mockChild = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); + $mockChild->expects($this->any()) + ->method('getType') + ->will($this->returnValue(vfsStreamContent::TYPE_FILE)); + $mockChild->expects($this->any()) + ->method('getName') + ->will($this->returnValue('bar')); + $mockChild->expects($this->any()) + ->method('appliesTo') + ->with($this->equalTo('bar')) + ->will($this->returnValue(true)); + $mockChild->expects($this->once()) + ->method('size') + ->will($this->returnValue(5)); + $this->dir->addChild($mockChild); + $this->assertTrue($this->dir->hasChild('bar')); + $bar = $this->dir->getChild('bar'); + $this->assertSame($mockChild, $bar); + $this->assertEquals(array($mockChild), $this->dir->getChildren()); + $this->assertEquals(0, $this->dir->size()); + $this->assertEquals(5, $this->dir->sizeSummarized()); + $this->assertTrue($this->dir->removeChild('bar')); + $this->assertEquals(array(), $this->dir->getChildren()); + $this->assertEquals(0, $this->dir->size()); + $this->assertEquals(0, $this->dir->sizeSummarized()); + } + + /** + * test that adding, handling and removing of a child works as expected + * + * @test + */ + public function childHandlingWithSubdirectory() + { + $mockChild = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); + $mockChild->expects($this->any()) + ->method('getType') + ->will($this->returnValue(vfsStreamContent::TYPE_FILE)); + $mockChild->expects($this->any()) + ->method('getName') + ->will($this->returnValue('bar')); + $mockChild->expects($this->once()) + ->method('size') + ->will($this->returnValue(5)); + $subdir = new vfsDirectory('subdir'); + $subdir->addChild($mockChild); + $this->dir->addChild($subdir); + $this->assertTrue($this->dir->hasChild('subdir')); + $this->assertSame($subdir, $this->dir->getChild('subdir')); + $this->assertEquals(array($subdir), $this->dir->getChildren()); + $this->assertEquals(0, $this->dir->size()); + $this->assertEquals(5, $this->dir->sizeSummarized()); + $this->assertTrue($this->dir->removeChild('subdir')); + $this->assertEquals(array(), $this->dir->getChildren()); + $this->assertEquals(0, $this->dir->size()); + $this->assertEquals(0, $this->dir->sizeSummarized()); + } + + /** + * dd + * + * @test + * @group regression + * @group bug_5 + */ + public function addChildReplacesChildWithSameName_Bug_5() + { + $mockChild1 = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); + $mockChild1->expects($this->any()) + ->method('getType') + ->will($this->returnValue(vfsStreamContent::TYPE_FILE)); + $mockChild1->expects($this->any()) + ->method('getName') + ->will($this->returnValue('bar')); + $mockChild2 = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); + $mockChild2->expects($this->any()) + ->method('getType') + ->will($this->returnValue(vfsStreamContent::TYPE_FILE)); + $mockChild2->expects($this->any()) + ->method('getName') + ->will($this->returnValue('bar')); + $this->dir->addChild($mockChild1); + $this->assertTrue($this->dir->hasChild('bar')); + $this->assertSame($mockChild1, $this->dir->getChild('bar')); + $this->dir->addChild($mockChild2); + $this->assertTrue($this->dir->hasChild('bar')); + $this->assertSame($mockChild2, $this->dir->getChild('bar')); + } + + /** + * When testing for a nested path, verify that directory separators are respected properly + * so that subdir1/subdir2 is not considered equal to subdir1Xsubdir2. + * + * @test + * @group bug_24 + * @group regression + */ + public function explicitTestForSeparatorWithNestedPaths_Bug_24() + { + $mockChild = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); + $mockChild->expects($this->any()) + ->method('getType') + ->will($this->returnValue(vfsStreamContent::TYPE_FILE)); + $mockChild->expects($this->any()) + ->method('getName') + ->will($this->returnValue('bar')); + + $subdir1 = new vfsDirectory('subdir1'); + $this->dir->addChild($subdir1); + + $subdir2 = new vfsDirectory('subdir2'); + $subdir1->addChild($subdir2); + + $subdir2->addChild($mockChild); + + $this->assertTrue($this->dir->hasChild('subdir1'), "Level 1 path with separator exists"); + $this->assertTrue($this->dir->hasChild('subdir1/subdir2'), "Level 2 path with separator exists"); + $this->assertTrue($this->dir->hasChild('subdir1/subdir2/bar'), "Level 3 path with separator exists"); + $this->assertFalse($this->dir->hasChild('subdir1.subdir2'), "Path with period does not exist"); + $this->assertFalse($this->dir->hasChild('subdir1.subdir2/bar'), "Nested path with period does not exist"); + } + + + /** + * setting and retrieving permissions for a directory + * + * @test + * @group permissions + */ + public function permissions() + { + $this->assertEquals(0777, $this->dir->getPermissions()); + $this->assertSame($this->dir, $this->dir->chmod(0755)); + $this->assertEquals(0755, $this->dir->getPermissions()); + } + + /** + * setting and retrieving permissions for a directory + * + * @test + * @group permissions + */ + public function permissionsSet() + { + $this->dir = new vfsDirectory('foo', 0755); + $this->assertEquals(0755, $this->dir->getPermissions()); + $this->assertSame($this->dir, $this->dir->chmod(0700)); + $this->assertEquals(0700, $this->dir->getPermissions()); + } + + /** + * setting and retrieving owner of a file + * + * @test + * @group permissions + */ + public function owner() + { + $this->assertEquals(vfsStream::getCurrentUser(), $this->dir->getUser()); + $this->assertTrue($this->dir->isOwnedByUser(vfsStream::getCurrentUser())); + $this->assertSame($this->dir, $this->dir->chown(vfsStream::OWNER_USER_1)); + $this->assertEquals(vfsStream::OWNER_USER_1, $this->dir->getUser()); + $this->assertTrue($this->dir->isOwnedByUser(vfsStream::OWNER_USER_1)); + } + + /** + * setting and retrieving owner group of a file + * + * @test + * @group permissions + */ + public function group() + { + $this->assertEquals(vfsStream::getCurrentGroup(), $this->dir->getGroup()); + $this->assertTrue($this->dir->isOwnedByGroup(vfsStream::getCurrentGroup())); + $this->assertSame($this->dir, $this->dir->chgrp(vfsStream::GROUP_USER_1)); + $this->assertEquals(vfsStream::GROUP_USER_1, $this->dir->getGroup()); + $this->assertTrue($this->dir->isOwnedByGroup(vfsStream::GROUP_USER_1)); + } +} diff --git a/tests/phpunit/vfsStreamAbstractContentTestCase.php b/tests/phpunit/vfsStreamAbstractContentTestCase.php index c7b195dd..381d8e04 100644 --- a/tests/phpunit/vfsStreamAbstractContentTestCase.php +++ b/tests/phpunit/vfsStreamAbstractContentTestCase.php @@ -12,7 +12,7 @@ use bovigo\callmap\NewInstance; use bovigo\vfs\vfsStream; -use bovigo\vfs\vfsStreamAbstractContent; +use org\bovigo\vfs\vfsStreamAbstractContent; use bovigo\vfs\vfsStreamContent; use bovigo\vfs\vfsStreamException; use PHPUnit\Framework\TestCase; diff --git a/tests/phpunit/vfsStreamBlockTestCase.php b/tests/phpunit/vfsStreamBlockTestCase.php index c6d66d1f..c6434ada 100644 --- a/tests/phpunit/vfsStreamBlockTestCase.php +++ b/tests/phpunit/vfsStreamBlockTestCase.php @@ -11,7 +11,7 @@ namespace bovigo\vfs\tests; use bovigo\vfs\vfsStream; -use bovigo\vfs\vfsStreamBlock; +use org\bovigo\vfs\vfsStreamBlock; use bovigo\vfs\vfsStreamContent; use bovigo\vfs\vfsStreamException; use PHPUnit\Framework\TestCase; diff --git a/tests/phpunit/vfsStreamDirectoryIssue134TestCase.php b/tests/phpunit/vfsStreamDirectoryIssue134TestCase.php index 7449f136..86acb89c 100644 --- a/tests/phpunit/vfsStreamDirectoryIssue134TestCase.php +++ b/tests/phpunit/vfsStreamDirectoryIssue134TestCase.php @@ -10,7 +10,7 @@ namespace bovigo\vfs\tests; use bovigo\vfs\vfsStream; -use bovigo\vfs\vfsStreamDirectory; +use org\bovigo\vfs\vfsStreamDirectory; use PHPUnit\Framework\TestCase; use function bovigo\assert\assertNotNull; diff --git a/tests/phpunit/vfsStreamDirectoryIssue18TestCase.php b/tests/phpunit/vfsStreamDirectoryIssue18TestCase.php index fb849c8d..6bb0aa43 100644 --- a/tests/phpunit/vfsStreamDirectoryIssue18TestCase.php +++ b/tests/phpunit/vfsStreamDirectoryIssue18TestCase.php @@ -11,7 +11,7 @@ namespace bovigo\vfs\tests; use bovigo\vfs\vfsStream; -use bovigo\vfs\vfsStreamDirectory; +use org\bovigo\vfs\vfsStreamDirectory; use PHPUnit\Framework\TestCase; use function bovigo\assert\assertThat; use function bovigo\assert\assertTrue; diff --git a/tests/phpunit/vfsStreamDirectoryTestCase.php b/tests/phpunit/vfsStreamDirectoryTestCase.php index 9509ab38..e46c837e 100644 --- a/tests/phpunit/vfsStreamDirectoryTestCase.php +++ b/tests/phpunit/vfsStreamDirectoryTestCase.php @@ -13,7 +13,7 @@ use bovigo\callmap\NewInstance; use bovigo\vfs\vfsStream; use bovigo\vfs\vfsStreamContent; -use bovigo\vfs\vfsStreamDirectory; +use org\bovigo\vfs\vfsStreamDirectory; use bovigo\vfs\vfsStreamException; use PHPUnit\Framework\TestCase; use function bovigo\assert\assertEmptyArray; diff --git a/tests/phpunit/vfsStreamFileTestCase.php b/tests/phpunit/vfsStreamFileTestCase.php index 517365e1..26d4960f 100644 --- a/tests/phpunit/vfsStreamFileTestCase.php +++ b/tests/phpunit/vfsStreamFileTestCase.php @@ -15,7 +15,7 @@ use bovigo\vfs\vfsStream; use bovigo\vfs\vfsStreamContent; use bovigo\vfs\vfsStreamException; -use bovigo\vfs\vfsStreamFile; +use org\bovigo\vfs\vfsStreamFile; use InvalidArgumentException; use PHPUnit\Framework\TestCase; use const SEEK_CUR; diff --git a/tests/phpunit/vfsStreamTestCase.php b/tests/phpunit/vfsStreamTestCase.php index 20811600..c3913164 100644 --- a/tests/phpunit/vfsStreamTestCase.php +++ b/tests/phpunit/vfsStreamTestCase.php @@ -13,10 +13,10 @@ use bovigo\callmap\NewInstance; use bovigo\vfs\content\LargeFileContent; use bovigo\vfs\vfsStream; -use bovigo\vfs\vfsStreamFile; +use bovigo\vfs\vfsFile; use bovigo\vfs\vfsStreamContent; -use bovigo\vfs\vfsStreamDirectory; -use bovigo\vfs\vfsStreamWrapper; +use bovigo\vfs\vfsDirectory; +use bovigo\vfs\StreamWrapper; use bovigo\vfs\visitor\vfsStreamVisitor; use InvalidArgumentException; use PHPUnit\Framework\TestCase; @@ -44,7 +44,7 @@ class vfsStreamTestCase extends \BC_PHPUnit_Framework_TestCase */ public function setUp() { - vfsStreamWrapper::register(); + StreamWrapper::register(); } /** @@ -239,7 +239,7 @@ public function newDirectoryWithSlashAtStart() public function setupRegistersStreamWrapperAndCreatesRootDirectoryWithDefaultNameAndPermissions() { $root = vfsStream::setup(); - $this->assertSame($root, vfsStreamWrapper::getRoot()); + $this->assertSame($root, StreamWrapper::getRoot()); $this->assertEquals('root', $root->getName()); $this->assertEquals(0777, $root->getPermissions()); } @@ -252,7 +252,7 @@ public function setupRegistersStreamWrapperAndCreatesRootDirectoryWithDefaultNam public function setupRegistersStreamWrapperAndCreatesRootDirectoryWithGivenNameAndDefaultPermissions() { $root = vfsStream::setup('foo'); - $this->assertSame($root, vfsStreamWrapper::getRoot()); + $this->assertSame($root, StreamWrapper::getRoot()); $this->assertEquals('foo', $root->getName()); $this->assertEquals(0777, $root->getPermissions()); } @@ -265,7 +265,7 @@ public function setupRegistersStreamWrapperAndCreatesRootDirectoryWithGivenNameA public function setupRegistersStreamWrapperAndCreatesRootDirectoryWithGivenNameAndPermissions() { $root = vfsStream::setup('foo', 0444); - $this->assertSame($root, vfsStreamWrapper::getRoot()); + $this->assertSame($root, StreamWrapper::getRoot()); $this->assertEquals('foo', $root->getName()); $this->assertEquals(0444, $root->getPermissions()); } @@ -381,7 +381,7 @@ public function setupCastsNumericDirectoriesToStrings() */ public function createArraysAreTurnedIntoSubdirectories() { - $baseDir = vfsStream::create(array('test' => array()), new vfsStreamDirectory('baseDir')); + $baseDir = vfsStream::create(array('test' => array()), new vfsDirectory('baseDir')); $this->assertTrue($baseDir->hasChildren()); $this->assertTrue($baseDir->hasChild('test')); $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamDirectory', @@ -429,7 +429,7 @@ public function createWorksRecursively() 'baz.txt' => 'world' ) ), - new vfsStreamDirectory('baseDir') + new vfsDirectory('baseDir') ); $this->assertTrue($baseDir->hasChildren()); $this->assertTrue($baseDir->hasChild('test')); @@ -485,7 +485,7 @@ public function createWorksRecursivelyWithRoot() */ public function createStringsAreTurnedIntoFilesWithContent() { - $baseDir = vfsStream::create(array('test.txt' => 'some content'), new vfsStreamDirectory('baseDir')); + $baseDir = vfsStream::create(array('test.txt' => 'some content'), new vfsDirectory('baseDir')); $this->assertTrue($baseDir->hasChildren()); $this->assertTrue($baseDir->hasChild('test.txt')); $this->assertVfsFile($baseDir->getChild('test.txt'), 'some content'); @@ -514,7 +514,7 @@ public function createStringsAreTurnedIntoFilesWithContentWithRoot() */ public function createCastsNumericDirectoriesToStrings() { - $baseDir = vfsStream::create(array(2011 => array ('test.txt' => 'some content')), new vfsStreamDirectory('baseDir')); + $baseDir = vfsStream::create(array(2011 => array ('test.txt' => 'some content')), new vfsDirectory('baseDir')); $this->assertTrue($baseDir->hasChild('2011')); $directory = $baseDir->getChild('2011'); @@ -539,14 +539,14 @@ public function createCastsNumericDirectoriesToStringsWithRoot() } /** - * helper function for assertions on vfsStreamFile + * helper function for assertions on vfsFile * - * @param vfsStreamFile $file + * @param vfsFile $file * @param string $content */ - protected function assertVfsFile(vfsStreamFile $file, $content) + protected function assertVfsFile(vfsFile $file, $content) { - $this->assertInstanceOf('org\\bovigo\\vfs\\vfsStreamFile', + $this->assertInstanceOf('bovigo\\vfs\\vfsFile', $file ); $this->assertEquals($content, diff --git a/tests/phpunit/vfsStreamUmaskTestCase.php b/tests/phpunit/vfsStreamUmaskTestCase.php index 35e4798c..626a83ad 100644 --- a/tests/phpunit/vfsStreamUmaskTestCase.php +++ b/tests/phpunit/vfsStreamUmaskTestCase.php @@ -11,8 +11,8 @@ namespace bovigo\vfs\tests; use bovigo\vfs\vfsStream; -use bovigo\vfs\vfsStreamFile; -use bovigo\vfs\vfsStreamDirectory; +use org\bovigo\vfs\vfsStreamFile; +use org\bovigo\vfs\vfsStreamDirectory; use PHPUnit\Framework\TestCase; use function bovigo\assert\assertThat; use function bovigo\assert\predicate\equals; diff --git a/tests/phpunit/vfsStreamWrapperAlreadyRegisteredTestCase.php b/tests/phpunit/vfsStreamWrapperAlreadyRegisteredTestCase.php index 4084441d..e48f83ce 100644 --- a/tests/phpunit/vfsStreamWrapperAlreadyRegisteredTestCase.php +++ b/tests/phpunit/vfsStreamWrapperAlreadyRegisteredTestCase.php @@ -13,7 +13,7 @@ use bovigo\callmap\NewInstance; use bovigo\vfs\vfsStream; use bovigo\vfs\vfsStreamException; -use bovigo\vfs\vfsStreamWrapper; +use bovigo\vfs\StreamWrapper; use PHPUnit\Framework\TestCase; use function bovigo\assert\expect; use function in_array; @@ -24,10 +24,10 @@ /** * Helper class for the test. */ -class TestvfsStreamWrapper extends vfsStreamWrapper +class TestvfsStreamWrapper extends StreamWrapper { /** - * unregisters vfsStreamWrapper + * unregisters StreamWrapper */ public static function unregister() { @@ -70,6 +70,6 @@ public function tearDown() */ public function registerOverAnotherStreamWrapper() { - vfsStreamWrapper::register(); + StreamWrapper::register(); } } diff --git a/tests/phpunit/vfsStreamWrapperBaseTestCase.php b/tests/phpunit/vfsStreamWrapperBaseTestCase.php index db61b310..90bb5c78 100644 --- a/tests/phpunit/vfsStreamWrapperBaseTestCase.php +++ b/tests/phpunit/vfsStreamWrapperBaseTestCase.php @@ -11,20 +11,20 @@ namespace bovigo\vfs\tests; use bovigo\vfs\vfsStream; -use bovigo\vfs\vfsStreamDirectory; +use bovigo\vfs\vfsDirectory; use bovigo\vfs\vfsStreamFile; -use bovigo\vfs\vfsStreamWrapper; +use bovigo\vfs\StreamWrapper; use PHPUnit\Framework\TestCase; /** - * Test for bovigo\vfs\vfsStreamWrapper. + * Test for bovigo\vfs\StreamWrapper. */ abstract class vfsStreamWrapperBaseTestCase extends \BC_PHPUnit_Framework_TestCase { /** * root directory * - * @var vfsStreamDirectory + * @var vfsDirectory */ protected $foo; /** @@ -36,7 +36,7 @@ abstract class vfsStreamWrapperBaseTestCase extends \BC_PHPUnit_Framework_TestCa /** * sub directory * - * @var vfsStreamDirectory + * @var vfsDirectory */ protected $bar; /** @@ -79,8 +79,8 @@ public function setUp() $this->barURL = vfsStream::url('foo/bar'); $this->baz1URL = vfsStream::url('foo/bar/baz1'); $this->baz2URL = vfsStream::url('foo/baz2'); - $this->foo = new vfsStreamDirectory('foo'); - $this->bar = new vfsStreamDirectory('bar'); + $this->foo = new vfsDirectory('foo'); + $this->bar = new vfsDirectory('bar'); $this->baz1 = vfsStream::newFile('baz1') ->lastModified(300) ->lastAccessed(300) @@ -100,7 +100,7 @@ public function setUp() $this->bar->lastModified(200) ->lastAccessed(100) ->lastAttributeModified(100); - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot($this->foo); + StreamWrapper::register(); + StreamWrapper::setRoot($this->foo); } } diff --git a/tests/phpunit/vfsStreamWrapperDirTestCase.php b/tests/phpunit/vfsStreamWrapperDirTestCase.php index 5cb69bfe..4fe79ff7 100644 --- a/tests/phpunit/vfsStreamWrapperDirTestCase.php +++ b/tests/phpunit/vfsStreamWrapperDirTestCase.php @@ -12,8 +12,8 @@ use bovigo\vfs\vfsStream; use bovigo\vfs\vfsStreamContent; -use bovigo\vfs\vfsStreamDirectory; -use bovigo\vfs\vfsStreamWrapper; +use bovigo\vfs\vfsDirectory; +use bovigo\vfs\StreamWrapper; use const E_USER_WARNING; use function bovigo\assert\assertFalse; use function bovigo\assert\assertNotNull; @@ -48,7 +48,7 @@ public function mkdirNoNewRoot() { $this->assertFalse(mkdir(vfsStream::url('another'))); $this->assertEquals(2, count($this->foo->getChildren())); - $this->assertSame($this->foo, vfsStreamWrapper::getRoot()); + $this->assertSame($this->foo, StreamWrapper::getRoot()); } /** @@ -60,7 +60,7 @@ public function mkdirNoNewRootRecursively() { $this->assertFalse(mkdir(vfsStream::url('another/more'), 0777, true)); $this->assertEquals(2, count($this->foo->getChildren())); - $this->assertSame($this->foo, vfsStreamWrapper::getRoot()); + $this->assertSame($this->foo, StreamWrapper::getRoot()); } /** @@ -114,11 +114,11 @@ public function mkdirWithDots() */ public function mkdirWithoutRootCreatesNewRoot() { - vfsStreamWrapper::register(); + StreamWrapper::register(); $this->assertTrue(@mkdir(vfsStream::url('foo'))); - $this->assertEquals(vfsStreamContent::TYPE_DIR, vfsStreamWrapper::getRoot()->getType()); - $this->assertEquals('foo', vfsStreamWrapper::getRoot()->getName()); - $this->assertEquals(0777, vfsStreamWrapper::getRoot()->getPermissions()); + $this->assertEquals(vfsStreamContent::TYPE_DIR, StreamWrapper::getRoot()->getType()); + $this->assertEquals('foo', StreamWrapper::getRoot()->getName()); + $this->assertEquals(0777, StreamWrapper::getRoot()->getPermissions()); } /** @@ -184,11 +184,11 @@ public function mkdirRecursivelyUsesDefaultPermissions() */ public function mkdirWithoutRootCreatesNewRootDifferentPermissions() { - vfsStreamWrapper::register(); + StreamWrapper::register(); $this->assertTrue(@mkdir(vfsStream::url('foo'), 0755)); - $this->assertEquals(vfsStreamContent::TYPE_DIR, vfsStreamWrapper::getRoot()->getType()); - $this->assertEquals('foo', vfsStreamWrapper::getRoot()->getName()); - $this->assertEquals(0755, vfsStreamWrapper::getRoot()->getPermissions()); + $this->assertEquals(vfsStreamContent::TYPE_DIR, StreamWrapper::getRoot()->getType()); + $this->assertEquals('foo', StreamWrapper::getRoot()->getName()); + $this->assertEquals(0755, StreamWrapper::getRoot()->getPermissions()); } /** @@ -199,11 +199,11 @@ public function mkdirWithoutRootCreatesNewRootDifferentPermissions() */ public function mkdirWithoutRootCreatesNewRootWithDefaultPermissions() { - vfsStreamWrapper::register(); + StreamWrapper::register(); $this->assertTrue(@mkdir(vfsStream::url('foo'))); - $this->assertEquals(vfsStreamContent::TYPE_DIR, vfsStreamWrapper::getRoot()->getType()); - $this->assertEquals('foo', vfsStreamWrapper::getRoot()->getName()); - $this->assertEquals(0777, vfsStreamWrapper::getRoot()->getPermissions()); + $this->assertEquals(vfsStreamContent::TYPE_DIR, StreamWrapper::getRoot()->getType()); + $this->assertEquals('foo', StreamWrapper::getRoot()->getName()); + $this->assertEquals(0777, StreamWrapper::getRoot()->getPermissions()); } /** @@ -213,12 +213,12 @@ public function mkdirWithoutRootCreatesNewRootWithDefaultPermissions() */ public function mkdirDirCanNotCreateNewDirInNonWritingDirectory() { - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot(new vfsStreamDirectory('root')); - vfsStreamWrapper::getRoot()->addChild(new vfsStreamDirectory('restrictedFolder', 0000)); + StreamWrapper::register(); + StreamWrapper::setRoot(new vfsDirectory('root')); + StreamWrapper::getRoot()->addChild(new vfsDirectory('restrictedFolder', 0000)); $this->assertFalse(is_writable(vfsStream::url('root/restrictedFolder/'))); $this->assertFalse(mkdir(vfsStream::url('root/restrictedFolder/newFolder'))); - $this->assertFalse(vfsStreamWrapper::getRoot()->hasChild('restrictedFolder/newFolder')); + $this->assertFalse(StreamWrapper::getRoot()->hasChild('restrictedFolder/newFolder')); } /** @@ -291,8 +291,8 @@ public function allowsRecursiveMkDirWithDirectoryName0() */ public function canNotIterateOverNonReadableDirectory() { - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot(new vfsStreamDirectory('root', 0000)); + StreamWrapper::register(); + StreamWrapper::setRoot(new vfsDirectory('root', 0000)); $this->assertFalse(@opendir(vfsStream::url('root'))); $this->assertFalse(@dir(vfsStream::url('root'))); } @@ -321,7 +321,7 @@ public function is_dir() */ public function canNotUnlinkDirectoryWithoutRoot() { - vfsStreamWrapper::register(); + StreamWrapper::register(); $this->assertFalse(@rmdir(vfsStream::url('foo'))); } @@ -390,7 +390,7 @@ public function rmdirCanRemoveEmptyRoot() $this->foo->removeChild('baz2'); $this->assertTrue(rmdir($this->fooURL)); $this->assertFalse(file_exists($this->fooURL)); // make sure statcache was cleared - $this->assertNull(vfsStreamWrapper::getRoot()); + $this->assertNull(StreamWrapper::getRoot()); } /** @@ -400,12 +400,12 @@ public function rmdirCanRemoveEmptyRoot() */ public function rmdirDirCanNotRemoveDirFromNonWritingDirectory() { - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot(new vfsStreamDirectory('root', 0000)); - vfsStreamWrapper::getRoot()->addChild(new vfsStreamDirectory('nonRemovableFolder')); + StreamWrapper::register(); + StreamWrapper::setRoot(new vfsDirectory('root', 0000)); + StreamWrapper::getRoot()->addChild(new vfsDirectory('nonRemovableFolder')); $this->assertFalse(is_writable(vfsStream::url('root'))); $this->assertFalse(rmdir(vfsStream::url('root/nonRemovableFolder'))); - $this->assertTrue(vfsStreamWrapper::getRoot()->hasChild('nonRemovableFolder')); + $this->assertTrue(StreamWrapper::getRoot()->hasChild('nonRemovableFolder')); } /** @@ -415,12 +415,12 @@ public function rmdirDirCanNotRemoveDirFromNonWritingDirectory() */ public function issue17() { - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot(new vfsStreamDirectory('root', 0770)); - vfsStreamWrapper::getRoot()->chgrp(vfsStream::GROUP_USER_1) + StreamWrapper::register(); + StreamWrapper::setRoot(new vfsDirectory('root', 0770)); + StreamWrapper::getRoot()->chgrp(vfsStream::GROUP_USER_1) ->chown(vfsStream::OWNER_USER_1); $this->assertFalse(mkdir(vfsStream::url('root/doesNotWork'))); - $this->assertFalse(vfsStreamWrapper::getRoot()->hasChild('doesNotWork')); + $this->assertFalse(StreamWrapper::getRoot()->hasChild('doesNotWork')); } /** @@ -451,7 +451,7 @@ public function accessWithExcessDoubleDotsReturnsCorrectContent() */ public function alwaysResolvesRootDirectoryAsOwnParentWithDoubleDot() { - vfsStreamWrapper::getRoot()->chown(vfsStream::OWNER_USER_1); + StreamWrapper::getRoot()->chown(vfsStream::OWNER_USER_1); $this->assertTrue(is_dir(vfsStream::url('foo/..'))); $stat = stat(vfsStream::url('foo/..')); diff --git a/tests/phpunit/vfsStreamWrapperFileTestCase.php b/tests/phpunit/vfsStreamWrapperFileTestCase.php index 1de05ca4..b0bde50d 100644 --- a/tests/phpunit/vfsStreamWrapperFileTestCase.php +++ b/tests/phpunit/vfsStreamWrapperFileTestCase.php @@ -11,8 +11,8 @@ namespace bovigo\vfs\tests; use bovigo\vfs\vfsStream; -use bovigo\vfs\vfsStreamDirectory; -use bovigo\vfs\vfsStreamWrapper; +use bovigo\vfs\vfsDirectory; +use bovigo\vfs\StreamWrapper; use const SEEK_CUR; use const SEEK_END; use const SEEK_SET; @@ -35,7 +35,7 @@ use function unlink; /** - * Test for bovigo\vfs\vfsStreamWrapper. + * Test for bovigo\vfs\StreamWrapper. */ class vfsStreamWrapperFileTestCase extends vfsStreamWrapperBaseTestCase { @@ -59,9 +59,9 @@ public function file_get_contents() */ public function file_get_contentsNonReadableFile() { - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot(new vfsStreamDirectory('root')); - vfsStream::newFile('new.txt', 0000)->at(vfsStreamWrapper::getRoot())->withContent('content'); + StreamWrapper::register(); + StreamWrapper::setRoot(new vfsDirectory('root')); + vfsStream::newFile('new.txt', 0000)->at(StreamWrapper::getRoot())->withContent('content'); $this->assertEquals('', @file_get_contents(vfsStream::url('root/new.txt'))); } @@ -87,9 +87,9 @@ public function file_put_contentsExistingFile() */ public function file_put_contentsExistingFileNonWritableDirectory() { - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot(new vfsStreamDirectory('root', 0000)); - vfsStream::newFile('new.txt')->at(vfsStreamWrapper::getRoot())->withContent('content'); + StreamWrapper::register(); + StreamWrapper::setRoot(new vfsDirectory('root', 0000)); + vfsStream::newFile('new.txt')->at(StreamWrapper::getRoot())->withContent('content'); $this->assertEquals(15, @file_put_contents(vfsStream::url('root/new.txt'), 'This does work.')); $this->assertEquals('This does work.', file_get_contents(vfsStream::url('root/new.txt'))); @@ -102,9 +102,9 @@ public function file_put_contentsExistingFileNonWritableDirectory() */ public function file_put_contentsExistingNonWritableFile() { - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot(new vfsStreamDirectory('root')); - vfsStream::newFile('new.txt', 0400)->at(vfsStreamWrapper::getRoot())->withContent('content'); + StreamWrapper::register(); + StreamWrapper::setRoot(new vfsDirectory('root')); + vfsStream::newFile('new.txt', 0400)->at(StreamWrapper::getRoot())->withContent('content'); $this->assertFalse(@file_put_contents(vfsStream::url('root/new.txt'), 'This does not work.')); $this->assertEquals('content', file_get_contents(vfsStream::url('root/new.txt'))); } @@ -129,8 +129,8 @@ public function file_put_contentsNonExistingFile() */ public function file_put_contentsNonExistingFileNonWritableDirectory() { - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot(new vfsStreamDirectory('root', 0000)); + StreamWrapper::register(); + StreamWrapper::setRoot(new vfsDirectory('root', 0000)); $this->assertFalse(@file_put_contents(vfsStream::url('root/new.txt'), 'This does not work.')); $this->assertFalse(file_exists(vfsStream::url('root/new.txt'))); @@ -333,9 +333,9 @@ public function canNotReadFromWriteOnlyFileWithModeX() */ public function canNotRemoveFileFromDirectoryWithoutWritePermissions() { - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot(new vfsStreamDirectory('root', 0000)); - vfsStream::newFile('new.txt')->at(vfsStreamWrapper::getRoot()); + StreamWrapper::register(); + StreamWrapper::setRoot(new vfsDirectory('root', 0000)); + vfsStream::newFile('new.txt')->at(StreamWrapper::getRoot()); $this->assertFalse(unlink(vfsStream::url('root/new.txt'))); $this->assertTrue(file_exists(vfsStream::url('root/new.txt'))); } diff --git a/tests/phpunit/vfsStreamWrapperFileTimesTestCase.php b/tests/phpunit/vfsStreamWrapperFileTimesTestCase.php index 401c049b..0925af62 100644 --- a/tests/phpunit/vfsStreamWrapperFileTimesTestCase.php +++ b/tests/phpunit/vfsStreamWrapperFileTimesTestCase.php @@ -12,8 +12,7 @@ use bovigo\vfs\vfsStream; use bovigo\vfs\vfsStreamContent; -use bovigo\vfs\vfsStreamDirectory; -use bovigo\vfs\vfsStreamWrapper; +use bovigo\vfs\StreamWrapper; use PHPUnit\Framework\TestCase; use function bovigo\assert\assertThat; use function bovigo\assert\predicate\equals; @@ -32,7 +31,7 @@ use function unlink; /** - * Test for bovigo\vfs\vfsStreamWrapper. + * Test for bovigo\vfs\StreamWrapper. * * @since 0.9.0 */ @@ -93,7 +92,7 @@ public function openFileChangesAttributeTimeOnly() { $file = vfsStream::newFile('foo.txt') ->withContent('test') - ->at(vfsStreamWrapper::getRoot()) + ->at(StreamWrapper::getRoot()) ->lastModified(100) ->lastAccessed(100) ->lastAttributeModified(100); @@ -114,7 +113,7 @@ public function fileGetContentsChangesAttributeTimeOnly() { $file = vfsStream::newFile('foo.txt') ->withContent('test') - ->at(vfsStreamWrapper::getRoot()) + ->at(StreamWrapper::getRoot()) ->lastModified(100) ->lastAccessed(100) ->lastAttributeModified(100); @@ -135,7 +134,7 @@ public function openFileWithTruncateChangesAttributeAndModificationTime() { $file = vfsStream::newFile('foo.txt') ->withContent('test') - ->at(vfsStreamWrapper::getRoot()) + ->at(StreamWrapper::getRoot()) ->lastModified(100) ->lastAccessed(100) ->lastAttributeModified(100); @@ -156,7 +155,7 @@ public function readFileChangesAccessTime() { $file = vfsStream::newFile('foo.txt') ->withContent('test') - ->at(vfsStreamWrapper::getRoot()) + ->at(StreamWrapper::getRoot()) ->lastModified(100) ->lastAccessed(100) ->lastAttributeModified(100); @@ -178,7 +177,7 @@ public function readFileChangesAccessTime() public function writeFileChangesModificationTime() { $file = vfsStream::newFile('foo.txt') - ->at(vfsStreamWrapper::getRoot()) + ->at(StreamWrapper::getRoot()) ->lastModified(100) ->lastAccessed(100) ->lastAttributeModified(100); @@ -204,7 +203,7 @@ public function createNewFileSetsAllTimesToCurrentTime() $this->assertLessThanOrEqual(time(), filemtime($this->fooUrl)); $this->assertEquals(fileatime($this->fooUrl), filectime($this->fooUrl)); $this->assertEquals(fileatime($this->fooUrl), filemtime($this->fooUrl)); - $this->assertFileTimesEqualStreamTimes($this->fooUrl, vfsStreamWrapper::getRoot()->getChild('foo.txt')); + $this->assertFileTimesEqualStreamTimes($this->fooUrl, StreamWrapper::getRoot()->getChild('foo.txt')); } /** @@ -214,7 +213,7 @@ public function createNewFileSetsAllTimesToCurrentTime() public function createNewFileChangesAttributeAndModificationTimeOfContainingDirectory() { $dir = vfsStream::newDirectory('bar') - ->at(vfsStreamWrapper::getRoot()) + ->at(StreamWrapper::getRoot()) ->lastModified(100) ->lastAccessed(100) ->lastAttributeModified(100); @@ -250,7 +249,7 @@ public function addNewFileNameWithLinkFunctionChangesAttributeAndModificationTim public function removeFileChangesAttributeAndModificationTimeOfContainingDirectory() { $dir = vfsStream::newDirectory('bar') - ->at(vfsStreamWrapper::getRoot()); + ->at(StreamWrapper::getRoot()); $file = vfsStream::newFile('baz.txt') ->at($dir) ->lastModified(100) @@ -273,12 +272,12 @@ public function removeFileChangesAttributeAndModificationTimeOfContainingDirecto public function renameFileChangesAttributeAndModificationTimeOfAffectedDirectories() { $target = vfsStream::newDirectory('target') - ->at(vfsStreamWrapper::getRoot()) + ->at(StreamWrapper::getRoot()) ->lastModified(200) ->lastAccessed(200) ->lastAttributeModified(200); $source = vfsStream::newDirectory('bar') - ->at(vfsStreamWrapper::getRoot()); + ->at(StreamWrapper::getRoot()); $file = vfsStream::newFile('baz.txt') ->at($source) ->lastModified(300) @@ -305,12 +304,12 @@ public function renameFileChangesAttributeAndModificationTimeOfAffectedDirectori public function renameFileDoesNotChangeFileTimesOfFileItself() { $target = vfsStream::newDirectory('target') - ->at(vfsStreamWrapper::getRoot()) + ->at(StreamWrapper::getRoot()) ->lastModified(200) ->lastAccessed(200) ->lastAttributeModified(200); $source = vfsStream::newDirectory('bar') - ->at(vfsStreamWrapper::getRoot()); + ->at(StreamWrapper::getRoot()); $file = vfsStream::newFile('baz.txt') ->at($source) ->lastModified(300) diff --git a/tests/phpunit/vfsStreamWrapperLargeFileTestCase.php b/tests/phpunit/vfsStreamWrapperLargeFileTestCase.php index 6f39f3ab..49e98238 100644 --- a/tests/phpunit/vfsStreamWrapperLargeFileTestCase.php +++ b/tests/phpunit/vfsStreamWrapperLargeFileTestCase.php @@ -12,7 +12,7 @@ use bovigo\vfs\content\LargeFileContent; use bovigo\vfs\vfsStream; -use bovigo\vfs\vfsStreamFile; +use bovigo\vfs\vfsFile; use PHPUnit\Framework\TestCase; use const PHP_INT_MAX; use const SEEK_SET; @@ -39,7 +39,7 @@ class vfsStreamWrapperLargeFileTestCase extends \BC_PHPUnit_Framework_TestCase /** * large file to test * - * @var vfsStreamFile + * @var vfsFile */ private $largeFile; diff --git a/tests/phpunit/vfsStreamWrapperQuotaTestCase.php b/tests/phpunit/vfsStreamWrapperQuotaTestCase.php index c09f74a9..0a123bcc 100644 --- a/tests/phpunit/vfsStreamWrapperQuotaTestCase.php +++ b/tests/phpunit/vfsStreamWrapperQuotaTestCase.php @@ -11,7 +11,7 @@ namespace bovigo\vfs\tests; use bovigo\vfs\vfsStream; -use bovigo\vfs\vfsStreamDirectory; +use bovigo\vfs\vfsDirectory; use PHPUnit\Framework\TestCase; use function bovigo\assert\assertFalse; use function bovigo\assert\assertThat; @@ -24,7 +24,7 @@ use function ftruncate; /** - * Test for quota related functionality of bovigo\vfs\vfsStreamWrapper. + * Test for quota related functionality of bovigo\vfs\StreamWrapper. * * @group issue_35 */ @@ -33,7 +33,7 @@ class vfsStreamWrapperQuotaTestCase extends \BC_PHPUnit_Framework_TestCase /** * access to root * - * @type vfsStreamDirectory + * @type vfsDirectory */ private $root; diff --git a/tests/phpunit/vfsStreamWrapperTestCase.php b/tests/phpunit/vfsStreamWrapperTestCase.php index 9eb2ab3b..1b909bde 100644 --- a/tests/phpunit/vfsStreamWrapperTestCase.php +++ b/tests/phpunit/vfsStreamWrapperTestCase.php @@ -11,7 +11,7 @@ namespace bovigo\vfs\tests; use bovigo\vfs\vfsStream; -use bovigo\vfs\vfsStreamWrapper; +use bovigo\vfs\StreamWrapper; use const E_USER_WARNING; use const E_WARNING; use const PHP_VERSION_ID; @@ -57,12 +57,12 @@ use function unlink; /** - * Test for bovigo\vfs\vfsStreamWrapper. + * Test for bovigo\vfs\StreamWrapper. */ class vfsStreamWrapperTestCase extends vfsStreamWrapperBaseTestCase { /** - * ensure that a call to vfsStreamWrapper::register() resets the stream + * ensure that a call to StreamWrapper::register() resets the stream * * Implemented after a request by David Zülke. * @@ -70,9 +70,9 @@ class vfsStreamWrapperTestCase extends vfsStreamWrapperBaseTestCase */ public function resetByRegister() { - $this->assertSame($this->foo, vfsStreamWrapper::getRoot()); - vfsStreamWrapper::register(); - $this->assertNull(vfsStreamWrapper::getRoot()); + $this->assertSame($this->foo, StreamWrapper::getRoot()); + StreamWrapper::register(); + $this->assertNull(StreamWrapper::getRoot()); } /** @@ -81,9 +81,9 @@ public function resetByRegister() */ public function setRootReturnsRoot() { - vfsStreamWrapper::register(); + StreamWrapper::register(); $root = vfsStream::newDirectory('root'); - $this->assertSame($root, vfsStreamWrapper::setRoot($root)); + $this->assertSame($root, StreamWrapper::setRoot($root)); } /** @@ -670,7 +670,7 @@ public function statReturnsFullDataForDirectoriesWithDot() */ public function openFileWithoutDirectory() { - vfsStreamWrapper::register(); + StreamWrapper::register(); $this->assertFalse(file_get_contents(vfsStream::url('file.txt'))); } diff --git a/tests/phpunit/vfsStreamWrapperUnregisterTestCase.php b/tests/phpunit/vfsStreamWrapperUnregisterTestCase.php index 01bf9c3c..7ef80546 100644 --- a/tests/phpunit/vfsStreamWrapperUnregisterTestCase.php +++ b/tests/phpunit/vfsStreamWrapperUnregisterTestCase.php @@ -13,7 +13,7 @@ use bovigo\callmap\NewInstance; use bovigo\vfs\vfsStream; use bovigo\vfs\vfsStreamException; -use bovigo\vfs\vfsStreamWrapper; +use bovigo\vfs\StreamWrapper; use PHPUnit\Framework\TestCase; use function bovigo\assert\assertThat; use function bovigo\assert\expect; @@ -23,7 +23,7 @@ use function stream_wrapper_unregister; /** - * Test for bovigo\vfs\vfsStreamWrapper. + * Test for bovigo\vfs\StreamWrapper. */ class vfsStreamWrapperUnregisterTestCase extends \BC_PHPUnit_Framework_TestCase { @@ -35,8 +35,8 @@ class vfsStreamWrapperUnregisterTestCase extends \BC_PHPUnit_Framework_TestCase */ public function unregisterRegisteredUrlWrapper() { - vfsStreamWrapper::register(); - vfsStreamWrapper::unregister(); + StreamWrapper::register(); + StreamWrapper::unregister(); $this->assertNotContains(vfsStream::SCHEME, stream_get_wrappers()); } @@ -50,12 +50,12 @@ public function unregisterRegisteredUrlWrapper() public function unregisterThirdPartyVfsScheme() { // Unregister possible registered URL wrapper. - vfsStreamWrapper::unregister(); + StreamWrapper::unregister(); $mock = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamWrapper'); stream_wrapper_register(vfsStream::SCHEME, get_class($mock)); - vfsStreamWrapper::unregister(); + StreamWrapper::unregister(); } /** @@ -67,9 +67,9 @@ public function unregisterThirdPartyVfsScheme() */ public function unregisterWhenNotInRegisteredState() { - vfsStreamWrapper::register(); + StreamWrapper::register(); stream_wrapper_unregister(vfsStream::SCHEME); - vfsStreamWrapper::unregister(); + StreamWrapper::unregister(); } /** @@ -80,9 +80,9 @@ public function unregisterWhenNotInRegisteredState() public function unregisterWhenNotRegistered() { // Unregister possible registered URL wrapper. - vfsStreamWrapper::unregister(); + StreamWrapper::unregister(); $this->assertNotContains(vfsStream::SCHEME, stream_get_wrappers()); - vfsStreamWrapper::unregister(); + StreamWrapper::unregister(); } } diff --git a/tests/phpunit/vfsStreamWrapperWithoutRootTestCase.php b/tests/phpunit/vfsStreamWrapperWithoutRootTestCase.php index 91ba281b..0a0b4475 100644 --- a/tests/phpunit/vfsStreamWrapperWithoutRootTestCase.php +++ b/tests/phpunit/vfsStreamWrapperWithoutRootTestCase.php @@ -11,7 +11,7 @@ namespace bovigo\vfs\tests; use bovigo\vfs\vfsStream; -use bovigo\vfs\vfsStreamWrapper; +use bovigo\vfs\StreamWrapper; use PHPUnit\Framework\TestCase; use function bovigo\assert\assertFalse; use function dir; @@ -20,7 +20,7 @@ use function unlink; /** - * Test for bovigo\vfs\vfsStreamWrapper. + * Test for bovigo\vfs\StreamWrapper. */ class vfsStreamWrapperWithoutRootTestCase extends \BC_PHPUnit_Framework_TestCase { @@ -29,7 +29,7 @@ class vfsStreamWrapperWithoutRootTestCase extends \BC_PHPUnit_Framework_TestCase */ public function setUp() { - vfsStreamWrapper::register(); + StreamWrapper::register(); } /** diff --git a/tests/phpunit/vfsStreamZipTestCase.php b/tests/phpunit/vfsStreamZipTestCase.php index 0a486455..a857a57d 100644 --- a/tests/phpunit/vfsStreamZipTestCase.php +++ b/tests/phpunit/vfsStreamZipTestCase.php @@ -20,7 +20,7 @@ use function bovigo\assert\predicate\equals; /** - * Test for bovigo\vfs\vfsStreamWrapper in conjunction with ext/zip. + * Test for bovigo\vfs\StreamWrapper in conjunction with ext/zip. * * @group zip */ @@ -37,8 +37,8 @@ public function setUp() $this->markTestSkipped('Zip extension can not work with vfsStream urls.'); - vfsStreamWrapper::register(); - vfsStreamWrapper::setRoot(vfsStream::newDirectory('root')); + StreamWrapper::register(); + StreamWrapper::setRoot(vfsStream::newDirectory('root')); } diff --git a/tests/phpunit/visitor/BaseVisitorTestCase.php b/tests/phpunit/visitor/BaseVisitorTestCase.php new file mode 100644 index 00000000..39d02d47 --- /dev/null +++ b/tests/phpunit/visitor/BaseVisitorTestCase.php @@ -0,0 +1,108 @@ +baseVisitor = $this->bc_getMock('bovigo\\vfs\\visitor\\BaseVisitor', + array('visitFile', 'visitDirectory') + ); + } + + /** + * @test + * @expectedException \InvalidArgumentException + */ + public function visitThrowsInvalidArgumentExceptionOnUnknownContentType() + { + $mockContent = $this->bc_getMock('org\\bovigo\\vfs\\vfsStreamContent'); + $mockContent->expects($this->any()) + ->method('getType') + ->will($this->returnValue('invalid')); + $this->assertSame($this->baseVisitor, + $this->baseVisitor->visit($mockContent) + ); + } + + /** + * @test + */ + public function visitWithFileCallsVisitFile() + { + $file = new vfsFile('foo.txt'); + $this->baseVisitor->expects($this->once()) + ->method('visitFile') + ->with($this->equalTo($file)); + $this->assertSame($this->baseVisitor, + $this->baseVisitor->visit($file) + ); + } + + /** + * tests that a block device eventually calls out to visit file + * + * @test + */ + public function visitWithBlockCallsVisitFile() + { + $block = new vfsBlock('foo'); + $this->baseVisitor->expects($this->once()) + ->method('visitFile') + ->with($this->equalTo($block)); + $this->assertSame($this->baseVisitor, + $this->baseVisitor->visit($block) + ); + } + + /** + * @test + */ + public function visitWithDirectoryCallsVisitDirectory() + { + $dir = new vfsDirectory('bar'); + $this->baseVisitor->expects($this->once()) + ->method('visitDirectory') + ->with($this->equalTo($dir)); + $this->assertSame($this->baseVisitor, + $this->baseVisitor->visit($dir) + ); + } +} diff --git a/tests/phpunit/visitor/PrinterTestCase.php b/tests/phpunit/visitor/PrinterTestCase.php new file mode 100644 index 00000000..776426fd --- /dev/null +++ b/tests/phpunit/visitor/PrinterTestCase.php @@ -0,0 +1,112 @@ +at(vfsStream::setup()); + $printer = new Printer(fopen('vfs://root/foo.txt', 'wb')); + $this->assertSame($printer, + $printer->visitFile(vfsStream::newFile('bar.txt')) + ); + $this->assertEquals("- bar.txt\n", $output->getContent()); + } + + /** + * @test + */ + public function visitFileWritesBlockDeviceToStream() + { + $output = vfsStream::newFile('foo.txt') + ->at(vfsStream::setup()); + $printer = new Printer(fopen('vfs://root/foo.txt', 'wb')); + $this->assertSame($printer, + $printer->visitBlockDevice(vfsStream::newBlock('bar')) + ); + $this->assertEquals("- [bar]\n", $output->getContent()); + } + + /** + * @test + */ + public function visitDirectoryWritesDirectoryNameToStream() + { + $output = vfsStream::newFile('foo.txt') + ->at(vfsStream::setup()); + $printer = new Printer(fopen('vfs://root/foo.txt', 'wb')); + $this->assertSame($printer, + $printer->visitDirectory(vfsStream::newDirectory('baz')) + ); + $this->assertEquals("- baz\n", $output->getContent()); + } + + /** + * @test + */ + public function visitRecursiveDirectoryStructure() + { + $root = vfsStream::setup('root', + null, + array('test' => array('foo' => array('test.txt' => 'hello'), + 'baz.txt' => 'world' + ), + 'foo.txt' => '' + ) + ); + $printer = new Printer(fopen('vfs://root/foo.txt', 'wb')); + $this->assertSame($printer, + $printer->visitDirectory($root) + ); + $this->assertEquals("- root\n - test\n - foo\n - test.txt\n - baz.txt\n - foo.txt\n", file_get_contents('vfs://root/foo.txt')); + } +} diff --git a/tests/phpunit/visitor/StructureInspectorTestCase.php b/tests/phpunit/visitor/StructureInspectorTestCase.php new file mode 100644 index 00000000..749183c9 --- /dev/null +++ b/tests/phpunit/visitor/StructureInspectorTestCase.php @@ -0,0 +1,92 @@ +assertEquals(array('foo.txt' => 'test'), + $structureInspector->visitFile(vfsStream::newFile('foo.txt') + ->withContent('test') + ) + ->getStructure() + ); + } + + /** + * @test + */ + public function visitFileCreatesStructureForBlock() + { + $structureInspector = new StructureInspector(); + $this->assertEquals(array('[foo]' => 'test'), + $structureInspector->visitBlockDevice(vfsStream::newBlock('foo') + ->withContent('test') + ) + ->getStructure() + ); + } + + /** + * @test + */ + public function visitDirectoryCreatesStructureForDirectory() + { + $structureInspector = new StructureInspector(); + $this->assertEquals(array('baz' => array()), + $structureInspector->visitDirectory(vfsStream::newDirectory('baz')) + ->getStructure() + ); + } + + /** + * @test + */ + public function visitRecursiveDirectoryStructure() + { + $root = vfsStream::setup('root', + null, + array('test' => array('foo' => array('test.txt' => 'hello'), + 'baz.txt' => 'world' + ), + 'foo.txt' => '' + ) + ); + $structureInspector = new StructureInspector(); + $this->assertEquals(array('root' => array('test' => array('foo' => array('test.txt' => 'hello'), + 'baz.txt' => 'world' + ), + 'foo.txt' => '' + ), + ), + $structureInspector->visitDirectory($root) + ->getStructure() + ); + } +} diff --git a/tests/phpunit/visitor/vfsStreamAbstractVisitorTestCase.php b/tests/phpunit/visitor/vfsStreamAbstractVisitorTestCase.php index 9357ab8a..82ea7e17 100644 --- a/tests/phpunit/visitor/vfsStreamAbstractVisitorTestCase.php +++ b/tests/phpunit/visitor/vfsStreamAbstractVisitorTestCase.php @@ -11,11 +11,11 @@ namespace bovigo\vfs\tests\visitor; use bovigo\callmap\NewInstance; -use bovigo\vfs\vfsStreamBlock; +use org\bovigo\vfs\vfsStreamBlock; use bovigo\vfs\vfsStreamContent; -use bovigo\vfs\vfsStreamDirectory; -use bovigo\vfs\vfsStreamFile; -use bovigo\vfs\visitor\vfsStreamAbstractVisitor; +use org\bovigo\vfs\vfsStreamDirectory; +use org\bovigo\vfs\vfsStreamFile; +use org\bovigo\vfs\visitor\vfsStreamAbstractVisitor; use InvalidArgumentException; use PHPUnit\Framework\TestCase; use function bovigo\assert\expect; diff --git a/tests/phpunit/visitor/vfsStreamPrintVisitorTestCase.php b/tests/phpunit/visitor/vfsStreamPrintVisitorTestCase.php index 443058db..22da0b79 100644 --- a/tests/phpunit/visitor/vfsStreamPrintVisitorTestCase.php +++ b/tests/phpunit/visitor/vfsStreamPrintVisitorTestCase.php @@ -11,7 +11,7 @@ namespace bovigo\vfs\tests\visitor; use bovigo\vfs\vfsStream; -use bovigo\vfs\visitor\vfsStreamPrintVisitor; +use org\bovigo\vfs\visitor\vfsStreamPrintVisitor; use InvalidArgumentException; use PHPUnit\Framework\TestCase; use function bovigo\assert\assertThat; diff --git a/tests/phpunit/visitor/vfsStreamStructureVisitorTestCase.php b/tests/phpunit/visitor/vfsStreamStructureVisitorTestCase.php index e1edce6c..e140512f 100644 --- a/tests/phpunit/visitor/vfsStreamStructureVisitorTestCase.php +++ b/tests/phpunit/visitor/vfsStreamStructureVisitorTestCase.php @@ -11,7 +11,7 @@ namespace bovigo\vfs\tests\visitor; use bovigo\vfs\vfsStream; -use bovigo\vfs\visitor\vfsStreamStructureVisitor; +use org\bovigo\vfs\visitor\vfsStreamStructureVisitor; use PHPUnit\Framework\TestCase; use function bovigo\assert\assertThat; use function bovigo\assert\predicate\equals; From 10d70c59771192595599fc191c3454f7fd136bd7 Mon Sep 17 00:00:00 2001 From: Frank Kleine Date: Thu, 5 Mar 2020 13:15:14 +0100 Subject: [PATCH 2/2] fix various type hints --- src/StreamWrapper.php | 2 +- src/vfsFile.php | 4 ++-- tests/phpunit/vfsStreamWrapperBaseTestCase.php | 6 +++--- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/StreamWrapper.php b/src/StreamWrapper.php index a109a891..d85d510a 100644 --- a/src/StreamWrapper.php +++ b/src/StreamWrapper.php @@ -111,7 +111,7 @@ class StreamWrapper /** * shortcut to file container * - * @type vfsStreamFile + * @type vfsFile */ protected $content; /** diff --git a/src/vfsFile.php b/src/vfsFile.php index 12017948..8cf776a9 100644 --- a/src/vfsFile.php +++ b/src/vfsFile.php @@ -91,7 +91,7 @@ public function appliesTo($name) * alias for withContent() * * @param string $content - * @return vfsStreamFile + * @return vfsFile * @see withContent() */ public function setContent($content) @@ -106,7 +106,7 @@ public function setContent($content) * was last modified. * * @param string]FileContent $content - * @return vfsStreamFile + * @return vfsFile * @throws \InvalidArgumentException */ public function withContent($content) diff --git a/tests/phpunit/vfsStreamWrapperBaseTestCase.php b/tests/phpunit/vfsStreamWrapperBaseTestCase.php index 90bb5c78..9bcbbd34 100644 --- a/tests/phpunit/vfsStreamWrapperBaseTestCase.php +++ b/tests/phpunit/vfsStreamWrapperBaseTestCase.php @@ -12,7 +12,7 @@ use bovigo\vfs\vfsStream; use bovigo\vfs\vfsDirectory; -use bovigo\vfs\vfsStreamFile; +use bovigo\vfs\vfsFile; use bovigo\vfs\StreamWrapper; use PHPUnit\Framework\TestCase; @@ -48,7 +48,7 @@ abstract class vfsStreamWrapperBaseTestCase extends \BC_PHPUnit_Framework_TestCa /** * a file * - * @var vfsStreamFile + * @var vfsFile */ protected $baz1; /** @@ -60,7 +60,7 @@ abstract class vfsStreamWrapperBaseTestCase extends \BC_PHPUnit_Framework_TestCa /** * another file * - * @var vfsStreamFile + * @var vfsFile */ protected $baz2; /**