diff --git a/Filesystem.php b/Filesystem.php index bfe387803..cc553bd35 100644 --- a/Filesystem.php +++ b/Filesystem.php @@ -70,7 +70,7 @@ public function copy(string $originFile, string $targetFile, bool $overwriteNewe if ($originIsLocal) { // Like `cp`, preserve executable permission bits - self::box('chmod', $targetFile, fileperms($targetFile) | (fileperms($originFile) & 0111)); + self::box('chmod', $targetFile, fileperms($targetFile) | (fileperms($originFile) & 0o111)); // Like `cp`, preserve the file modification time self::box('touch', $targetFile, filemtime($originFile)); @@ -87,7 +87,7 @@ public function copy(string $originFile, string $targetFile, bool $overwriteNewe * * @throws IOException On any directory creation failure */ - public function mkdir(string|iterable $dirs, int $mode = 0777): void + public function mkdir(string|iterable $dirs, int $mode = 0o777): void { foreach ($this->toIterable($dirs) as $dir) { if (is_dir($dir)) { @@ -208,7 +208,7 @@ private static function doRemove(array $files, bool $isRecursive): void * * @throws IOException When the change fails */ - public function chmod(string|iterable $files, int $mode, int $umask = 0000, bool $recursive = false): void + public function chmod(string|iterable $files, int $mode, int $umask = 0o000, bool $recursive = false): void { foreach ($this->toIterable($files) as $file) { if (!self::box('chmod', $file, $mode & ~$umask)) { @@ -670,13 +670,13 @@ public function dumpFile(string $filename, $content): void throw new IOException(\sprintf('Failed to write file "%s": ', $filename).self::$lastError, 0, null, $filename); } - self::box('chmod', $tmpFile, self::box('fileperms', $filename) ?: 0666 & ~umask()); + self::box('chmod', $tmpFile, self::box('fileperms', $filename) ?: 0o666 & ~umask()); $this->rename($tmpFile, $filename, true); } finally { if (file_exists($tmpFile)) { if ('\\' === \DIRECTORY_SEPARATOR && !is_writable($tmpFile)) { - self::box('chmod', $tmpFile, self::box('fileperms', $tmpFile) | 0200); + self::box('chmod', $tmpFile, self::box('fileperms', $tmpFile) | 0o200); } self::box('unlink', $tmpFile); diff --git a/Tests/FilesystemTest.php b/Tests/FilesystemTest.php index 4c3355c79..39d77f3c7 100644 --- a/Tests/FilesystemTest.php +++ b/Tests/FilesystemTest.php @@ -11,6 +11,8 @@ namespace Symfony\Component\Filesystem\Tests; +use PHPUnit\Framework\Attributes\DataProvider; +use PHPUnit\Framework\Attributes\Depends; use Symfony\Component\Filesystem\Exception\InvalidArgumentException; use Symfony\Component\Filesystem\Exception\IOException; use Symfony\Component\Filesystem\Path; @@ -62,7 +64,7 @@ public function testCopyUnreadableFileFails() file_put_contents($sourceFilePath, 'SOURCE FILE'); // make sure target cannot be read - $this->filesystem->chmod($sourceFilePath, 0222); + $this->filesystem->chmod($sourceFilePath, 0o222); $this->filesystem->copy($sourceFilePath, $targetFilePath); } @@ -144,7 +146,7 @@ public function testCopyWithOverrideWithReadOnlyTargetFails() touch($targetFilePath, $modificationTime); // make sure target is read-only - $this->filesystem->chmod($targetFilePath, 0444); + $this->filesystem->chmod($targetFilePath, 0o444); $this->filesystem->copy($sourceFilePath, $targetFilePath, true); } @@ -357,7 +359,7 @@ public function testRemoveThrowsExceptionOnPermissionDenied() mkdir($basePath); $file = $basePath.\DIRECTORY_SEPARATOR.'file'; touch($file); - chmod($basePath, 0400); + chmod($basePath, 0o400); try { $this->filesystem->remove($file); @@ -367,7 +369,7 @@ public function testRemoveThrowsExceptionOnPermissionDenied() $this->assertStringContainsString('Permission denied', $e->getMessage()); } finally { // Make sure we can clean up this file - chmod($basePath, 0777); + chmod($basePath, 0o777); } } @@ -474,8 +476,8 @@ public function testChmodChangesFileMode() $file = $dir.\DIRECTORY_SEPARATOR.'file'; touch($file); - $this->filesystem->chmod($file, 0400); - $this->filesystem->chmod($dir, 0753); + $this->filesystem->chmod($file, 0o400); + $this->filesystem->chmod($dir, 0o753); $this->assertFilePermissions(753, $dir); $this->assertFilePermissions(400, $file); @@ -490,8 +492,8 @@ public function testChmodRecursive() $file = $dir.\DIRECTORY_SEPARATOR.'file'; touch($file); - $this->filesystem->chmod($file, 0400, 0000, true); - $this->filesystem->chmod($dir, 0753, 0000, true); + $this->filesystem->chmod($file, 0o400, 0o000, true); + $this->filesystem->chmod($dir, 0o753, 0o000, true); $this->assertFilePermissions(753, $dir); $this->assertFilePermissions(753, $file); @@ -504,7 +506,7 @@ public function testChmodAppliesUmask() $file = $this->workspace.\DIRECTORY_SEPARATOR.'file'; touch($file); - $this->filesystem->chmod($file, 0770, 0022); + $this->filesystem->chmod($file, 0o770, 0o022); $this->assertFilePermissions(750, $file); } @@ -519,7 +521,7 @@ public function testChmodChangesModeOfArrayOfFiles() mkdir($directory); touch($file); - $this->filesystem->chmod($files, 0753); + $this->filesystem->chmod($files, 0o753); $this->assertFilePermissions(753, $file); $this->assertFilePermissions(753, $directory); @@ -536,7 +538,7 @@ public function testChmodChangesModeOfTraversableFileObject() mkdir($directory); touch($file); - $this->filesystem->chmod($files, 0753); + $this->filesystem->chmod($files, 0o753); $this->assertFilePermissions(753, $file); $this->assertFilePermissions(753, $directory); @@ -551,9 +553,9 @@ public function testChmodChangesZeroModeOnSubdirectoriesOnRecursive() mkdir($directory); mkdir($subdirectory); - chmod($subdirectory, 0000); + chmod($subdirectory, 0o000); - $this->filesystem->chmod($directory, 0753, 0000, true); + $this->filesystem->chmod($directory, 0o753, 0o000, true); $this->assertFilePermissions(753, $subdirectory); } @@ -889,9 +891,7 @@ public function testSymlink() $this->assertEquals($file, readlink($link)); } - /** - * @depends testSymlink - */ + #[Depends('testSymlink')] public function testRemoveSymlink() { $this->markAsSkippedIfSymlinkIsMissing(); @@ -970,9 +970,7 @@ public function testLink() $this->assertEquals(fileinode($file), fileinode($link)); } - /** - * @depends testLink - */ + #[Depends('testLink')] public function testRemoveLink() { $this->markAsSkippedIfLinkIsMissing(); @@ -1142,9 +1140,7 @@ public function testReadLinkCanonicalizedPathDoesNotExist() $this->assertNull($this->filesystem->readlink($this->normalize($this->workspace.'invalid'), true)); } - /** - * @dataProvider providePathsForMakePathRelative - */ + #[DataProvider('providePathsForMakePathRelative')] public function testMakePathRelative($endPath, $startPath, $expectedPath) { $path = $this->filesystem->makePathRelative($endPath, $startPath); @@ -1298,7 +1294,7 @@ public function testMirrorCopiesLinkedDirectoryContents() $sourcePath = $this->workspace.\DIRECTORY_SEPARATOR.'source'.\DIRECTORY_SEPARATOR; - mkdir($sourcePath.'nested/', 0777, true); + mkdir($sourcePath.'nested/', 0o777, true); file_put_contents($sourcePath.'/nested/file1.txt', 'FILE1'); // Note: We symlink directory, not file symlink($sourcePath.'nested', $sourcePath.'link1'); @@ -1319,7 +1315,7 @@ public function testMirrorCopiesRelativeLinkedContents() $sourcePath = $this->workspace.\DIRECTORY_SEPARATOR.'source'.\DIRECTORY_SEPARATOR; $oldPath = getcwd(); - mkdir($sourcePath.'nested/', 0777, true); + mkdir($sourcePath.'nested/', 0o777, true); file_put_contents($sourcePath.'/nested/file1.txt', 'FILE1'); // Note: Create relative symlink chdir($sourcePath); @@ -1430,9 +1426,7 @@ public function testMirrorFromSubdirectoryInToParentDirectory() $this->assertFileEquals($file1, $targetPath.'file1'); } - /** - * @dataProvider providePathsForIsAbsolutePath - */ + #[DataProvider('providePathsForIsAbsolutePath')] public function testIsAbsolutePath($path, $expectedResult) { $result = $this->filesystem->isAbsolutePath($path); @@ -1571,7 +1565,7 @@ public function testDumpFile() // skip mode check on Windows if ('\\' !== \DIRECTORY_SEPARATOR) { - $oldMask = umask(0002); + $oldMask = umask(0o002); } $this->filesystem->dumpFile($filename, 'bar'); @@ -1667,7 +1661,7 @@ public function testAppendToFile() // skip mode check on Windows if ('\\' !== \DIRECTORY_SEPARATOR) { - $oldMask = umask(0002); + $oldMask = umask(0o002); } $this->filesystem->dumpFile($filename, 'foo'); @@ -1690,7 +1684,7 @@ public function testAppendToFileWithResource() // skip mode check on Windows if ('\\' !== \DIRECTORY_SEPARATOR) { - $oldMask = umask(0002); + $oldMask = umask(0o002); } $this->filesystem->dumpFile($filename, 'foo'); @@ -1773,7 +1767,7 @@ public function testAppendToFileCreateTheFileIfNotExists() // skip mode check on Windows if ('\\' !== \DIRECTORY_SEPARATOR) { - $oldMask = umask(0002); + $oldMask = umask(0o002); } $this->filesystem->appendToFile($filename, 'bar'); @@ -1806,7 +1800,7 @@ public function testDumpKeepsExistingPermissionsWhenOverwritingAnExistingFile() $filename = $this->workspace.\DIRECTORY_SEPARATOR.'foo.txt'; file_put_contents($filename, 'FOO BAR'); - chmod($filename, 0745); + chmod($filename, 0o745); $this->filesystem->dumpFile($filename, 'bar'); @@ -1817,13 +1811,13 @@ public function testDumpFileCleansUpAfterFailure() { $targetFile = $this->workspace.'/dump-file'; $this->filesystem->touch($targetFile); - $this->filesystem->chmod($targetFile, 0444); + $this->filesystem->chmod($targetFile, 0o444); try { $this->filesystem->dumpFile($targetFile, 'any content'); } catch (IOException $e) { } finally { - $this->filesystem->chmod($targetFile, 0666); + $this->filesystem->chmod($targetFile, 0o666); } $this->assertSame([$targetFile], glob($this->workspace.'/*')); @@ -1874,7 +1868,7 @@ public function testCopyShouldKeepExecutionPermission() $targetFilePath = $this->workspace.\DIRECTORY_SEPARATOR.'copy_target_file'; file_put_contents($sourceFilePath, 'SOURCE FILE'); - chmod($sourceFilePath, 0745); + chmod($sourceFilePath, 0o745); $this->filesystem->copy($sourceFilePath, $targetFilePath); diff --git a/Tests/FilesystemTestCase.php b/Tests/FilesystemTestCase.php index ce9176a47..8886eec58 100644 --- a/Tests/FilesystemTestCase.php +++ b/Tests/FilesystemTestCase.php @@ -59,7 +59,7 @@ protected function setUp(): void $this->umask = umask(0); $this->filesystem = new Filesystem(); $this->workspace = sys_get_temp_dir().'/'.microtime(true).'.'.mt_rand(); - mkdir($this->workspace, 0777, true); + mkdir($this->workspace, 0o777, true); $this->workspace = realpath($this->workspace); } @@ -103,7 +103,7 @@ protected function getFileOwner($filepath) { $this->markAsSkippedIfPosixIsMissing(); - return ($datas = posix_getpwuid($this->getFileOwnerId($filepath))) ? $datas['name'] : null; + return ($data = posix_getpwuid($this->getFileOwnerId($filepath))) ? $data['name'] : null; } protected function getFileGroupId($filepath) @@ -119,8 +119,8 @@ protected function getFileGroup($filepath) { $this->markAsSkippedIfPosixIsMissing(); - if ($datas = posix_getgrgid($this->getFileGroupId($filepath))) { - return $datas['name']; + if ($data = posix_getgrgid($this->getFileGroupId($filepath))) { + return $data['name']; } $this->markTestSkipped('Unable to retrieve file group name'); diff --git a/Tests/PathTest.php b/Tests/PathTest.php index 285d55f0d..b818a7518 100644 --- a/Tests/PathTest.php +++ b/Tests/PathTest.php @@ -11,6 +11,7 @@ namespace Symfony\Component\Filesystem\Tests; +use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use Symfony\Component\Filesystem\Path; @@ -164,9 +165,7 @@ public static function provideCanonicalizationTests(): \Generator yield ['~/../../css/style.css', '/css/style.css']; } - /** - * @dataProvider provideCanonicalizationTests - */ + #[DataProvider('provideCanonicalizationTests')] public function testCanonicalize(string $path, string $canonicalized) { $this->assertSame($canonicalized, Path::canonicalize($path)); @@ -227,9 +226,7 @@ public static function provideGetDirectoryTests(): \Generator yield ['D:/Folder/Aééé/Subfolder', 'D:/Folder/Aééé']; } - /** - * @dataProvider provideGetDirectoryTests - */ + #[DataProvider('provideGetDirectoryTests')] public function testGetDirectory(string $path, string $directory) { $this->assertSame($directory, Path::getDirectory($path)); @@ -258,9 +255,7 @@ public static function provideGetFilenameWithoutExtensionTests(): \Generator yield ['/webmozart/symfony/.style.css', '.css', '.style']; } - /** - * @dataProvider provideGetFilenameWithoutExtensionTests - */ + #[DataProvider('provideGetFilenameWithoutExtensionTests')] public function testGetFilenameWithoutExtension(string $path, ?string $extension, string $filename) { $this->assertSame($filename, Path::getFilenameWithoutExtension($path, $extension)); @@ -283,9 +278,7 @@ public static function provideGetExtensionTests(): \Generator yield ['/webmozart/symfony/style.ÄÖÜ', true, 'äöü']; } - /** - * @dataProvider provideGetExtensionTests - */ + #[DataProvider('provideGetExtensionTests')] public function testGetExtension(string $path, bool $forceLowerCase, string $extension) { $this->assertSame($extension, Path::getExtension($path, $forceLowerCase)); @@ -329,10 +322,9 @@ public static function provideHasExtensionTests(): \Generator } /** - * @dataProvider provideHasExtensionTests - * * @param string|string[]|null $extension */ + #[DataProvider('provideHasExtensionTests')] public function testHasExtension(bool $hasExtension, string $path, $extension, bool $ignoreCase) { $this->assertSame($hasExtension, Path::hasExtension($path, $extension, $ignoreCase)); @@ -354,9 +346,7 @@ public static function provideChangeExtensionTests(): \Generator yield ['', 'css', '']; } - /** - * @dataProvider provideChangeExtensionTests - */ + #[DataProvider('provideChangeExtensionTests')] public function testChangeExtension(string $path, string $extension, string $pathExpected) { $this->assertSame($pathExpected, Path::changeExtension($path, $extension)); @@ -391,17 +381,13 @@ public static function provideIsAbsolutePathTests(): \Generator yield ['C:css/style.css', false]; } - /** - * @dataProvider provideIsAbsolutePathTests - */ + #[DataProvider('provideIsAbsolutePathTests')] public function testIsAbsolute(string $path, bool $isAbsolute) { $this->assertSame($isAbsolute, Path::isAbsolute($path)); } - /** - * @dataProvider provideIsAbsolutePathTests - */ + #[DataProvider('provideIsAbsolutePathTests')] public function testIsRelative(string $path, bool $isAbsolute) { $this->assertSame(!$isAbsolute, Path::isRelative($path)); @@ -433,9 +419,7 @@ public static function provideGetRootTests(): \Generator yield ['phar://C:', 'phar://C:/']; } - /** - * @dataProvider provideGetRootTests - */ + #[DataProvider('provideGetRootTests')] public function testGetRoot(string $path, string $root) { $this->assertSame($root, Path::getRoot($path)); @@ -529,9 +513,7 @@ public static function provideMakeAbsoluteTests(): \Generator yield ['D:\\css\\style.css', 'D:/webmozart/symfony', 'D:/css/style.css']; } - /** - * @dataProvider provideMakeAbsoluteTests - */ + #[DataProvider('provideMakeAbsoluteTests')] public function testMakeAbsolute(string $relativePath, string $basePath, string $absolutePath) { $this->assertSame($absolutePath, Path::makeAbsolute($relativePath, $basePath)); @@ -579,9 +561,7 @@ public static function provideAbsolutePathsWithDifferentRoots(): \Generator yield ['phar://C:\\css\\style.css', 'C:\\webmozart\\symfony']; } - /** - * @dataProvider provideAbsolutePathsWithDifferentRoots - */ + #[DataProvider('provideAbsolutePathsWithDifferentRoots')] public function testMakeAbsoluteDoesNotFailIfDifferentRoot(string $basePath, string $absolutePath) { // If a path in partition D: is passed, but $basePath is in partition @@ -682,9 +662,7 @@ public static function provideMakeRelativeTests(): \Generator yield ['\\webmozart\\symfony\\css\\style.css', '/webmozart/symfony', 'css/style.css']; } - /** - * @dataProvider provideMakeRelativeTests - */ + #[DataProvider('provideMakeRelativeTests')] public function testMakeRelative(string $absolutePath, string $basePath, string $relativePath) { $this->assertSame($relativePath, Path::makeRelative($absolutePath, $basePath)); @@ -705,9 +683,7 @@ public function testMakeRelativeFailsIfAbsolutePathAndBasePathEmpty() Path::makeRelative('/webmozart/symfony/css/style.css', ''); } - /** - * @dataProvider provideAbsolutePathsWithDifferentRoots - */ + #[DataProvider('provideAbsolutePathsWithDifferentRoots')] public function testMakeRelativeFailsIfDifferentRoot(string $absolutePath, string $basePath) { $this->expectException(\InvalidArgumentException::class); @@ -724,9 +700,7 @@ public static function provideIsLocalTests(): \Generator yield ['', false]; } - /** - * @dataProvider provideIsLocalTests - */ + #[DataProvider('provideIsLocalTests')] public function testIsLocal(string $path, bool $isLocal) { $this->assertSame($isLocal, Path::isLocal($path)); @@ -843,10 +817,9 @@ public static function provideGetLongestCommonBasePathTests(): \Generator } /** - * @dataProvider provideGetLongestCommonBasePathTests - * * @param string[] $paths */ + #[DataProvider('provideGetLongestCommonBasePathTests')] public function testGetLongestCommonBasePath(array $paths, ?string $basePath) { $this->assertSame($basePath, Path::getLongestCommonBasePath(...$paths)); @@ -933,9 +906,7 @@ public static function provideIsBasePathTests(): \Generator yield ['phar://C:/base/path', 'phar://D:/base/path', false]; } - /** - * @dataProvider provideIsBasePathTests - */ + #[DataProvider('provideIsBasePathTests')] public function testIsBasePath(string $path, string $ofPath, bool $result) { $this->assertSame($result, Path::isBasePath($path, $ofPath)); @@ -1012,9 +983,7 @@ public static function provideJoinTests(): \Generator yield [['phar://C:/', '/path/to/test'], 'phar://C:/path/to/test']; } - /** - * @dataProvider provideJoinTests - */ + #[DataProvider('provideJoinTests')] public function testJoin(array $paths, $result) { $this->assertSame($result, Path::join(...$paths)); diff --git a/composer.json b/composer.json index c781e55b1..42bbfa08a 100644 --- a/composer.json +++ b/composer.json @@ -21,7 +21,7 @@ "symfony/polyfill-mbstring": "~1.8" }, "require-dev": { - "symfony/process": "^6.4|^7.0" + "symfony/process": "^6.4|^7.0|^8.0" }, "autoload": { "psr-4": { "Symfony\\Component\\Filesystem\\": "" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index e7418f42c..de9ee5866 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,10 +1,11 @@ @@ -18,7 +19,7 @@ - + ./ @@ -26,5 +27,9 @@ ./Tests ./vendor - + + + + +