From 15f01161f410cd4be76539e3d97eccc03df46663 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9o=20FIDRY?= <5175937+theofidry@users.noreply.github.com> Date: Sat, 7 Oct 2023 09:51:28 +0200 Subject: [PATCH] refactor: Migrate Box FileSystem to Fidry FileSystem (#1028) --- composer.json | 2 +- composer.lock | 71 +- src/Box.php | 24 +- src/Composer/ComposerConfiguration.php | 4 +- src/Composer/ComposerOrchestrator.php | 7 +- src/Configuration/Configuration.php | 46 +- src/Configuration/ExportableConfiguration.php | 4 +- src/Console/Command/Compile.php | 24 +- src/Console/Command/Extract.php | 22 +- src/Console/Command/GenerateDockerFile.php | 7 +- src/Console/Command/Process.php | 11 +- src/Console/Php/PhpSettingsHandler.php | 4 +- src/FileSystem/FileSystem.php | 572 ---------- src/FileSystem/file_system.php | 982 ------------------ src/Json/Json.php | 4 +- src/MapFile.php | 4 +- src/Phar/PharMeta.php | 3 +- src/Pharaoh/Pharaoh.php | 9 +- src/RequirementChecker/RequirementsDumper.php | 4 +- src/Test/FileSystemTestCase.php | 65 +- tests/AutoReview/DocumentationSchemaTest.php | 8 +- tests/BoxTest.php | 86 +- tests/Composer/ComposerConfigurationTest.php | 20 +- .../ComposerOrchestratorComposer22Test.php | 17 +- .../ComposerOrchestratorComposer23Test.php | 17 +- .../ComposerOrchestratorComposer24Test.php | 17 +- .../ConfigurationFileNoConfigTest.php | 525 +++++----- tests/Configuration/ConfigurationFileTest.php | 738 +++++++------ .../Configuration/ConfigurationLoaderTest.php | 13 +- .../ConfigurationSigningTest.php | 8 +- tests/Configuration/ConfigurationTest.php | 193 ++-- tests/Configuration/ConfigurationTestCase.php | 13 +- tests/Console/Command/CompileTest.php | 158 ++- tests/Console/Command/ConfigOptionTest.php | 21 +- tests/Console/Command/ExtractTest.php | 4 +- tests/Console/Command/Namespace_Test.php | 4 +- tests/Console/Command/ProcessTest.php | 23 +- tests/Console/Command/ValidateTest.php | 35 +- tests/Console/ConfigurationLocatorTest.php | 10 +- tests/Json/JsonTest.php | 9 +- tests/Json/JsonValidationExceptionTest.php | 4 +- 41 files changed, 1098 insertions(+), 2694 deletions(-) delete mode 100644 src/FileSystem/FileSystem.php delete mode 100644 src/FileSystem/file_system.php diff --git a/composer.json b/composer.json index 1cc346481..0a61794df 100644 --- a/composer.json +++ b/composer.json @@ -25,6 +25,7 @@ "composer/semver": "^3.3.2", "composer/xdebug-handler": "^3.0.3", "fidry/console": "^0.5.3", + "fidry/filesystem": "^1.1", "humbug/php-scoper": "^0.18.3", "justinrainbow/json-schema": "^5.2.12", "laravel/serializable-closure": "^1.2.2", @@ -68,7 +69,6 @@ "KevinGH\\Box\\": "src" }, "files": [ - "src/FileSystem/file_system.php", "src/consts.php", "src/functions.php" ], diff --git a/composer.lock b/composer.lock index 245180975..efcce54b6 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "5853e0f14e8dd6aee008ffcf917bccf7", + "content-hash": "929461c05717f1f10281876774046cb3", "packages": [ { "name": "amphp/amp", @@ -906,6 +906,75 @@ ], "time": "2022-12-18T10:49:34+00:00" }, + { + "name": "fidry/filesystem", + "version": "1.1.0", + "source": { + "type": "git", + "url": "https://github.com/theofidry/filesystem.git", + "reference": "1dd372ab3eb8b84ffe9578bff576b00c9a44ee46" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theofidry/filesystem/zipball/1dd372ab3eb8b84ffe9578bff576b00c9a44ee46", + "reference": "1dd372ab3eb8b84ffe9578bff576b00c9a44ee46", + "shasum": "" + }, + "require": { + "php": "^8.1", + "symfony/filesystem": "^6.3", + "thecodingmachine/safe": "^2.0" + }, + "require-dev": { + "bamarni/composer-bin-plugin": "^1.4", + "ergebnis/composer-normalize": "^2.28", + "infection/infection": "^0.26", + "phpspec/prophecy-phpunit": "^2.0", + "phpunit/phpunit": "^10.3", + "symfony/finder": "^6.3", + "symfony/phpunit-bridge": "^6.2" + }, + "type": "library", + "extra": { + "bamarni-bin": { + "bin-links": false, + "forward-command": false + }, + "branch-alias": { + "dev-main": "1.0.x-dev" + } + }, + "autoload": { + "psr-4": { + "Fidry\\FileSystem\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "BSD-3-Clause" + ], + "authors": [ + { + "name": "Théo Fidry", + "email": "theo.fidry@gmail.com" + } + ], + "description": "Symfony Filesystem with a few more utilities.", + "keywords": [ + "filesystem" + ], + "support": { + "issues": "https://github.com/theofidry/filesystem/issues", + "source": "https://github.com/theofidry/filesystem/tree/1.1.0" + }, + "funding": [ + { + "url": "https://github.com/theofidry", + "type": "github" + } + ], + "time": "2023-10-07T07:32:54+00:00" + }, { "name": "humbug/php-scoper", "version": "0.18.3", diff --git a/src/Box.php b/src/Box.php index 8da47f8de..f39a1606c 100644 --- a/src/Box.php +++ b/src/Box.php @@ -17,6 +17,7 @@ use Amp\MultiReasonException; use BadMethodCallException; use Countable; +use Fidry\FileSystem\FS; use Humbug\PhpScoper\Symbol\SymbolsRegistry; use KevinGH\Box\Compactor\Compactors; use KevinGH\Box\Compactor\PhpScoper; @@ -41,11 +42,6 @@ use function file_exists; use function getcwd; use function is_object; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\file_contents; -use function KevinGH\Box\FileSystem\make_tmp_dir; -use function KevinGH\Box\FileSystem\mkdir; -use function KevinGH\Box\FileSystem\remove; use function openssl_pkey_export; use function openssl_pkey_get_details; use function openssl_pkey_get_private; @@ -92,7 +88,7 @@ public static function create(string $pharFilePath, int $pharFlags = 0, ?string { // Ensure the parent directory of the PHAR file exists as `new \Phar()` does not create it and would fail // otherwise. - mkdir(dirname($pharFilePath)); + FS::mkdir(dirname($pharFilePath)); return new self( new Phar($pharFilePath, $pharFlags, $pharAlias), @@ -127,7 +123,7 @@ public function endBuffering(?callable $dumpAutoload): void $dumpAutoload ??= static fn () => null; $cwd = getcwd(); - $tmp = make_tmp_dir('box', self::class); + $tmp = FS::makeTmpDir('box', self::class); chdir($tmp); if ([] === $this->bufferedFiles) { @@ -138,7 +134,7 @@ public function endBuffering(?callable $dumpAutoload): void try { foreach ($this->bufferedFiles as $file => $contents) { - dump_file($file, $contents); + FS::dumpFile($file, $contents); } if (null !== $dumpAutoload) { @@ -152,7 +148,7 @@ public function endBuffering(?callable $dumpAutoload): void $this->phar->buildFromDirectory($tmp); } finally { - remove($tmp); + FS::remove($tmp); } $this->buffering = false; @@ -283,7 +279,7 @@ public function registerStub(string $file): void { $contents = $this->placeholderCompactor->compact( $file, - file_contents($file), + FS::getFileContents($file), ); $this->phar->setStub($contents); @@ -327,7 +323,7 @@ public function addFile(string $file, ?string $contents = null, bool $binary = f Assert::true($this->buffering, 'Cannot add files if the buffering has not started.'); if (null === $contents) { - $contents = file_contents($file); + $contents = FS::getFileContents($file); } $local = ($this->mapFile)($file); @@ -350,7 +346,7 @@ public function getPhar(): Phar */ public function signUsingFile(string $file, ?string $password = null): void { - $this->sign(file_contents($file), $password); + $this->sign(FS::getFileContents($file), $password); } /** @@ -383,7 +379,7 @@ public function sign(string $key, ?string $password): void $this->phar->setSignatureAlgorithm(Phar::OPENSSL, $private); - dump_file($pubKey, $details['key']); + FS::dumpFile($pubKey, $details['key']); } /** @@ -410,7 +406,7 @@ private function processContents(array $files): array \KevinGH\Box\register_error_handler(); } - $contents = file_contents($file); + $contents = \Fidry\FileSystem\FS::getFileContents($file); $local = $mapFile($file); diff --git a/src/Composer/ComposerConfiguration.php b/src/Composer/ComposerConfiguration.php index d6ed9a538..0529f6ee9 100644 --- a/src/Composer/ComposerConfiguration.php +++ b/src/Composer/ComposerConfiguration.php @@ -14,11 +14,11 @@ namespace KevinGH\Box\Composer; +use Symfony\Component\Filesystem\Path; use function array_column; use function array_filter; use function array_key_exists; use function array_map; -use function KevinGH\Box\FileSystem\make_path_absolute; use function realpath; use const DIRECTORY_SEPARATOR; @@ -61,7 +61,7 @@ private static function getDevPackagePaths( array $composerJsonDecodedContents, array $composerLockDecodedContents, ): array { - $vendorDir = make_path_absolute( + $vendorDir = Path::makeAbsolute( self::retrieveVendorDir($composerJsonDecodedContents), $basePath, ); diff --git a/src/Composer/ComposerOrchestrator.php b/src/Composer/ComposerOrchestrator.php index 1aaec6390..10f84fc0d 100644 --- a/src/Composer/ComposerOrchestrator.php +++ b/src/Composer/ComposerOrchestrator.php @@ -16,6 +16,7 @@ use Composer\Semver\Semver; use Fidry\Console\Input\IO; +use Fidry\FileSystem\FS; use Humbug\PhpScoper\Autoload\ScoperAutoloadGenerator; use Humbug\PhpScoper\Symbol\SymbolsRegistry; use KevinGH\Box\Console\Logger\CompilerLogger; @@ -25,8 +26,6 @@ use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\ExecutableFinder; use Symfony\Component\Process\Process; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\file_contents; use function preg_replace; use function sprintf; use function str_replace; @@ -121,10 +120,10 @@ public static function dumpAutoload( $autoloadContents = self::generateAutoloadStatements( $symbolsRegistry, - file_contents($autoloadFile), + FS::getFileContents($autoloadFile), ); - dump_file($autoloadFile, $autoloadContents); + FS::dumpFile($autoloadFile, $autoloadContents); } } diff --git a/src/Configuration/Configuration.php b/src/Configuration/Configuration.php index 661743cde..5f9b7ee76 100644 --- a/src/Configuration/Configuration.php +++ b/src/Configuration/Configuration.php @@ -17,6 +17,7 @@ use Closure; use DateTimeImmutable; use DateTimeZone; +use Fidry\FileSystem\FS; use Humbug\PhpScoper\Configuration\Configuration as PhpScoperConfiguration; use Humbug\PhpScoper\Container; use InvalidArgumentException; @@ -39,6 +40,7 @@ use Seld\JsonLint\ParsingException; use SplFileInfo; use stdClass; +use Symfony\Component\Filesystem\Path; use Symfony\Component\Finder\Finder; use Symfony\Component\Process\Exception\ProcessFailedException; use Symfony\Component\Process\Process; @@ -74,12 +76,6 @@ use function iter\map; use function iter\toArray; use function iter\values; -use function KevinGH\Box\FileSystem\canonicalize; -use function KevinGH\Box\FileSystem\file_contents; -use function KevinGH\Box\FileSystem\is_absolute_path; -use function KevinGH\Box\FileSystem\longest_common_base_path; -use function KevinGH\Box\FileSystem\make_path_absolute; -use function KevinGH\Box\FileSystem\make_path_relative; use function KevinGH\Box\get_box_version; use function KevinGH\Box\get_phar_signing_algorithms; use function KevinGH\Box\unique_id; @@ -249,7 +245,7 @@ public static function create(?string $file, stdClass $raw): self $stubBannerPath = self::retrieveStubBannerPath($raw, $basePath, $isStubGenerated, $logger); if (null !== $stubBannerPath) { - $stubBannerContents = file_contents($stubBannerPath); + $stubBannerContents = FS::getFileContents($stubBannerPath); } $stubBannerContents = self::normalizeStubBannerContents($stubBannerContents); @@ -824,7 +820,7 @@ private static function retrieveBlacklist( foreach ($blacklist as $file) { $normalizedBlacklist[] = self::normalizePath($file, $basePath); - $normalizedBlacklist[] = canonicalize(make_path_relative(trim($file), $basePath)); + $normalizedBlacklist[] = Path::canonicalize(Path::makeRelative(trim($file), $basePath)); } return array_unique($normalizedBlacklist); @@ -1108,7 +1104,7 @@ private static function processFinder( ->filter( static function (SplFileInfo $fileInfo) use ($devPackages): bool { foreach ($devPackages as $devPackage) { - if ($devPackage === longest_common_base_path([$devPackage, $fileInfo->getRealPath()])) { + if ($devPackage === Path::getLongestCommonBasePath($devPackage, $fileInfo->getRealPath())) { // File belongs to the dev package return false; } @@ -1333,8 +1329,8 @@ static function (SplFileInfo $fileInfo): ?bool { } } - $normalizePath = static fn (string $path): string => is_absolute_path($path) - ? canonicalize($path) + $normalizePath = static fn (string $path): string => Path::isAbsolute($path) + ? Path::canonicalize($path) : self::normalizePath(trim($path, '/ '), $basePath); if (array_key_exists('files', $autoload)) { @@ -1396,7 +1392,7 @@ private static function retrieveAllFiles( } $relativeDevPackages = array_map( - static fn (string $packagePath): string => make_path_relative($packagePath, $basePath), + static fn (string $packagePath): string => Path::makeRelative($packagePath, $basePath), $devPackages, ); @@ -1459,7 +1455,7 @@ private static function retrieveAllFiles( ->notName('build.xml*'); if (null !== $mainScriptPath) { - $finder->notPath(make_path_relative($mainScriptPath, $basePath)); + $finder->notPath(Path::makeRelative($mainScriptPath, $basePath)); } $finder->in($directories); @@ -1467,7 +1463,7 @@ private static function retrieveAllFiles( $excludedPaths = array_unique( array_filter( array_map( - static fn (string $path): string => make_path_relative($path, $basePath), + static fn (string $path): string => Path::makeRelative($path, $basePath), $excludedPaths, ), static fn (string $path): bool => !str_starts_with($path, '..'), @@ -1527,7 +1523,7 @@ private static function retrieveDirectoryPaths( private static function normalizePath(string $file, string $basePath): string { - return make_path_absolute(trim($file), $basePath); + return Path::makeAbsolute(trim($file), $basePath); } /** @@ -1804,7 +1800,7 @@ private static function retrieveMainScriptContents(?string $mainScriptPath): ?st return null; } - $contents = file_contents($mainScriptPath); + $contents = FS::getFileContents($mainScriptPath); // Remove the shebang line: the shebang line in a PHAR should be located in the stub file which is the real // PHAR entry point file. @@ -1840,9 +1836,9 @@ private static function retrieveComposerFiles(string $basePath): ComposerFiles }; return new ComposerFiles( - $retrieveFileAndContents(canonicalize($basePath.'/composer.json')), - $retrieveFileAndContents(canonicalize($basePath.'/composer.lock')), - $retrieveFileAndContents(canonicalize($basePath.'/vendor/composer/installed.json')), + $retrieveFileAndContents(Path::canonicalize($basePath.'/composer.json')), + $retrieveFileAndContents(Path::canonicalize($basePath.'/composer.lock')), + $retrieveFileAndContents(Path::canonicalize($basePath.'/vendor/composer/installed.json')), ); } @@ -1863,7 +1859,7 @@ private static function retrieveMap(stdClass $raw, ConfigurationLogger $logger): $processed = []; foreach ($item as $match => $replace) { - $processed[canonicalize(trim($match))] = canonicalize(trim($replace)); + $processed[Path::canonicalize(trim($match))] = Path::canonicalize(trim($replace)); } if (isset($processed['_empty_'])) { @@ -2358,7 +2354,7 @@ private static function retrieveStubBannerPath( return null; } - $bannerFile = make_path_absolute($raw->{self::BANNER_FILE_KEY}, $basePath); + $bannerFile = Path::makeAbsolute($raw->{self::BANNER_FILE_KEY}, $basePath); Assert::file($bannerFile); @@ -2391,7 +2387,7 @@ private static function retrieveStubPath(stdClass $raw, string $basePath, Config self::checkIfDefaultValue($logger, $raw, self::STUB_KEY); if (isset($raw->{self::STUB_KEY}) && is_string($raw->{self::STUB_KEY})) { - $stubPath = make_path_absolute($raw->{self::STUB_KEY}, $basePath); + $stubPath = Path::makeAbsolute($raw->{self::STUB_KEY}, $basePath); Assert::file($stubPath); @@ -2508,7 +2504,7 @@ private static function retrievePhpScoperConfig(stdClass $raw, string $basePath, self::checkIfDefaultValue($logger, $raw, self::PHP_SCOPER_KEY, self::PHP_SCOPER_CONFIG); if (!isset($raw->{self::PHP_SCOPER_KEY})) { - $configFilePath = make_path_absolute(self::PHP_SCOPER_CONFIG, $basePath); + $configFilePath = Path::makeAbsolute(self::PHP_SCOPER_CONFIG, $basePath); $configFilePath = file_exists($configFilePath) ? $configFilePath : null; return self::createPhpScoperConfig($configFilePath); @@ -2518,7 +2514,7 @@ private static function retrievePhpScoperConfig(stdClass $raw, string $basePath, Assert::string($configFile); - $configFilePath = make_path_absolute($configFile, $basePath); + $configFilePath = Path::makeAbsolute($configFile, $basePath); Assert::file($configFilePath); Assert::readable($configFilePath); @@ -2672,7 +2668,7 @@ private static function createPhpScoperCompactor( $excludedFilePaths = array_values( array_unique( array_map( - static fn (string $path): string => make_path_relative($path, $basePath), + static fn (string $path): string => Path::makeRelative($path, $basePath), array_keys( $phpScoperConfig->getExcludedFilesWithContents(), ), diff --git a/src/Configuration/ExportableConfiguration.php b/src/Configuration/ExportableConfiguration.php index 7e90ea4da..620ba3147 100644 --- a/src/Configuration/ExportableConfiguration.php +++ b/src/Configuration/ExportableConfiguration.php @@ -19,13 +19,13 @@ use KevinGH\Box\Composer\ComposerFile; use KevinGH\Box\MapFile; use SplFileInfo; +use Symfony\Component\Filesystem\Path; use Symfony\Component\Finder\SplFileInfo as SymfonySplFileInfo; use Symfony\Component\VarDumper\Cloner\VarCloner; use Symfony\Component\VarDumper\Dumper\CliDumper; use function array_flip; use function array_map; use function iter\values; -use function KevinGH\Box\FileSystem\make_path_relative; use function KevinGH\Box\get_phar_signing_algorithms; use function sort; use const SORT_STRING; @@ -110,7 +110,7 @@ private static function createPathNormalizer(string $basePath): Closure $path = $path->getPathname(); } - return make_path_relative($path, $basePath); + return Path::makeRelative($path, $basePath); }; } diff --git a/src/Console/Command/Compile.php b/src/Console/Command/Compile.php index 74b2b687f..cc8849b2c 100644 --- a/src/Console/Command/Compile.php +++ b/src/Console/Command/Compile.php @@ -21,6 +21,7 @@ use Fidry\Console\Command\Configuration as CommandConfiguration; use Fidry\Console\ExitCode; use Fidry\Console\Input\IO; +use Fidry\FileSystem\FS; use Humbug\PhpScoper\Symbol\SymbolsRegistry; use KevinGH\Box\Amp\FailureCollector; use KevinGH\Box\Box; @@ -43,6 +44,7 @@ use Symfony\Component\Console\Input\StringInput; use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Question\Question; +use Symfony\Component\Filesystem\Path; use Webmozart\Assert\Assert; use function array_map; use function array_shift; @@ -57,12 +59,6 @@ use function KevinGH\Box\bump_open_file_descriptor_limit; use function KevinGH\Box\check_php_settings; use function KevinGH\Box\disable_parallel_processing; -use function KevinGH\Box\FileSystem\chmod; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\make_path_absolute; -use function KevinGH\Box\FileSystem\make_path_relative; -use function KevinGH\Box\FileSystem\remove; -use function KevinGH\Box\FileSystem\rename; use function KevinGH\Box\format_size; use function KevinGH\Box\format_time; use function memory_get_peak_usage; @@ -285,7 +281,7 @@ private function createPhar( self::signPhar($config, $box, $config->getTmpOutputPath(), $io, $logger); if ($config->getTmpOutputPath() !== $config->getOutputPath()) { - rename($config->getTmpOutputPath(), $config->getOutputPath()); + FS::rename($config->getTmpOutputPath(), $config->getOutputPath()); } return $box; @@ -295,7 +291,7 @@ private static function getComposerBin(IO $io): ?string { $composerBin = $io->getOption(self::COMPOSER_BIN_OPTION)->asNullableNonEmptyString(); - return null === $composerBin ? null : make_path_absolute($composerBin, getcwd()); + return null === $composerBin ? null : Path::makeAbsolute($composerBin, getcwd()); } private function removeExistingArtifacts(Configuration $config, CompilerLogger $logger, bool $debug): void @@ -303,9 +299,9 @@ private function removeExistingArtifacts(Configuration $config, CompilerLogger $ $path = $config->getOutputPath(); if ($debug) { - remove(self::DEBUG_DIR); + FS::remove(self::DEBUG_DIR); - dump_file( + FS::dumpFile( self::DEBUG_DIR.'/.box_configuration', ConfigurationExporter::export($config), ); @@ -323,7 +319,7 @@ private function removeExistingArtifacts(Configuration $config, CompilerLogger $ ), ); - remove($path); + FS::remove($path); } private static function checkComposerVersion( @@ -531,7 +527,7 @@ private static function registerMainScript(Configuration $config, Box $box, Comp $config->getMainScriptContents(), ); - $relativeMain = make_path_relative($main, $config->getBasePath()); + $relativeMain = Path::makeRelative($main, $config->getBasePath()); if ($localMain !== $relativeMain) { $logger->log( @@ -752,7 +748,7 @@ private static function signPhar( CompilerLogger $logger, ): void { // Sign using private key when applicable - remove($path.'.pubkey'); + FS::remove($path.'.pubkey'); $key = $config->getPrivateKeyPath(); @@ -805,7 +801,7 @@ private static function correctPermissions(string $path, Configuration $config, ), ); - chmod($path, $chmod); + FS::chmod($path, $chmod); } } diff --git a/src/Console/Command/Extract.php b/src/Console/Command/Extract.php index b8f2ee2c9..896814cba 100644 --- a/src/Console/Command/Extract.php +++ b/src/Console/Command/Extract.php @@ -18,6 +18,7 @@ use Fidry\Console\Command\Configuration; use Fidry\Console\ExitCode; use Fidry\Console\Input\IO; +use Fidry\FileSystem\FS; use KevinGH\Box\Phar\PharFactory; use KevinGH\Box\Phar\PharMeta; use KevinGH\Box\Pharaoh\InvalidPhar; @@ -28,12 +29,7 @@ use Throwable; use function file_exists; use function KevinGH\Box\check_php_settings; -use function KevinGH\Box\FileSystem\copy; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\mkdir; -use function KevinGH\Box\FileSystem\remove; use function realpath; -use function Safe\file_get_contents; use function sprintf; use const DIRECTORY_SEPARATOR; @@ -100,7 +96,7 @@ public function execute(IO $io): int ); if ($canDelete) { - remove($outputDir); + FS::remove($outputDir); // Continue } else { // Do nothing @@ -108,7 +104,7 @@ public function execute(IO $io): int } } - mkdir($outputDir); + FS::mkdir($outputDir); try { self::dumpPhar($pharPath, $outputDir); @@ -157,11 +153,11 @@ private static function dumpPhar(string $file, string $tmpDir): string $tmpPubKey = $tmpFile.'.pubkey'; try { - copy($file, $tmpFile, true); + FS::copy($file, $tmpFile, true); if (file_exists($pubKey)) { - copy($pubKey, $tmpPubKey, true); - $pubKeyContent = file_get_contents($pubKey); + FS::copy($pubKey, $tmpPubKey, true); + $pubKeyContent = FS::getFileContents($pubKey); } $phar = PharFactory::create($tmpFile); @@ -169,18 +165,18 @@ private static function dumpPhar(string $file, string $tmpDir): string $phar->extractTo($tmpDir); } catch (Throwable $throwable) { - remove([$tmpFile, $tmpPubKey]); + FS::remove([$tmpFile, $tmpPubKey]); throw $throwable; } - dump_file( + FS::dumpFile( $tmpDir.DIRECTORY_SEPARATOR.self::PHAR_META_PATH, $pharMeta->toJson(), ); // Cleanup the temporary PHAR. - remove([$tmpFile, $tmpPubKey]); + FS::remove([$tmpFile, $tmpPubKey]); return $tmpDir; } diff --git a/src/Console/Command/GenerateDockerFile.php b/src/Console/Command/GenerateDockerFile.php index 94da1d52d..52dd7c61d 100644 --- a/src/Console/Command/GenerateDockerFile.php +++ b/src/Console/Command/GenerateDockerFile.php @@ -19,6 +19,7 @@ use Fidry\Console\Command\Configuration; use Fidry\Console\ExitCode; use Fidry\Console\Input\IO; +use Fidry\FileSystem\FS; use KevinGH\Box\DockerFileGenerator; use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputInterface; @@ -28,8 +29,6 @@ use Webmozart\Assert\Assert; use function file_exists; use function getcwd; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\make_path_relative; use function realpath; use function sprintf; @@ -179,7 +178,7 @@ private function generateFile(string $pharPath, string $requirementsPhar, IO $io $dockerFileContents = DockerFileGenerator::createForRequirements( $requirements, - make_path_relative($pharPath, getcwd()), + Path::makeRelative($pharPath, getcwd()), ) ->generateStub(); @@ -198,7 +197,7 @@ private function generateFile(string $pharPath, string $requirementsPhar, IO $io } } - dump_file(self::DOCKER_FILE_NAME, $dockerFileContents); + FS::dumpFile(self::DOCKER_FILE_NAME, $dockerFileContents); $io->success('Done'); diff --git a/src/Console/Command/Process.php b/src/Console/Command/Process.php index 17d6697fc..a0ebcabda 100644 --- a/src/Console/Command/Process.php +++ b/src/Console/Command/Process.php @@ -18,6 +18,7 @@ use Fidry\Console\Command\Configuration as ConsoleConfiguration; use Fidry\Console\ExitCode; use Fidry\Console\Input\IO; +use Fidry\FileSystem\FS; use Humbug\PhpScoper\Symbol\SymbolsRegistry; use KevinGH\Box\Compactor\Compactor; use KevinGH\Box\Compactor\Compactors; @@ -28,6 +29,7 @@ use Symfony\Component\Console\Input\InputArgument; use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; +use Symfony\Component\Filesystem\Path; use Symfony\Component\VarDumper\Cloner\VarCloner; use Symfony\Component\VarDumper\Dumper\CliDumper; use function array_map; @@ -37,9 +39,6 @@ use function getcwd; use function implode; use function KevinGH\Box\check_php_settings; -use function KevinGH\Box\FileSystem\file_contents; -use function KevinGH\Box\FileSystem\make_path_absolute; -use function KevinGH\Box\FileSystem\make_path_relative; use function putenv; use function sprintf; use const KevinGH\Box\BOX_ALLOW_XDEBUG; @@ -102,12 +101,12 @@ public function execute(IO $io): int $filePath = $io->getArgument(self::FILE_ARGUMENT)->asNonEmptyString(); - $path = make_path_relative($filePath, $config->getBasePath()); + $path = Path::makeRelative($filePath, $config->getBasePath()); $compactors = self::retrieveCompactors($config); - $fileContents = file_contents( - $absoluteFilePath = make_path_absolute( + $fileContents = FS::getFileContents( + $absoluteFilePath = Path::makeAbsolute( $filePath, getcwd(), ), diff --git a/src/Console/Php/PhpSettingsHandler.php b/src/Console/Php/PhpSettingsHandler.php index 2e30d0034..c268c7444 100644 --- a/src/Console/Php/PhpSettingsHandler.php +++ b/src/Console/Php/PhpSettingsHandler.php @@ -15,13 +15,13 @@ namespace KevinGH\Box\Console\Php; use Composer\XdebugHandler\XdebugHandler; +use Fidry\FileSystem\FS; use KevinGH\Box\Phar\PharPhpSettings; use Psr\Log\LoggerInterface; use Webmozart\Assert\Assert; use function getenv; use function ini_get; use function ini_set; -use function KevinGH\Box\FileSystem\append_to_file; use function KevinGH\Box\format_size; use function KevinGH\Box\memory_to_bytes; use function sprintf; @@ -82,7 +82,7 @@ private function disablePharReadonly(): void if (PharPhpSettings::isReadonly()) { Assert::notNull($this->tmpIni); - append_to_file($this->tmpIni, 'phar.readonly=0'.PHP_EOL); + FS::appendToFile($this->tmpIni, 'phar.readonly=0'.PHP_EOL); $this->logger->debug('Configured `phar.readonly=0`'); } diff --git a/src/FileSystem/FileSystem.php b/src/FileSystem/FileSystem.php deleted file mode 100644 index 98cd2f2b0..000000000 --- a/src/FileSystem/FileSystem.php +++ /dev/null @@ -1,572 +0,0 @@ - - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace KevinGH\Box\FileSystem; - -use FilesystemIterator; -use Symfony\Component\Filesystem\Exception\IOException; -use Symfony\Component\Filesystem\Filesystem as SymfonyFilesystem; -use Symfony\Component\Filesystem\Path; -use Traversable; -use Webmozart\Assert\Assert; -use function array_reverse; -use function defined; -use function error_get_last; -use function escapeshellarg; -use function exec; -use function file_exists; -use function file_get_contents; -use function is_array; -use function is_dir; -use function is_link; -use function iterator_to_array; -use function random_int; -use function realpath; -use function rmdir; -use function sprintf; -use function str_replace; -use function sys_get_temp_dir; -use function unlink; -use const DIRECTORY_SEPARATOR; - -/** - * @author Fabien Potencier - * @author Bernhard Schussek - * @author Thomas Schulz - * - * @private - */ -final class FileSystem extends SymfonyFilesystem -{ - /** - * Canonicalizes the given path. - * - * During normalization, all slashes are replaced by forward slashes ("/"). - * Furthermore, all "." and ".." segments are removed as far as possible. - * ".." segments at the beginning of relative paths are not removed. - * - * ```php - * echo Path::canonicalize("\webmozart\puli\..\css\style.css"); - * // => /webmozart/css/style.css - * - * echo Path::canonicalize("../css/./style.css"); - * // => ../css/style.css - * ``` - * - * This method is able to deal with both UNIX and Windows paths. - * - * @param string $path A path string - * - * @return string The canonical path - */ - public function canonicalize(string $path): string - { - return Path::canonicalize($path); - } - - /** - * Normalizes the given path. - * - * During normalization, all slashes are replaced by forward slashes ("/"). - * Contrary to {@link canonicalize()}, this method does not remove invalid - * or dot path segments. Consequently, it is much more efficient and should - * be used whenever the given path is known to be a valid, absolute system - * path. - * - * This method is able to deal with both UNIX and Windows paths. - * - * @param string $path a path string - * - * @return string the normalized path - */ - public function normalize(string $path): string - { - return Path::normalize($path); - } - - /** - * Returns the directory part of the path. - * - * This method is similar to PHP's dirname(), but handles various cases - * where dirname() returns a weird result: - * - * - dirname() does not accept backslashes on UNIX - * - dirname("C:/webmozart") returns "C:", not "C:/" - * - dirname("C:/") returns ".", not "C:/" - * - dirname("C:") returns ".", not "C:/" - * - dirname("webmozart") returns ".", not "" - * - dirname() does not canonicalize the result - * - * This method fixes these shortcomings and behaves like dirname() - * otherwise. - * - * The result is a canonical path. - * - * @param string $path a path string - * - * @return string The canonical directory part. Returns the root directory - * if the root directory is passed. Returns an empty string - * if a relative path is passed that contains no slashes. - * Returns an empty string if an empty string is passed. - */ - public function getDirectory(string $path): string - { - return Path::getDirectory($path); - } - - /** - * Returns canonical path of the user's home directory. - * - * Supported operating systems: - * - * - UNIX - * - Windows8 and upper - * - * If your operation system or environment isn't supported, an exception is thrown. - * - * The result is a canonical path. - * - * @return string The canonical home directory - */ - public function getHomeDirectory(): string - { - return Path::getHomeDirectory(); - } - - /** - * Returns the root directory of a path. - * - * The result is a canonical path. - * - * @param string $path a path string - * - * @return string The canonical root directory. Returns an empty string if - * the given path is relative or empty. - */ - public function getRoot(string $path): string - { - return Path::getRoot($path); - } - - /** - * Returns the file name from a file path. - * - * @param string $path the path string - * - * @return string The file name - */ - public function getFilename(string $path): string - { - return Path::getFilename($path); - } - - /** - * Returns the file name without the extension from a file path. - * - * @param string $path the path string - * @param null|string $extension if specified, only that extension is cut - * off (may contain leading dot) - * - * @return string the file name without extension - */ - public function getFilenameWithoutExtension($path, $extension = null): string - { - return Path::getFilenameWithoutExtension($path, $extension); - } - - /** - * Returns the extension from a file path. - * - * @param string $path the path string - * @param bool $forceLowerCase forces the extension to be lower-case - * (requires mbstring extension for correct - * multi-byte character handling in extension) - * - * @return string the extension of the file path (without leading dot) - */ - public function getExtension(string $path, bool $forceLowerCase = false): string - { - return Path::getExtension($path, $forceLowerCase); - } - - /** - * Returns whether the path has an extension. - * - * @param string $path the path string - * @param null|array|string $extensions if null or not provided, checks if - * an extension exists, otherwise - * checks for the specified extension - * or array of extensions (with or - * without leading dot) - * @param bool $ignoreCase whether to ignore case-sensitivity - * (requires mbstring extension for - * correct multi-byte character - * handling in the extension) - * - * @return bool returns `true` if the path has an (or the specified) - * extension and `false` otherwise - */ - public function hasExtension(string $path, $extensions = null, bool $ignoreCase = false): bool - { - return Path::hasExtension($path, $extensions, $ignoreCase); - } - - /** - * Changes the extension of a path string. - * - * @param string $path The path string with filename.ext to change. - * @param string $extension new extension (with or without leading dot) - * - * @return string the path string with new file extension - */ - public function changeExtension(string $path, string $extension): string - { - return Path::changeExtension($path, $extension); - } - - /** - * Returns whether a path is relative. - * - * @param string $path a path string - * - * @return bool returns true if the path is relative or empty, false if - * it is absolute - */ - public function isRelativePath(string $path): bool - { - return !$this->isAbsolutePath($path); - } - - /** - * Turns a relative path into an absolute path. - * - * Usually, the relative path is appended to the given base path. Dot - * segments ("." and "..") are removed/collapsed and all slashes turned - * into forward slashes. - * - * ```php - * echo Path::makeAbsolute("../style.css", "/webmozart/puli/css"); - * // => /webmozart/puli/style.css - * ``` - * - * If an absolute path is passed, that path is returned unless its root - * directory is different than the one of the base path. In that case, an - * exception is thrown. - * - * ```php - * Path::makeAbsolute("/style.css", "/webmozart/puli/css"); - * // => /style.css - * - * Path::makeAbsolute("C:/style.css", "C:/webmozart/puli/css"); - * // => C:/style.css - * - * Path::makeAbsolute("C:/style.css", "/webmozart/puli/css"); - * // InvalidArgumentException - * ``` - * - * If the base path is not an absolute path, an exception is thrown. - * - * The result is a canonical path. - * - * @param string $path a path to make absolute - * @param string $basePath an absolute base path - * - * @return string an absolute path in canonical form - */ - public function makeAbsolute(string $path, string $basePath): string - { - return Path::makeAbsolute($path, $basePath); - } - - /** - * Turns a path into a relative path. - * - * The relative path is created relative to the given base path: - * - * ```php - * echo Path::makeRelative("/webmozart/style.css", "/webmozart/puli"); - * // => ../style.css - * ``` - * - * If a relative path is passed and the base path is absolute, the relative - * path is returned unchanged: - * - * ```php - * Path::makeRelative("style.css", "/webmozart/puli/css"); - * // => style.css - * ``` - * - * If both paths are relative, the relative path is created with the - * assumption that both paths are relative to the same directory: - * - * ```php - * Path::makeRelative("style.css", "webmozart/puli/css"); - * // => ../../../style.css - * ``` - * - * If both paths are absolute, their root directory must be the same, - * otherwise an exception is thrown: - * - * ```php - * Path::makeRelative("C:/webmozart/style.css", "/webmozart/puli"); - * // InvalidArgumentException - * ``` - * - * If the passed path is absolute, but the base path is not, an exception - * is thrown as well: - * - * ```php - * Path::makeRelative("/webmozart/style.css", "webmozart/puli"); - * // InvalidArgumentException - * ``` - * - * If the base path is not an absolute path, an exception is thrown. - * - * The result is a canonical path. - * - * @param string $path a path to make relative - * @param string $basePath a base path - * - * @return string a relative path in canonical form - */ - public function makeRelative(string $path, string $basePath): string - { - return Path::makeRelative($path, $basePath); - } - - /** - * Returns whether the given path is on the local filesystem. - * - * @param string $path a path string - * - * @return bool returns true if the path is local, false for a URL - */ - public function isLocal(string $path): bool - { - return Path::isLocal($path); - } - - /** - * Returns the longest common base path of a set of paths. - * - * Dot segments ("." and "..") are removed/collapsed and all slashes turned - * into forward slashes. - * - * ```php - * $basePath = Path::getLongestCommonBasePath(array( - * '/webmozart/css/style.css', - * '/webmozart/css/..' - * )); - * // => /webmozart - * ``` - * - * The root is returned if no common base path can be found: - * - * ```php - * $basePath = Path::getLongestCommonBasePath(array( - * '/webmozart/css/style.css', - * '/puli/css/..' - * )); - * // => / - * ``` - * - * If the paths are located on different Windows partitions, `null` is - * returned. - * - * ```php - * $basePath = Path::getLongestCommonBasePath(array( - * 'C:/webmozart/css/style.css', - * 'D:/webmozart/css/..' - * )); - * // => null - * ``` - * - * @param array $paths a list of paths - * - * @return null|string the longest common base path in canonical form or - * `null` if the paths are on different Windows - * partitions - */ - public function getLongestCommonBasePath(array $paths): ?string - { - return Path::getLongestCommonBasePath(...$paths); - } - - /** - * Joins two or more path strings. - * - * The result is a canonical path. - * - * @param string|string[] $paths path parts as parameters or array - * - * @return string the joint path - */ - public function join(array|string $paths): string - { - return Path::join($paths); - } - - /** - * Returns whether a path is a base path of another path. - * - * Dot segments ("." and "..") are removed/collapsed and all slashes turned - * into forward slashes. - * - * ```php - * Path::isBasePath('/webmozart', '/webmozart/css'); - * // => true - * - * Path::isBasePath('/webmozart', '/webmozart'); - * // => true - * - * Path::isBasePath('/webmozart', '/webmozart/..'); - * // => false - * - * Path::isBasePath('/webmozart', '/puli'); - * // => false - * ``` - * - * @param string $basePath the base path to test - * @param string $ofPath the other path - * - * @return bool whether the base path is a base path of the other path - */ - public function isBasePath(string $basePath, string $ofPath): bool - { - return Path::isBasePath($basePath, $ofPath); - } - - public function escapePath(string $path): string - { - return str_replace('/', DIRECTORY_SEPARATOR, $path); - } - - /** - * Gets the contents of a file. - * - * @param string $file File path - * - * @throws IOException If the file cannot be read - * - * @return string File contents - */ - public function getFileContents(string $file): string - { - Assert::file($file); - Assert::readable($file); - - if (false === ($contents = @file_get_contents($file))) { - throw new IOException( - sprintf( - 'Failed to read file "%s": %s.', - $file, - error_get_last()['message'], - ), - 0, - null, - $file, - ); - } - - return $contents; - } - - /** - * Creates a temporary directory. - * - * @param string $namespace the directory path in the system's temporary directory - * @param string $className the name of the test class - * - * @return string the path to the created directory - */ - public function makeTmpDir(string $namespace, string $className): string - { - if (false !== ($pos = mb_strrpos($className, '\\'))) { - $shortClass = mb_substr($className, $pos + 1); - } else { - $shortClass = $className; - } - - // Usage of realpath() is important if the temporary directory is a - // symlink to another directory (e.g. /var => /private/var on some Macs) - // We want to know the real path to avoid comparison failures with - // code that uses real paths only - $systemTempDir = str_replace('\\', '/', realpath(sys_get_temp_dir())); - $basePath = $systemTempDir.'/'.$namespace.'/'.$shortClass; - - $result = false; - $attempts = 0; - - do { - $tmpDir = $this->escapePath($basePath.random_int(10000, 99999)); - - try { - $this->mkdir($tmpDir, 0o777); - - $result = true; - } catch (IOException) { - ++$attempts; - } - } while (false === $result && $attempts <= 10); - - return $tmpDir; - } - - /** - * Removes files or directories. - * - * @param iterable|string $files A filename, an array of files, or a \Traversable instance to remove - * - * @throws IOException When removal fails - */ - public function remove($files): void - { - if ($files instanceof Traversable) { - $files = iterator_to_array($files, false); - } elseif (!is_array($files)) { - $files = [$files]; - } - $files = array_reverse($files); - foreach ($files as $file) { - // MODIFIED CODE - if (defined('PHP_WINDOWS_VERSION_BUILD') && is_dir($file)) { - exec(sprintf('rd /s /q %s', escapeshellarg($file))); - // - MODIFIED CODE - } elseif (is_link($file)) { - // See https://bugs.php.net/52176 - if (!@(unlink($file) || '\\' !== DIRECTORY_SEPARATOR || rmdir($file)) && file_exists($file)) { - $error = error_get_last(); - - throw new IOException(sprintf('Failed to remove symlink "%s": %s.', $file, $error['message'])); - } - } elseif (is_dir($file)) { - $this->remove(new FilesystemIterator($file, FilesystemIterator::CURRENT_AS_PATHNAME | FilesystemIterator::SKIP_DOTS)); - - if (!@rmdir($file) && file_exists($file)) { - $error = error_get_last(); - - throw new IOException(sprintf('Failed to remove directory "%s": %s.', $file, $error['message'])); - } - } elseif (!@unlink($file) && file_exists($file)) { - $error = error_get_last(); - - throw new IOException(sprintf('Failed to remove file "%s": %s.', $file, $error['message'])); - // MODIFIED CODE - } elseif (file_exists($file)) { - throw new IOException(sprintf('Failed to remove file "%s".', $file)); - // - MODIFIED CODE - } - } - } -} diff --git a/src/FileSystem/file_system.php b/src/FileSystem/file_system.php deleted file mode 100644 index 41d0bf4b7..000000000 --- a/src/FileSystem/file_system.php +++ /dev/null @@ -1,982 +0,0 @@ - - * Théo Fidry - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace KevinGH\Box\FileSystem; - -use Symfony\Component\Filesystem\Exception\FileNotFoundException; -use Symfony\Component\Filesystem\Exception\IOException; -use Symfony\Component\Filesystem\Path; -use Traversable; - -/** - * Canonicalizes the given path. - * - * During normalization, all slashes are replaced by forward slashes ("/"). - * Furthermore, all "." and ".." segments are removed as far as possible. - * ".." segments at the beginning of relative paths are not removed. - * - * ```php - * echo Path::canonicalize("\webmozart\puli\..\css\style.css"); - * // => /webmozart/css/style.css - * - * echo Path::canonicalize("../css/./style.css"); - * // => ../css/style.css - * ``` - * - * This method is able to deal with both UNIX and Windows paths. - * - * @param string $path A path string - * - * @return string The canonical path - * - * @private - */ -function canonicalize(string $path): string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->canonicalize($path); -} - -/** - * Normalizes the given path. - * - * During normalization, all slashes are replaced by forward slashes ("/"). - * Contrary to {@link canonicalize()}, this method does not remove invalid - * or dot path segments. Consequently, it is much more efficient and should - * be used whenever the given path is known to be a valid, absolute system - * path. - * - * This method is able to deal with both UNIX and Windows paths. - * - * @param string $path a path string - * - * @return string the normalized path - * - * @private - */ -function normalize(string $path): string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->normalize($path); -} - -/** - * Returns the directory part of the path. - * - * This method is similar to PHP's dirname(), but handles various cases - * where dirname() returns a weird result: - * - * - dirname() does not accept backslashes on UNIX - * - dirname("C:/webmozart") returns "C:", not "C:/" - * - dirname("C:/") returns ".", not "C:/" - * - dirname("C:") returns ".", not "C:/" - * - dirname("webmozart") returns ".", not "" - * - dirname() does not canonicalize the result - * - * This method fixes these shortcomings and behaves like dirname() - * otherwise. - * - * The result is a canonical path. - * - * @param string $path a path string - * - * @return string The canonical directory part. Returns the root directory - * if the root directory is passed. Returns an empty string - * if a relative path is passed that contains no slashes. - * Returns an empty string if an empty string is passed. - * - * @private - */ -function directory(string $path): string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->getDirectory($path); -} - -/** - * Returns canonical path of the user's home directory. - * - * Supported operating systems: - * - * - UNIX - * - Windows8 and upper - * - * If your operation system or environment isn't supported, an exception is thrown. - * - * The result is a canonical path. - * - * @return string The canonical home directory - * - * @private - */ -function home_directory(): string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->getHomeDirectory(); -} - -/** - * Returns the root directory of a path. - * - * The result is a canonical path. - * - * @param string $path a path string - * - * @return string The canonical root directory. Returns an empty string if - * the given path is relative or empty. - * - * @private - */ -function root(string $path): string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->getRoot($path); -} - -/** - * Returns the file name from a file path. - * - * @param string $path the path string - * - * @return string The file name - * - * @private - */ -function filename(string $path): string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->getFilename($path); -} - -/** - * Returns the file name without the extension from a file path. - * - * @param string $path the path string - * @param null|string $extension if specified, only that extension is cut - * off (may contain leading dot) - * - * @return string the file name without extension - * - * @private - */ -function filename_without_extension($path, $extension = null): string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->getFilenameWithoutExtension($path, $extension); -} - -/** - * Returns the extension from a file path. - * - * @param string $path the path string - * @param bool $forceLowerCase forces the extension to be lower-case - * (requires mbstring extension for correct - * multi-byte character handling in extension) - * - * @return string the extension of the file path (without leading dot) - * - * @private - */ -function extension(string $path, bool $forceLowerCase = false): string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->getExtension($path, $forceLowerCase); -} - -/** - * Returns whether the path has an extension. - * - * @param string $path the path string - * @param null|array|string $extensions if null or not provided, checks if - * an extension exists, otherwise - * checks for the specified extension - * or array of extensions (with or - * without leading dot) - * @param bool $ignoreCase whether to ignore case-sensitivity - * (requires mbstring extension for - * correct multi-byte character - * handling in the extension) - * - * @return bool returns `true` if the path has an (or the specified) - * extension and `false` otherwise - * - * @private - */ -function has_extension(string $path, $extensions = null, bool $ignoreCase = false): bool -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->hasExtension($path, $extensions, $ignoreCase); -} - -/** - * Changes the extension of a path string. - * - * @param string $path The path string with filename.ext to change. - * @param string $extension new extension (with or without leading dot) - * - * @return string the path string with new file extension - * - * @private - */ -function change_extension(string $path, string $extension): string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->changeExtension($path, $extension); -} - -/** - * Returns whether the file path is an absolute path. - * - * @param string $path a path string - * - * @private - */ -function is_absolute_path(string $path): bool -{ - return Path::isAbsolute($path); -} - -/** - * Returns whether a path is relative. - * - * @param string $path a path string - * - * @return bool returns true if the path is relative or empty, false if - * it is absolute - * - * @private - */ -function is_relative_path(string $path): bool -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->isRelativePath($path); -} - -/** - * Turns a relative path into an absolute path. - * - * Usually, the relative path is appended to the given base path. Dot - * segments ("." and "..") are removed/collapsed and all slashes turned - * into forward slashes. - * - * ```php - * echo Path::makeAbsolute("../style.css", "/webmozart/puli/css"); - * // => /webmozart/puli/style.css - * ``` - * - * If an absolute path is passed, that path is returned unless its root - * directory is different than the one of the base path. In that case, an - * exception is thrown. - * - * ```php - * Path::makeAbsolute("/style.css", "/webmozart/puli/css"); - * // => /style.css - * - * Path::makeAbsolute("C:/style.css", "C:/webmozart/puli/css"); - * // => C:/style.css - * - * Path::makeAbsolute("C:/style.css", "/webmozart/puli/css"); - * // InvalidArgumentException - * ``` - * - * If the base path is not an absolute path, an exception is thrown. - * - * The result is a canonical path. - * - * @param string $path a path to make absolute - * @param string $basePath an absolute base path - * - * @return string an absolute path in canonical form - * - * @private - */ -function make_path_absolute(string $path, string $basePath): string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->makeAbsolute($path, $basePath); -} - -/** - * Turns a path into a relative path. - * - * The relative path is created relative to the given base path: - * - * ```php - * echo Path::makeRelative("/webmozart/style.css", "/webmozart/puli"); - * // => ../style.css - * ``` - * - * If a relative path is passed and the base path is absolute, the relative - * path is returned unchanged: - * - * ```php - * Path::makeRelative("style.css", "/webmozart/puli/css"); - * // => style.css - * ``` - * - * If both paths are relative, the relative path is created with the - * assumption that both paths are relative to the same directory: - * - * ```php - * Path::makeRelative("style.css", "webmozart/puli/css"); - * // => ../../../style.css - * ``` - * - * If both paths are absolute, their root directory must be the same, - * otherwise an exception is thrown: - * - * ```php - * Path::makeRelative("C:/webmozart/style.css", "/webmozart/puli"); - * // InvalidArgumentException - * ``` - * - * If the passed path is absolute, but the base path is not, an exception - * is thrown as well: - * - * ```php - * Path::makeRelative("/webmozart/style.css", "webmozart/puli"); - * // InvalidArgumentException - * ``` - * - * If the base path is not an absolute path, an exception is thrown. - * - * The result is a canonical path. - * - * @param string $path a path to make relative - * @param string $basePath a base path - * - * @return string a relative path in canonical form - * - * @private - */ -function make_path_relative(string $path, string $basePath): string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->makeRelative($path, $basePath); -} - -/** - * Returns whether the given path is on the local filesystem. - * - * @param string $path a path string - * - * @return bool returns true if the path is local, false for a URL - * - * @private - */ -function is_local(string $path): bool -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->isLocal($path); -} - -/** - * Returns the longest common base path of a set of paths. - * - * Dot segments ("." and "..") are removed/collapsed and all slashes turned - * into forward slashes. - * - * ```php - * $basePath = Path::getLongestCommonBasePath(array( - * '/webmozart/css/style.css', - * '/webmozart/css/..' - * )); - * // => /webmozart - * ``` - * - * The root is returned if no common base path can be found: - * - * ```php - * $basePath = Path::getLongestCommonBasePath(array( - * '/webmozart/css/style.css', - * '/puli/css/..' - * )); - * // => / - * ``` - * - * If the paths are located on different Windows partitions, `null` is - * returned. - * - * ```php - * $basePath = Path::getLongestCommonBasePath(array( - * 'C:/webmozart/css/style.css', - * 'D:/webmozart/css/..' - * )); - * // => null - * ``` - * - * @param array $paths a list of paths - * - * @return null|string the longest common base path in canonical form or - * `null` if the paths are on different Windows - * partitions - * - * @private - */ -function longest_common_base_path(array $paths): ?string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->getLongestCommonBasePath($paths); -} - -/** - * Joins two or more path strings. - * - * The result is a canonical path. - * - * @param string|string[] $paths path parts as parameters or array - * - * @return string the joint path - * - * @private - */ -function join(array|string $paths): string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->join($paths); -} - -/** - * Returns whether a path is a base path of another path. - * - * Dot segments ("." and "..") are removed/collapsed and all slashes turned - * into forward slashes. - * - * ```php - * Path::isBasePath('/webmozart', '/webmozart/css'); - * // => true - * - * Path::isBasePath('/webmozart', '/webmozart'); - * // => true - * - * Path::isBasePath('/webmozart', '/webmozart/..'); - * // => false - * - * Path::isBasePath('/webmozart', '/puli'); - * // => false - * ``` - * - * @param string $basePath the base path to test - * @param string $ofPath the other path - * - * @return bool whether the base path is a base path of the other path - * - * @private - */ -function is_base_path(string $basePath, string $ofPath): bool -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->isBasePath($basePath, $ofPath); -} - -function escape_path(string $path): string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->escapePath($path); -} - -/** - * Gets the contents of a file. - * - * @param string $file File path - * - * @throws IOException If the file cannot be read - * - * @return string File contents - * - * @private - */ -function file_contents(string $file): string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->getFileContents($file); -} - -/** - * Copies a file. - * - * If the target file is older than the origin file, it's always overwritten. - * If the target file is newer, it is overwritten only when the - * $overwriteNewerFiles option is set to true. - * - * @param string $originFile The original filename - * @param string $targetFile The target filename - * @param bool $overwriteNewerFiles If true, target files newer than origin files are overwritten - * - * @throws FileNotFoundException When originFile doesn't exist - * @throws IOException When copy fails - * - * @private - */ -function copy(string $originFile, string $targetFile, bool $overwriteNewerFiles = false): void -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - $fileSystem->copy($originFile, $targetFile, $overwriteNewerFiles); -} - -/** - * Creates a directory recursively. - * - * @param iterable|string $dirs The directory path - * @param int $mode The directory mode - * - * @throws IOException On any directory creation failure - * - * @private - */ -function mkdir(iterable|string $dirs, int $mode = 0o777): void -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - $fileSystem->mkdir($dirs, $mode); -} - -/** - * Removes files or directories. - * - * @param iterable|string $files A filename, an array of files, or a \Traversable instance to remove - * - * @throws IOException When removal fails - * - * @private - */ -function remove(iterable|string $files): void -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - $fileSystem->remove($files); -} - -/** - * Checks the existence of files or directories. - * - * @param iterable|string $files A filename, an array of files, or a \Traversable instance to check - * - * @return bool true if the file exists, false otherwise - * - * @private - */ -function exists(iterable|string $files): bool -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->exists($files); -} - -/** - * Sets access and modification time of file. - * - * @param iterable|string $files A filename, an array of files, or a \Traversable instance to create - * @param int $time The touch time as a Unix timestamp - * @param int $atime The access time as a Unix timestamp - * - * @throws IOException When touch fails - * - * @private - */ -function touch(iterable|string $files, ?int $time = null, ?int $atime = null): void -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - $fileSystem->touch($files, $time, $atime); -} - -/** - * Change mode for an array of files or directories. - * - * @param iterable|string $files A filename, an array of files, or a \Traversable instance to change mode - * @param int $mode The new mode (octal) - * @param int $umask The mode mask (octal) - * @param bool $recursive Whether change the mod recursively or not - * - * @throws IOException When the change fail - * - * @private - */ -function chmod(iterable|string $files, int $mode, int $umask = 0, bool $recursive = false): void -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - $fileSystem->chmod($files, $mode, $umask, $recursive); -} - -/** - * Change the owner of an array of files or directories. - * - * @param iterable|string $files A filename, an array of files, or a \Traversable instance to change owner - * @param string $user The new owner user name - * @param bool $recursive Whether change the owner recursively or not - * - * @throws IOException When the change fail - * - * @private - */ -function chown(iterable|string $files, string $user, bool $recursive = false): void -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - $fileSystem->chown($files, $user, $recursive); -} - -/** - * Change the group of an array of files or directories. - * - * @param iterable|string $files A filename, an array of files, or a \Traversable instance to change group - * @param string $group The group name - * @param bool $recursive Whether change the group recursively or not - * - * @throws IOException When the change fail - * - * @private - */ -function chgrp(iterable|string $files, string $group, bool $recursive = false): void -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - $fileSystem->chgrp($files, $group, $recursive); -} - -/** - * Renames a file or a directory. - * - * @param string $origin The origin filename or directory - * @param string $target The new filename or directory - * @param bool $overwrite Whether to overwrite the target if it already exists - * - * @throws IOException When target file or directory already exists - * @throws IOException When origin cannot be renamed - * - * @private - */ -function rename(string $origin, string $target, bool $overwrite = false): void -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - $fileSystem->rename($origin, $target, $overwrite); -} - -/** - * Creates a symbolic link or copy a directory. - * - * @param string $originDir The origin directory path - * @param string $targetDir The symbolic link name - * @param bool $copyOnWindows Whether to copy files if on Windows - * - * @throws IOException When symlink fails - * - * @private - */ -function symlink(string $originDir, string $targetDir, bool $copyOnWindows = false): void -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - $fileSystem->symlink($originDir, $targetDir, $copyOnWindows); -} - -/** - * Creates a hard link, or several hard links to a file. - * - * @param string $originFile The original file - * @param string|string[] $targetFiles The target file(s) - * - * @throws FileNotFoundException When original file is missing or not a file - * @throws IOException When link fails, including if link already exists - * - * @private - */ -function hardlink(string $originFile, array|string $targetFiles): void -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - $fileSystem->hardlink($originFile, $targetFiles); -} - -/** - * Resolves links in paths. - * - * With $canonicalize = false (default) - * - if $path does not exist or is not a link, returns null - * - if $path is a link, returns the next direct target of the link without considering the existence of the target - * - * With $canonicalize = true - * - if $path does not exist, returns null - * - if $path exists, returns its absolute fully resolved final version - * - * @param string $path A filesystem path - * @param bool $canonicalize Whether or not to return a canonicalized path - * - * @private - */ -function readlink(string $path, bool $canonicalize = false): ?string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->readlink($path, $canonicalize); -} - -/** - * Mirrors a directory to another. - * - * @param string $originDir The origin directory - * @param string $targetDir The target directory - * @param Traversable $iterator A Traversable instance - * @param array $options An array of boolean options - * Valid options are: - * - $options['override'] Whether to override an existing file on copy or not (see copy()) - * - $options['copy_on_windows'] Whether to copy files instead of links on Windows (see symlink()) - * - $options['delete'] Whether to delete files that are not in the source directory (defaults to false) - * - * @throws IOException When file type is unknown - * - * @private - */ -function mirror(string $originDir, string $targetDir, ?Traversable $iterator = null, array $options = []): void -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - $fileSystem->mirror($originDir, $targetDir, $iterator, $options); -} - -/** - * Creates a temporary directory. - * - * @param string $namespace the directory path in the system's temporary directory - * @param string $className the name of the test class - * - * @return string the path to the created directory - * - * @private - */ -function make_tmp_dir(string $namespace, string $className): string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->makeTmpDir($namespace, $className); -} - -/** - * Creates a temporary file with support for custom stream wrappers. - * - * @param string $dir The directory where the temporary filename will be created - * @param string $prefix The prefix of the generated temporary filename - * Note: Windows uses only the first three characters of prefix - * - * @return string The new temporary filename (with path), or throw an exception on failure - * - * @private - */ -function tempnam($dir, $prefix): string -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - return $fileSystem->tempnam($dir, $prefix); -} - -/** - * Atomically dumps content into a file. - * - * @param string $filename The file to be written to - * @param null|string $content The data to write into the file - * - * @throws IOException if the file cannot be written to - * - * @private - */ -function dump_file(string $filename, ?string $content = null): void -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - $fileSystem->dumpFile($filename, $content); -} - -/** - * Appends content to an existing file. - * - * @param string $filename The file to which to append content - * @param string $content The content to append - * - * @throws IOException If the file is not writable - * - * @private - */ -function append_to_file(string $filename, string $content): void -{ - static $fileSystem; - - if (null === $fileSystem) { - $fileSystem = new FileSystem(); - } - - $fileSystem->appendToFile($filename, $content); -} diff --git a/src/Json/Json.php b/src/Json/Json.php index 1d8c3f463..a49b999fd 100644 --- a/src/Json/Json.php +++ b/src/Json/Json.php @@ -14,6 +14,7 @@ namespace KevinGH\Box\Json; +use Fidry\FileSystem\FS; use JsonSchema\Validator; use Seld\JsonLint\JsonParser; use Seld\JsonLint\ParsingException; @@ -21,7 +22,6 @@ use function implode; use function json_decode; use function json_last_error; -use function KevinGH\Box\FileSystem\file_contents; use const JSON_ERROR_NONE; use const JSON_ERROR_UTF8; @@ -74,7 +74,7 @@ public function decode(string $json, bool $assoc = false): array|stdClass */ public function decodeFile(string $file, bool $assoc = false): array|stdClass { - $json = file_contents($file); + $json = FS::getFileContents($file); return $this->decode($json, $assoc); } diff --git a/src/MapFile.php b/src/MapFile.php index 0ad3eeb11..2bedefd79 100644 --- a/src/MapFile.php +++ b/src/MapFile.php @@ -14,7 +14,7 @@ namespace KevinGH\Box; -use function KevinGH\Box\FileSystem\make_path_relative; +use Symfony\Component\Filesystem\Path; use function preg_quote; use function preg_replace; @@ -37,7 +37,7 @@ public function __construct( public function __invoke(string $path): ?string { - $relativePath = make_path_relative($path, $this->basePath); + $relativePath = Path::makeRelative($path, $this->basePath); foreach ($this->map as $item) { foreach ($item as $match => $replace) { diff --git a/src/Phar/PharMeta.php b/src/Phar/PharMeta.php index 613969ff2..1e4967fea 100644 --- a/src/Phar/PharMeta.php +++ b/src/Phar/PharMeta.php @@ -22,7 +22,6 @@ use SplFileInfo; use Symfony\Component\Filesystem\Path; use UnexpectedValueException; -use function KevinGH\Box\FileSystem\make_path_relative; use function ksort; use function Safe\json_decode; use function Safe\json_encode; @@ -157,7 +156,7 @@ private static function traverseSource( continue; } - $relativePath = make_path_relative($path, $root); + $relativePath = Path::makeRelative($path, $root); $filesMeta[$relativePath] = [ 'compression' => self::getCompressionAlgorithm($pharFileInfo), diff --git a/src/Pharaoh/Pharaoh.php b/src/Pharaoh/Pharaoh.php index ea6baba0c..8407f43a5 100644 --- a/src/Pharaoh/Pharaoh.php +++ b/src/Pharaoh/Pharaoh.php @@ -43,6 +43,7 @@ namespace KevinGH\Box\Pharaoh; +use Fidry\FileSystem\FS; use KevinGH\Box\Console\Command\Extract; use KevinGH\Box\Phar\CompressionAlgorithm; use KevinGH\Box\Phar\PharMeta; @@ -61,8 +62,6 @@ use function is_readable; use function iter\mapKeys; use function iter\toArrayWithKeys; -use function KevinGH\Box\FileSystem\make_tmp_dir; -use function KevinGH\Box\FileSystem\remove; use function random_bytes; use function sprintf; @@ -109,7 +108,7 @@ public function __construct(string $file) $this->file = $file; $this->fileName = basename($file); - $this->tmp = make_tmp_dir('HumbugBox', 'Pharaoh'); + $this->tmp = FS::makeTmpDir('HumbugBox', 'Pharaoh'); self::dumpPhar($file, $this->tmp); [ @@ -129,8 +128,8 @@ public function __destruct() Phar::unlinkArchive($path); } - if (null !== $this->tmp) { - remove($this->tmp); + if (isset($this->tmp)) { + FS::remove($this->tmp); } } diff --git a/src/RequirementChecker/RequirementsDumper.php b/src/RequirementChecker/RequirementsDumper.php index b3fcec4a6..8399d8070 100644 --- a/src/RequirementChecker/RequirementsDumper.php +++ b/src/RequirementChecker/RequirementsDumper.php @@ -14,12 +14,12 @@ namespace KevinGH\Box\RequirementChecker; +use Fidry\FileSystem\FS; use KevinGH\Box\Phar\CompressionAlgorithm; use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\SplFileInfo; use Webmozart\Assert\Assert; use function array_map; -use function KevinGH\Box\FileSystem\file_contents; use function str_replace; use function var_export; @@ -62,7 +62,7 @@ public static function dump( foreach ($requirementCheckerFiles as $file) { $filesWithContents[] = [ $file->getRelativePathname(), - file_contents($file->getPathname()), + FS::getFileContents($file->getPathname()), ]; } diff --git a/src/Test/FileSystemTestCase.php b/src/Test/FileSystemTestCase.php index 7b7386da6..17e5fa8d3 100644 --- a/src/Test/FileSystemTestCase.php +++ b/src/Test/FileSystemTestCase.php @@ -14,72 +14,13 @@ namespace KevinGH\Box\Test; -use PHPUnit\Framework\TestCase; -use function array_map; -use function array_values; -use function chdir; -use function getcwd; -use function KevinGH\Box\FileSystem\make_tmp_dir; -use function KevinGH\Box\FileSystem\remove; -use function natcasesort; -use function realpath; -use function str_replace; -use function sys_get_temp_dir; -use const DIRECTORY_SEPARATOR; - /** * @private */ -abstract class FileSystemTestCase extends TestCase +abstract class FileSystemTestCase extends \Fidry\FileSystem\Test\FileSystemTestCase { - /** @var string */ - protected $cwd; - - /** @var string */ - protected $tmp; - - protected function setUp(): void - { - parent::setUp(); - - // Cleans up whatever was there before. Indeed upon failure PHPUnit fails to trigger the `tearDown()` method - // and as a result some temporary files may still remain. - remove(str_replace('\\', '/', realpath(sys_get_temp_dir())).'/box'); - - $this->cwd = getcwd(); - $this->tmp = make_tmp_dir('box', self::class); - - chdir($this->tmp); - } - - protected function tearDown(): void + public static function getTmpDirNamespace(): string { - parent::tearDown(); - - chdir($this->cwd); - - remove($this->tmp); - } - - /** - * @param string[] $files - * - * @return string[] File real paths relative to the current temporary directory - */ - final protected function normalizePaths(array $files): array - { - $root = $this->tmp; - - $files = array_values( - array_map( - static fn (string $file): string => str_replace($root.DIRECTORY_SEPARATOR, '', $file), - $files, - ), - ); - - natsort($files); - natcasesort($files); - - return array_values($files); + return 'Box'; } } diff --git a/tests/AutoReview/DocumentationSchemaTest.php b/tests/AutoReview/DocumentationSchemaTest.php index 036aa9bfc..c121081f5 100644 --- a/tests/AutoReview/DocumentationSchemaTest.php +++ b/tests/AutoReview/DocumentationSchemaTest.php @@ -14,6 +14,7 @@ namespace KevinGH\Box\AutoReview; +use Fidry\FileSystem\FS; use PHPUnit\Framework\TestCase; use Webmozart\Assert\Assert; use function array_diff; @@ -23,7 +24,6 @@ use function array_unique; use function array_values; use function json_decode; -use function KevinGH\Box\FileSystem\file_contents; use function preg_match; use function preg_match_all; use function sort; @@ -107,7 +107,7 @@ private function retrieveDocSchemaKeys(): array 1, preg_match( '/```json(?.*?)```/s', - file_contents(self::CONFIGURATION_DOC_PATH), + FS::getFileContents(self::CONFIGURATION_DOC_PATH), $matches, ), ); @@ -121,7 +121,7 @@ private function retrieveDocSchemaKeys(): array private function retrieveSchemaKeys(): array { $schema = json_decode( - file_contents(self::SCHEMA_PATH), + FS::getFileContents(self::SCHEMA_PATH), true, 512, JSON_THROW_ON_ERROR, @@ -137,7 +137,7 @@ private function retrieveDocKeys(): array { preg_match_all( '/#+ [\p{L}\\-\s]+\(`(.*?)`(?:[\p{L}\\-\s]+`(.*?)`)?\)/u', - file_contents(self::CONFIGURATION_DOC_PATH), + FS::getFileContents(self::CONFIGURATION_DOC_PATH), $matches, ); diff --git a/tests/BoxTest.php b/tests/BoxTest.php index 1080780a8..1e1f65b94 100644 --- a/tests/BoxTest.php +++ b/tests/BoxTest.php @@ -17,6 +17,7 @@ use Error; use Exception; use Fidry\Console\DisplayNormalizer; +use Fidry\FileSystem\FS; use InvalidArgumentException; use KevinGH\Box\Compactor\Compactor; use KevinGH\Box\Compactor\Compactors; @@ -34,6 +35,7 @@ use RuntimeException; use SplFileInfo; use Stringable; +use Symfony\Component\Filesystem\Path; use Symfony\Component\Finder\Finder; use Throwable; use function array_filter; @@ -46,11 +48,6 @@ use function implode; use function in_array; use function iterator_to_array; -use function KevinGH\Box\FileSystem\canonicalize; -use function KevinGH\Box\FileSystem\chmod; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\make_tmp_dir; -use function KevinGH\Box\FileSystem\mkdir; use function realpath; use function sprintf; use function str_replace; @@ -143,7 +140,7 @@ public function test_it_can_add_a_file_to_the_phar(): void $file = 'foo'; $contents = 'test'; - dump_file($file, $contents); + FS::dumpFile($file, $contents); $this->box->startBuffering(); $this->box->addFile($file); @@ -209,7 +206,7 @@ public function test_it_cannot_add_a_file_to_the_phar_if_the_buffering_did_not_s $file = 'foo'; $contents = 'test'; - dump_file($file, $contents); + FS::dumpFile($file, $contents); try { $this->box->addFile($file); @@ -247,7 +244,7 @@ public function test_it_can_add_an_existent_file_with_contents_to_the_phar(): vo $file = 'foo'; $contents = 'test'; - dump_file($file, 'tset'); + FS::dumpFile($file, 'tset'); $this->box->startBuffering(); $this->box->addFile($file, $contents); @@ -287,7 +284,7 @@ public function test_it_can_add_an_existent_bin_file_with_contents_to_the_phar() $file = 'foo'; $contents = 'test'; - dump_file($file, 'tset'); + FS::dumpFile($file, 'tset'); $this->box->startBuffering(); $this->box->addFile($file, $contents, true); @@ -306,10 +303,10 @@ public function test_it_can_add_an_existent_bin_file_with_contents_to_the_phar() public function test_it_can_add_a_file_with_absolute_path_to_the_phar(): void { $relativePath = 'path-to/foo'; - $file = canonicalize($this->tmp.DIRECTORY_SEPARATOR.$relativePath); + $file = Path::canonicalize($this->tmp.DIRECTORY_SEPARATOR.$relativePath); $contents = 'test'; - dump_file($file, $contents); + FS::dumpFile($file, $contents); $this->box->startBuffering(); $this->box->addFile($file); @@ -331,7 +328,7 @@ public function test_it_can_add_a_file_with_a_local_path_to_the_phar(): void $contents = 'test'; $localPath = 'local/path/foo'; - dump_file($file, $contents); + FS::dumpFile($file, $contents); $fileMapper = new MapFile( $this->tmp, @@ -361,7 +358,7 @@ public function test_it_can_add_a_binary_file_to_the_phar(): void $file = 'foo'; $contents = 'test'; - dump_file($file, $contents); + FS::dumpFile($file, $contents); $this->box->registerCompactors(new Compactors(new FakeCompactor())); @@ -385,7 +382,7 @@ public function test_it_can_add_a_binary_file_with_a_local_path_to_the_phar(): v $contents = 'test'; $localPath = 'local/path/foo'; - dump_file($file, $contents); + FS::dumpFile($file, $contents); $fileMapper = new MapFile( $this->tmp, @@ -418,7 +415,7 @@ public function test_it_compacts_the_file_content_and_replace_placeholders_befor '@foo_placeholder@' => 'foo_value', ]; - dump_file($file, $contents); + FS::dumpFile($file, $contents); /** @var Compactor|ObjectProphecy $firstCompactorProphecy */ $firstCompactorProphecy = $this->prophesize(Compactor::class); @@ -478,7 +475,7 @@ public function test_it_maps_the_file_before_adding_it_to_the_phar(): void $this->box->registerFileMapping($map); foreach ($files as $file => $expectedLocal) { - dump_file($file); + FS::dumpFile($file); $this->box->startBuffering(); $local = $this->box->addFile($file); @@ -522,8 +519,8 @@ public function test_it_cannot_add_an_unreadable_file(): void $file = 'foo'; $contents = 'test'; - dump_file($file, $contents); - chmod($file, 0o355); + FS::dumpFile($file, $contents); + FS::chmod($file, 0o355); try { $this->box->startBuffering(); @@ -548,7 +545,7 @@ public function test_it_compacts_the_contents_before_adding_it_to_the_phar(): vo '@foo_placeholder@' => 'foo_value', ]; - dump_file($file, $contents); + FS::dumpFile($file, $contents); $firstCompactorProphecy = $this->prophesize(Compactor::class); $firstCompactorProphecy @@ -594,7 +591,7 @@ public function test_it_can_add_files_to_the_phar(): void ]; foreach ($files as $file => $contents) { - dump_file($file, $contents); + FS::dumpFile($file, $contents); } $this->box->startBuffering(); @@ -621,7 +618,7 @@ public function test_it_cannot_add_files_to_the_phar_if_the_buffering_did_not_st ]; foreach ($files as $file => $contents) { - dump_file($file, $contents); + FS::dumpFile($file, $contents); } try { @@ -641,7 +638,7 @@ public function test_it_can_add_files_with_absolute_path_to_the_phar(): void ]; foreach ($files as $file => $contents) { - dump_file($file, $contents); + FS::dumpFile($file, $contents); } $this->box->startBuffering(); @@ -683,7 +680,7 @@ public function test_it_can_add_files_with_a_local_path_to_the_phar(): void ]; foreach ($files as $file => $item) { - dump_file($file, $item['contents']); + FS::dumpFile($file, $item['contents']); } $this->box->startBuffering(); @@ -711,7 +708,7 @@ public function test_it_can_dump_the_autoloader_when_adding_files_to_the_phar(): ]; foreach ($files as $file => $contents) { - dump_file($file, $contents); + FS::dumpFile($file, $contents); } $autoloadDumped = false; @@ -745,16 +742,16 @@ public function test_it_artefacts_created_when_dumping_the_autoloader_are_added_ ]; foreach ($files as $file => $contents) { - dump_file($file, $contents); + FS::dumpFile($file, $contents); } $this->box->startBuffering(); $this->box->addFiles(array_keys($files), false); $this->box->endBuffering(static function () use (&$files): void { - dump_file('zip'); + FS::dumpFile('zip', ''); $files['zip'] = ''; - dump_file('zap'); + FS::dumpFile('zap', ''); $files['zap'] = ''; }); @@ -779,7 +776,7 @@ public function test_it_can_remove_the_composer_files(): void ]; foreach ($files as $file => $contents) { - dump_file($file, $contents); + FS::dumpFile($file, $contents); } $this->box->startBuffering(); @@ -812,7 +809,7 @@ public function test_it_can_remove_the_composer_files_with_a_custom_vendor_direc ]; foreach ($files as $file => $contents) { - dump_file($file, $contents); + FS::dumpFile($file, $contents); } $this->box->startBuffering(); @@ -839,7 +836,7 @@ public function test_it_can_remove_the_composer_files_mapped_with_a_different_pa ]; foreach ($files as $file => $contents) { - dump_file($file, $contents); + FS::dumpFile($file, $contents); } $map = new MapFile( @@ -917,7 +914,7 @@ public function test_it_can_add_binary_files_to_the_phar(): void ]; foreach ($files as $file => $contents) { - dump_file($file, $contents); + FS::dumpFile($file, $contents); } $this->box->startBuffering(); @@ -959,7 +956,7 @@ public function test_it_can_add_binary_files_with_a_local_path_to_the_phar(): vo ]; foreach ($files as $file => $item) { - dump_file($file, $item['contents']); + FS::dumpFile($file, $item['contents']); } $this->box->startBuffering(); @@ -993,7 +990,7 @@ public function test_it_compacts_the_files_contents_and_replace_placeholders_bef $this->box->registerPlaceholders($placeholderMapping); foreach ($files as $file => $contents) { - dump_file($file, $contents); + FS::dumpFile($file, $contents); } // Cannot test the compactors: there is a bug with the serialization of the Prophecy objects which prevents @@ -1039,7 +1036,7 @@ public function test_it_maps_the_files_before_adding_it_to_the_phar(): void $this->box->registerFileMapping($map); foreach ($files as $file => $expectedLocal) { - dump_file($file); + FS::dumpFile($file); } $this->box->startBuffering(); @@ -1083,8 +1080,8 @@ public function test_it_cannot_add_unreadable_files(): void $file = 'foo'; $contents = 'test'; - dump_file($file, $contents); - chmod($file, 0o355); + FS::dumpFile($file, $contents); + FS::chmod($file, 0o355); try { $this->box->startBuffering(); @@ -1102,7 +1099,7 @@ public function test_it_cannot_add_unreadable_files(): void public function test_the_temporary_directory_created_for_box_is_removed_upon_failure(): void { - $boxTmp = make_tmp_dir('box', Box::class); + $boxTmp = $this->tmp.DIRECTORY_SEPARATOR.'test-tmp-dir'; try { $this->box->startBuffering(); @@ -1115,7 +1112,6 @@ public function test_the_temporary_directory_created_for_box_is_removed_upon_fai ->directories() ->depth(0) ->in(dirname($boxTmp)), - true, ); $boxDir = current( @@ -1149,7 +1145,7 @@ public function test_it_exposes_the_underlying_phar(): void public function test_register_placeholders(): void { - dump_file( + FS::dumpFile( $file = 'foo', <<<'PHP' #!/usr/bin/env php @@ -1200,7 +1196,7 @@ public function __toString(): string public function test_register_stub_file(): void { - dump_file( + FS::dumpFile( $file = 'foo', <<<'STUB' #!/usr/bin/env php @@ -1235,7 +1231,7 @@ public function test_register_stub_file(): void public function test_placeholders_are_also_replaced_in_stub_file(): void { - dump_file( + FS::dumpFile( $file = 'foo', <<<'STUB' #!/usr/bin/env php @@ -1461,7 +1457,7 @@ public function test_it_cannot_sign_if_cannot_get_the_private_key(): void $key = 'Invalid key'; $password = 'test'; - mkdir('test.phar.pubkey'); + FS::mkdir('test.phar.pubkey'); $this->configureHelloWorldPhar(); @@ -1481,7 +1477,7 @@ public function test_it_cannot_sign_if_cannot_create_the_public_key(): void { [$key, $password] = $this->getPrivateKey(); - mkdir('test.phar.pubkey'); + FS::mkdir('test.phar.pubkey'); $this->configureHelloWorldPhar(); @@ -1506,7 +1502,7 @@ public function test_it_can_sign_the_phar_using_a_private_key_with_password(): v [$key, $password] = $this->getPrivateKey(); - dump_file($file = 'foo', $key); + FS::dumpFile($file = 'foo', $key); $this->configureHelloWorldPhar(); @@ -1533,7 +1529,7 @@ public function test_it_cannot_sign_the_phar_using_a_private_key_with_the_wrong_ $key = $this->getPrivateKey()[0]; $password = 'wrong password'; - dump_file($file = 'foo', $key); + FS::dumpFile($file = 'foo', $key); $this->configureHelloWorldPhar(); diff --git a/tests/Composer/ComposerConfigurationTest.php b/tests/Composer/ComposerConfigurationTest.php index ff5e8ab6c..b66843839 100644 --- a/tests/Composer/ComposerConfigurationTest.php +++ b/tests/Composer/ComposerConfigurationTest.php @@ -14,9 +14,9 @@ namespace KevinGH\Box\Composer; +use Fidry\FileSystem\FS; use KevinGH\Box\Test\FileSystemTestCase; use function json_decode; -use function KevinGH\Box\FileSystem\mkdir; /** * @covers \KevinGH\Box\Composer\ComposerConfiguration @@ -253,8 +253,8 @@ public function test_it_can_retrieve_the_dev_packages_found_in_the_lock_file(): $decodedComposerJson = []; $decodedComposerLock = json_decode(self::COMPOSER_LOCK_SAMPLE, true); - mkdir('vendor/bamarni/composer-bin-plugin'); - mkdir('vendor/doctrine/instantiator'); + FS::mkdir('vendor/bamarni/composer-bin-plugin'); + FS::mkdir('vendor/doctrine/instantiator'); $expected = [ $this->tmp.'/vendor/bamarni/composer-bin-plugin', @@ -281,8 +281,8 @@ public function test_it_can_retrieve_the_dev_packages_found_in_the_lock_file_2() $decodedComposerJson = ['config' => []]; $decodedComposerLock = json_decode(self::COMPOSER_LOCK_SAMPLE, true); - mkdir('vendor/bamarni/composer-bin-plugin'); - mkdir('vendor/doctrine/instantiator'); + FS::mkdir('vendor/bamarni/composer-bin-plugin'); + FS::mkdir('vendor/doctrine/instantiator'); $expected = [ $this->tmp.'/vendor/bamarni/composer-bin-plugin', @@ -309,7 +309,7 @@ public function test_it_ignores_non_existent_dev_packages_found_in_the_lock_file $decodedComposerJson = []; $decodedComposerLock = json_decode(self::COMPOSER_LOCK_SAMPLE, true); - mkdir('vendor/bamarni/composer-bin-plugin'); + FS::mkdir('vendor/bamarni/composer-bin-plugin'); // Doctrine Instantiator vendor does not exists $expected = [ @@ -340,8 +340,8 @@ public function test_it_can_retrieve_the_dev_packages_found_in_the_lock_file_in_ ]; $decodedComposerLock = json_decode(self::COMPOSER_LOCK_SAMPLE, true); - mkdir('custom-vendor/bamarni/composer-bin-plugin'); - mkdir('vendor/doctrine/instantiator'); // Wrong directory + FS::mkdir('custom-vendor/bamarni/composer-bin-plugin'); + FS::mkdir('vendor/doctrine/instantiator'); // Wrong directory $expected = [ $this->tmp.'/custom-vendor/bamarni/composer-bin-plugin', @@ -468,8 +468,8 @@ public function test_it_can_retrieve_the_dev_packages_found_in_the_lock_file_eve true, ); - mkdir('custom-vendor/bamarni/composer-bin-plugin'); - mkdir('vendor/doctrine/instantiator'); // Wrong directory + FS::mkdir('custom-vendor/bamarni/composer-bin-plugin'); + FS::mkdir('vendor/doctrine/instantiator'); // Wrong directory $expected = []; diff --git a/tests/Composer/ComposerOrchestratorComposer22Test.php b/tests/Composer/ComposerOrchestratorComposer22Test.php index 8f3e7dab9..98d197c50 100644 --- a/tests/Composer/ComposerOrchestratorComposer22Test.php +++ b/tests/Composer/ComposerOrchestratorComposer22Test.php @@ -15,6 +15,7 @@ namespace KevinGH\Box\Composer; use Fidry\Console\DisplayNormalizer; +use Fidry\FileSystem\FS; use Humbug\PhpScoper\Symbol\SymbolsRegistry; use KevinGH\Box\Test\FileSystemTestCase; use PhpParser\Node\Name\FullyQualified; @@ -23,8 +24,6 @@ use function file_exists; use function file_get_contents; use function iterator_to_array; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\mirror; use function preg_replace; use function sprintf; use function version_compare; @@ -70,7 +69,7 @@ public function test_it_can_dump_the_autoloader_with_an_empty_composer_json( string $prefix, string $expectedAutoloadContents, ): void { - dump_file('composer.json', '{}'); + FS::dumpFile('composer.json', '{}'); ComposerOrchestrator::dumpAutoload($symbolsRegistry, $prefix, false); @@ -127,9 +126,9 @@ public function test_it_cannot_dump_the_autoloader_with_an_invalid_composer_json SymbolsRegistry $symbolsRegistry, string $prefix, ): void { - mirror(self::FIXTURES.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES.'/dir000', $this->tmp); - dump_file('composer.json', ''); + FS::dumpFile('composer.json', ''); try { ComposerOrchestrator::dumpAutoload($symbolsRegistry, $prefix, false); @@ -152,7 +151,7 @@ public function test_it_cannot_dump_the_autoloader_with_an_invalid_composer_json public function test_it_can_dump_the_autoloader_with_a_composer_json_with_a_dependency(): void { - mirror(self::FIXTURES.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES.'/dir000', $this->tmp); ComposerOrchestrator::dumpAutoload(new SymbolsRegistry(), '', false); @@ -246,7 +245,7 @@ public function test_it_can_dump_the_autoloader_with_a_composer_json_lock_and_in string $expectedAutoloadContents, ): void { $this->skipIfFixturesNotInstalled(self::FIXTURES.'/dir001/vendor'); - mirror(self::FIXTURES.'/dir001', $this->tmp); + FS::mirror(self::FIXTURES.'/dir001', $this->tmp); ComposerOrchestrator::dumpAutoload($SymbolsRegistry, $prefix, false); @@ -317,7 +316,7 @@ public function test_it_can_dump_the_autoloader_with_a_composer_json_lock_and_in public function test_it_can_dump_the_autoloader_with_a_composer_json_lock_and_installed_with_a_dev_dependency(): void { $this->skipIfFixturesNotInstalled(self::FIXTURES.'/dir003/vendor'); - mirror(self::FIXTURES.'/dir003', $this->tmp); + FS::mirror(self::FIXTURES.'/dir003', $this->tmp); $composerAutoloaderName = self::COMPOSER_AUTOLOADER_NAME; @@ -408,7 +407,7 @@ public function test_it_can_dump_the_autoloader_with_a_composer_json_and_lock_wi string $expectedAutoloadContents, ): void { $this->skipIfFixturesNotInstalled(self::FIXTURES.'/dir002/vendor'); - mirror(self::FIXTURES.'/dir002', $this->tmp); + FS::mirror(self::FIXTURES.'/dir002', $this->tmp); ComposerOrchestrator::dumpAutoload($symbolsRegistry, $prefix, false); diff --git a/tests/Composer/ComposerOrchestratorComposer23Test.php b/tests/Composer/ComposerOrchestratorComposer23Test.php index 65cc51304..68d7b00e2 100644 --- a/tests/Composer/ComposerOrchestratorComposer23Test.php +++ b/tests/Composer/ComposerOrchestratorComposer23Test.php @@ -15,6 +15,7 @@ namespace KevinGH\Box\Composer; use Fidry\Console\DisplayNormalizer; +use Fidry\FileSystem\FS; use Humbug\PhpScoper\Symbol\SymbolsRegistry; use KevinGH\Box\Test\FileSystemTestCase; use PhpParser\Node\Name\FullyQualified; @@ -23,8 +24,6 @@ use function file_exists; use function file_get_contents; use function iterator_to_array; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\mirror; use function preg_replace; use function sprintf; use function version_compare; @@ -70,7 +69,7 @@ public function test_it_can_dump_the_autoloader_with_an_empty_composer_json( string $prefix, string $expectedAutoloadContents, ): void { - dump_file('composer.json', '{}'); + FS::dumpFile('composer.json', '{}'); ComposerOrchestrator::dumpAutoload($symbolsRegistry, $prefix, false); @@ -127,9 +126,9 @@ public function test_it_cannot_dump_the_autoloader_with_an_invalid_composer_json SymbolsRegistry $symbolsRegistry, string $prefix, ): void { - mirror(self::FIXTURES.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES.'/dir000', $this->tmp); - dump_file('composer.json', ''); + FS::dumpFile('composer.json', ''); try { ComposerOrchestrator::dumpAutoload($symbolsRegistry, $prefix, false); @@ -152,7 +151,7 @@ public function test_it_cannot_dump_the_autoloader_with_an_invalid_composer_json public function test_it_can_dump_the_autoloader_with_a_composer_json_with_a_dependency(): void { - mirror(self::FIXTURES.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES.'/dir000', $this->tmp); ComposerOrchestrator::dumpAutoload(new SymbolsRegistry(), '', false); @@ -251,7 +250,7 @@ public function test_it_can_dump_the_autoloader_with_a_composer_json_lock_and_in string $expectedAutoloadContents, ): void { $this->skipIfFixturesNotInstalled(self::FIXTURES.'/dir001/vendor'); - mirror(self::FIXTURES.'/dir001', $this->tmp); + FS::mirror(self::FIXTURES.'/dir001', $this->tmp); ComposerOrchestrator::dumpAutoload($SymbolsRegistry, $prefix, false); @@ -322,7 +321,7 @@ public function test_it_can_dump_the_autoloader_with_a_composer_json_lock_and_in public function test_it_can_dump_the_autoloader_with_a_composer_json_lock_and_installed_with_a_dev_dependency(): void { $this->skipIfFixturesNotInstalled(self::FIXTURES.'/dir003/vendor'); - mirror(self::FIXTURES.'/dir003', $this->tmp); + FS::mirror(self::FIXTURES.'/dir003', $this->tmp); $composerAutoloaderName = self::COMPOSER_AUTOLOADER_NAME; @@ -418,7 +417,7 @@ public function test_it_can_dump_the_autoloader_with_a_composer_json_and_lock_wi string $expectedAutoloadContents, ): void { $this->skipIfFixturesNotInstalled(self::FIXTURES.'/dir002/vendor'); - mirror(self::FIXTURES.'/dir002', $this->tmp); + FS::mirror(self::FIXTURES.'/dir002', $this->tmp); ComposerOrchestrator::dumpAutoload($symbolsRegistry, $prefix, false); diff --git a/tests/Composer/ComposerOrchestratorComposer24Test.php b/tests/Composer/ComposerOrchestratorComposer24Test.php index 036163ee8..d067bcf39 100644 --- a/tests/Composer/ComposerOrchestratorComposer24Test.php +++ b/tests/Composer/ComposerOrchestratorComposer24Test.php @@ -15,6 +15,7 @@ namespace KevinGH\Box\Composer; use Fidry\Console\DisplayNormalizer; +use Fidry\FileSystem\FS; use Humbug\PhpScoper\Symbol\SymbolsRegistry; use KevinGH\Box\Test\FileSystemTestCase; use PhpParser\Node\Name\FullyQualified; @@ -23,8 +24,6 @@ use function file_exists; use function file_get_contents; use function iterator_to_array; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\mirror; use function preg_replace; /** @@ -68,7 +67,7 @@ public function test_it_can_dump_the_autoloader_with_an_empty_composer_json( string $prefix, string $expectedAutoloadContents, ): void { - dump_file('composer.json', '{}'); + FS::dumpFile('composer.json', '{}'); ComposerOrchestrator::dumpAutoload($symbolsRegistry, $prefix, false); @@ -125,9 +124,9 @@ public function test_it_cannot_dump_the_autoloader_with_an_invalid_composer_json SymbolsRegistry $symbolsRegistry, string $prefix, ): void { - mirror(self::FIXTURES.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES.'/dir000', $this->tmp); - dump_file('composer.json', ''); + FS::dumpFile('composer.json', ''); try { ComposerOrchestrator::dumpAutoload($symbolsRegistry, $prefix, false); @@ -150,7 +149,7 @@ public function test_it_cannot_dump_the_autoloader_with_an_invalid_composer_json public function test_it_can_dump_the_autoloader_with_a_composer_json_with_a_dependency(): void { - mirror(self::FIXTURES.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES.'/dir000', $this->tmp); ComposerOrchestrator::dumpAutoload(new SymbolsRegistry(), '', false); @@ -262,7 +261,7 @@ public function test_it_can_dump_the_autoloader_with_a_composer_json_lock_and_in string $expectedAutoloadContents, ): void { $this->skipIfFixturesNotInstalled(self::FIXTURES.'/dir001/vendor'); - mirror(self::FIXTURES.'/dir001', $this->tmp); + FS::mirror(self::FIXTURES.'/dir001', $this->tmp); ComposerOrchestrator::dumpAutoload($SymbolsRegistry, $prefix, false); @@ -333,7 +332,7 @@ public function test_it_can_dump_the_autoloader_with_a_composer_json_lock_and_in public function test_it_can_dump_the_autoloader_with_a_composer_json_lock_and_installed_with_a_dev_dependency(): void { $this->skipIfFixturesNotInstalled(self::FIXTURES.'/dir003/vendor'); - mirror(self::FIXTURES.'/dir003', $this->tmp); + FS::mirror(self::FIXTURES.'/dir003', $this->tmp); $composerAutoloaderName = self::COMPOSER_AUTOLOADER_NAME; @@ -442,7 +441,7 @@ public function test_it_can_dump_the_autoloader_with_a_composer_json_and_lock_wi string $expectedAutoloadContents, ): void { $this->skipIfFixturesNotInstalled(self::FIXTURES.'/dir002/vendor'); - mirror(self::FIXTURES.'/dir002', $this->tmp); + FS::mirror(self::FIXTURES.'/dir002', $this->tmp); ComposerOrchestrator::dumpAutoload($symbolsRegistry, $prefix, false); diff --git a/tests/Configuration/ConfigurationFileNoConfigTest.php b/tests/Configuration/ConfigurationFileNoConfigTest.php index 2df9fa3b4..5979e7f00 100644 --- a/tests/Configuration/ConfigurationFileNoConfigTest.php +++ b/tests/Configuration/ConfigurationFileNoConfigTest.php @@ -14,12 +14,9 @@ namespace KevinGH\Box\Configuration; +use Fidry\FileSystem\FS; use InvalidArgumentException; use KevinGH\Box\Platform; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\mkdir; -use function KevinGH\Box\FileSystem\remove; -use function KevinGH\Box\FileSystem\touch; use function natcasesort; use function symlink; @@ -34,58 +31,58 @@ class ConfigurationFileNoConfigTest extends ConfigurationTestCase { public function test_all_the_files_found_in_the_composer_json_are_taken_by_default_with_no_config_file_is_used(): void { - touch('index.php'); - touch('index.phar'); + FS::touch('index.php'); + FS::touch('index.phar'); - touch('file0'); - touch('file1'); - touch('file2'); + FS::touch('file0'); + FS::touch('file1'); + FS::touch('file2'); - mkdir('B'); - touch('B/fileB0'); - touch('B/fileB1'); + FS::mkdir('B'); + FS::touch('B/fileB0'); + FS::touch('B/fileB1'); - mkdir('PSR4_0'); - touch('PSR4_0/file0'); - touch('PSR4_0/file1'); + FS::mkdir('PSR4_0'); + FS::touch('PSR4_0/file0'); + FS::touch('PSR4_0/file1'); - mkdir('PSR4_1'); - touch('PSR4_1/file0'); - touch('PSR4_1/file1'); + FS::mkdir('PSR4_1'); + FS::touch('PSR4_1/file0'); + FS::touch('PSR4_1/file1'); - mkdir('PSR4_2'); - touch('PSR4_2/file0'); - touch('PSR4_2/file1'); + FS::mkdir('PSR4_2'); + FS::touch('PSR4_2/file0'); + FS::touch('PSR4_2/file1'); - mkdir('DEV_PSR4_0'); - touch('DEV_PSR4_0/file0'); - touch('DEV_PSR4_0/file1'); + FS::mkdir('DEV_PSR4_0'); + FS::touch('DEV_PSR4_0/file0'); + FS::touch('DEV_PSR4_0/file1'); - mkdir('PSR0_0'); - touch('PSR0_0/file0'); - touch('PSR0_0/file1'); + FS::mkdir('PSR0_0'); + FS::touch('PSR0_0/file0'); + FS::touch('PSR0_0/file1'); - mkdir('PSR0_1'); - touch('PSR0_1/file0'); - touch('PSR0_1/file1'); + FS::mkdir('PSR0_1'); + FS::touch('PSR0_1/file0'); + FS::touch('PSR0_1/file1'); - mkdir('PSR0_2'); - touch('PSR0_2/file0'); - touch('PSR0_2/file1'); + FS::mkdir('PSR0_2'); + FS::touch('PSR0_2/file0'); + FS::touch('PSR0_2/file1'); - mkdir('DEV_PSR0_0'); - touch('DEV_PSR0_0/file0'); - touch('DEV_PSR0_0/file1'); + FS::mkdir('DEV_PSR0_0'); + FS::touch('DEV_PSR0_0/file0'); + FS::touch('DEV_PSR0_0/file1'); - mkdir('CLASSMAP_DIR'); - touch('CLASSMAP_DIR/file0'); - touch('CLASSMAP_DIR/file1'); + FS::mkdir('CLASSMAP_DIR'); + FS::touch('CLASSMAP_DIR/file0'); + FS::touch('CLASSMAP_DIR/file1'); - mkdir('CLASSMAP_DEV_DIR'); - touch('CLASSMAP_DEV_DIR/file0'); - touch('CLASSMAP_DEV_DIR/file1'); + FS::mkdir('CLASSMAP_DEV_DIR'); + FS::touch('CLASSMAP_DEV_DIR/file0'); + FS::touch('CLASSMAP_DEV_DIR/file1'); - dump_file( + FS::dumpFile( 'composer.json', <<<'JSON' { @@ -158,11 +155,11 @@ public function test_all_the_files_found_in_the_composer_json_are_taken_by_defau public function test_find_psr0_files(): void { - mkdir('PSR0_0'); - touch('PSR0_0/file0'); - touch('PSR0_0/file1'); + FS::mkdir('PSR0_0'); + FS::touch('PSR0_0/file0'); + FS::touch('PSR0_0/file1'); - dump_file( + FS::dumpFile( 'composer.json', <<<'JSON' { @@ -199,15 +196,15 @@ public function test_find_psr0_files(): void public function test_psr0_with_empty_directory_in_composer_json(): void { - touch('root_file0'); - touch('root_file1'); + FS::touch('root_file0'); + FS::touch('root_file1'); - mkdir('Acme'); - touch('Acme/file0'); - touch('Acme/file1'); - touch('Acme/file2'); + FS::mkdir('Acme'); + FS::touch('Acme/file0'); + FS::touch('Acme/file1'); + FS::touch('Acme/file2'); - dump_file( + FS::dumpFile( 'composer.json', <<<'JSON' { @@ -246,9 +243,9 @@ public function test_psr0_with_empty_directory_in_composer_json(): void public function test_throws_an_error_if_a_non_existent_file_is_found_via_the_composer_json(): void { - touch('file0'); + FS::touch('file0'); - dump_file( + FS::dumpFile( 'composer.json', <<<'JSON' { @@ -270,7 +267,7 @@ public function test_throws_an_error_if_a_non_existent_file_is_found_via_the_com ); } - dump_file( + FS::dumpFile( 'composer.json', <<<'JSON' { @@ -295,10 +292,10 @@ public function test_throws_an_error_if_a_non_existent_file_is_found_via_the_com public function test_throws_an_error_if_a_symlink_is_used(): void { - touch('file0'); + FS::touch('file0'); symlink('file0', 'file1'); - dump_file( + FS::dumpFile( 'composer.json', <<<'JSON' { @@ -320,7 +317,7 @@ public function test_throws_an_error_if_a_symlink_is_used(): void ); } - dump_file( + FS::dumpFile( 'composer.json', <<<'JSON' { @@ -330,7 +327,7 @@ public function test_throws_an_error_if_a_symlink_is_used(): void } JSON, ); - mkdir('original_dir'); + FS::mkdir('original_dir'); symlink('original_dir', 'CLASSMAP_DIR'); try { @@ -347,59 +344,59 @@ public function test_throws_an_error_if_a_symlink_is_used(): void public function test_the_blacklist_setting_is_applied_to_all_the_files_found_in_the_current_directory_are_taken_by_default_if_no_file_setting_is_used(): void { - touch('file0'); - touch('file1'); - touch('file2'); + FS::touch('file0'); + FS::touch('file1'); + FS::touch('file2'); - mkdir('B'); - touch('B/fileB0'); - touch('B/fileB1'); + FS::mkdir('B'); + FS::touch('B/fileB0'); + FS::touch('B/fileB1'); - mkdir('PSR4_0'); - touch('PSR4_0/file0'); - touch('PSR4_0/file1'); + FS::mkdir('PSR4_0'); + FS::touch('PSR4_0/file0'); + FS::touch('PSR4_0/file1'); - mkdir('PSR4_1'); - touch('PSR4_1/file0'); - touch('PSR4_1/file1'); + FS::mkdir('PSR4_1'); + FS::touch('PSR4_1/file0'); + FS::touch('PSR4_1/file1'); - mkdir('PSR4_2'); - touch('PSR4_2/file0'); - touch('PSR4_2/file1'); + FS::mkdir('PSR4_2'); + FS::touch('PSR4_2/file0'); + FS::touch('PSR4_2/file1'); - mkdir('DEV_PSR4_0'); - touch('DEV_PSR4_0/file0'); - touch('DEV_PSR4_0/file1'); + FS::mkdir('DEV_PSR4_0'); + FS::touch('DEV_PSR4_0/file0'); + FS::touch('DEV_PSR4_0/file1'); - mkdir('PSR0_0'); - touch('PSR0_0/file0'); - touch('PSR0_0/file1'); + FS::mkdir('PSR0_0'); + FS::touch('PSR0_0/file0'); + FS::touch('PSR0_0/file1'); - mkdir('PSR0_1'); - touch('PSR0_1/file0'); - touch('PSR0_1/file1'); + FS::mkdir('PSR0_1'); + FS::touch('PSR0_1/file0'); + FS::touch('PSR0_1/file1'); - mkdir('PSR0_2'); - touch('PSR0_2/file0'); - touch('PSR0_2/file1'); + FS::mkdir('PSR0_2'); + FS::touch('PSR0_2/file0'); + FS::touch('PSR0_2/file1'); - mkdir('DEV_PSR0_0'); - touch('DEV_PSR0_0/file0'); - touch('DEV_PSR0_0/file1'); + FS::mkdir('DEV_PSR0_0'); + FS::touch('DEV_PSR0_0/file0'); + FS::touch('DEV_PSR0_0/file1'); - mkdir('BLACKLISTED_CLASSMAP_DIR'); - touch('BLACKLISTED_CLASSMAP_DIR/file0'); - touch('BLACKLISTED_CLASSMAP_DIR/file1'); + FS::mkdir('BLACKLISTED_CLASSMAP_DIR'); + FS::touch('BLACKLISTED_CLASSMAP_DIR/file0'); + FS::touch('BLACKLISTED_CLASSMAP_DIR/file1'); - mkdir('CLASSMAP_DIR'); - touch('CLASSMAP_DIR/file0'); - touch('CLASSMAP_DIR/file1'); + FS::mkdir('CLASSMAP_DIR'); + FS::touch('CLASSMAP_DIR/file0'); + FS::touch('CLASSMAP_DIR/file1'); - mkdir('CLASSMAP_DEV_DIR'); - touch('CLASSMAP_DEV_DIR/file0'); - touch('CLASSMAP_DEV_DIR/file1'); + FS::mkdir('CLASSMAP_DEV_DIR'); + FS::touch('CLASSMAP_DEV_DIR/file0'); + FS::touch('CLASSMAP_DEV_DIR/file1'); - dump_file( + FS::dumpFile( 'composer.json', <<<'JSON' { @@ -472,211 +469,211 @@ public function test_it_ignores_the_most_common_non_needed_files_when_guess_the_ self::markTestSkipped('Cannot run this test on OSX since it is case insensitive.'); } - touch('main.php~'); - touch('main.php.back'); - touch('main.php.swp'); + FS::touch('main.php~'); + FS::touch('main.php.back'); + FS::touch('main.php.swp'); - touch('phpunit.xml.dist'); - touch('phpunit.xml'); - touch('phpunit_infection.xml.dist'); + FS::touch('phpunit.xml.dist'); + FS::touch('phpunit.xml'); + FS::touch('phpunit_infection.xml.dist'); - touch('LICENSE'); - touch('LICENSE.md'); - touch('license'); - touch('LICENSE_GECKO'); + FS::touch('LICENSE'); + FS::touch('LICENSE.md'); + FS::touch('license'); + FS::touch('LICENSE_GECKO'); - touch('License.php'); - touch('LicenseCommand.php'); + FS::touch('License.php'); + FS::touch('LicenseCommand.php'); - touch('README'); - touch('README.md'); - touch('README_ru.md'); - touch('README.rst'); - touch('readme'); + FS::touch('README'); + FS::touch('README.md'); + FS::touch('README_ru.md'); + FS::touch('README.rst'); + FS::touch('readme'); - touch('Readme.php'); - touch('ReadmeCommand.php'); + FS::touch('Readme.php'); + FS::touch('ReadmeCommand.php'); - touch('UPGRADE'); - touch('UPGRADE.md'); - touch('upgrade'); + FS::touch('UPGRADE'); + FS::touch('UPGRADE.md'); + FS::touch('upgrade'); - touch('Upgrade.php'); - touch('UpgradeCommand.php'); + FS::touch('Upgrade.php'); + FS::touch('UpgradeCommand.php'); - touch('CHANGELOG'); - touch('ChangeLog-7.1.md'); - touch('CHANGELOG.md'); - touch('changelog'); + FS::touch('CHANGELOG'); + FS::touch('ChangeLog-7.1.md'); + FS::touch('CHANGELOG.md'); + FS::touch('changelog'); - touch('Changelog.php'); - touch('ChangelogCommand.php'); + FS::touch('Changelog.php'); + FS::touch('ChangelogCommand.php'); - touch('CONTRIBUTING'); - touch('CONTRIBUTING.md'); - touch('contributing'); + FS::touch('CONTRIBUTING'); + FS::touch('CONTRIBUTING.md'); + FS::touch('contributing'); - touch('Contributing.php'); - touch('ContributingCommand.php'); + FS::touch('Contributing.php'); + FS::touch('ContributingCommand.php'); - touch('TODO'); - touch('TODO.md'); - touch('todo'); + FS::touch('TODO'); + FS::touch('TODO.md'); + FS::touch('todo'); - touch('Todo.php'); - touch('TodoCommand.php'); + FS::touch('Todo.php'); + FS::touch('TodoCommand.php'); - touch('CONDUCT'); - touch('CONDUCT.md'); - touch('conduct'); - touch('CODE_OF_CONDUCT.md'); + FS::touch('CONDUCT'); + FS::touch('CONDUCT.md'); + FS::touch('conduct'); + FS::touch('CODE_OF_CONDUCT.md'); - touch('Conduct.php'); - touch('ConductCommand.php'); + FS::touch('Conduct.php'); + FS::touch('ConductCommand.php'); - touch('AUTHORS'); - touch('AUTHORS.md'); - touch('authors'); + FS::touch('AUTHORS'); + FS::touch('AUTHORS.md'); + FS::touch('authors'); - touch('Author.php'); - touch('AuthorCommand.php'); + FS::touch('Author.php'); + FS::touch('AuthorCommand.php'); - touch('Test.php'); - touch('MainTest.php'); - touch('SkippedTest.php'); + FS::touch('Test.php'); + FS::touch('MainTest.php'); + FS::touch('SkippedTest.php'); - touch('Makefile'); + FS::touch('Makefile'); - mkdir('doc'); - touch('doc/file0'); + FS::mkdir('doc'); + FS::touch('doc/file0'); - mkdir('docs'); - touch('docs/file0'); + FS::mkdir('docs'); + FS::touch('docs/file0'); - mkdir('src'); - touch('src/.fileB0'); - touch('src/foo.php'); - touch('src/doc.md'); - touch('src/doc.rst'); - touch('src/composer.json'); + FS::mkdir('src'); + FS::touch('src/.fileB0'); + FS::touch('src/foo.php'); + FS::touch('src/doc.md'); + FS::touch('src/doc.rst'); + FS::touch('src/composer.json'); - mkdir('test'); - touch('test/file0'); - touch('test/Test.php'); - touch('test/MainTest.php'); - touch('test/SkippedTest.php'); + FS::mkdir('test'); + FS::touch('test/file0'); + FS::touch('test/Test.php'); + FS::touch('test/MainTest.php'); + FS::touch('test/SkippedTest.php'); - mkdir('tests'); - touch('tests/file0'); - touch('tests/Test.php'); - touch('tests/MainTest.php'); - touch('tests/SkippedTest.php'); + FS::mkdir('tests'); + FS::touch('tests/file0'); + FS::touch('tests/Test.php'); + FS::touch('tests/MainTest.php'); + FS::touch('tests/SkippedTest.php'); - mkdir('src/Test'); - touch('src/Test/file0'); - touch('src/Test/Test.php'); - touch('src/Test/MainTest.php'); - touch('src/Test/SkippedTest.php'); + FS::mkdir('src/Test'); + FS::touch('src/Test/file0'); + FS::touch('src/Test/Test.php'); + FS::touch('src/Test/MainTest.php'); + FS::touch('src/Test/SkippedTest.php'); - mkdir('src/Tests'); - touch('src/Tests/file0'); - touch('src/Tests/Test.php'); - touch('src/Tests/MainTest.php'); - touch('src/Tests/SkippedTest.php'); + FS::mkdir('src/Tests'); + FS::touch('src/Tests/file0'); + FS::touch('src/Tests/Test.php'); + FS::touch('src/Tests/MainTest.php'); + FS::touch('src/Tests/SkippedTest.php'); - mkdir('travis'); - touch('travis/install-ev.sh'); + FS::mkdir('travis'); + FS::touch('travis/install-ev.sh'); - mkdir('.travis'); - touch('.travis/install-ev.sh'); + FS::mkdir('.travis'); + FS::touch('.travis/install-ev.sh'); - touch('.travis.yml'); - touch('appveyor.yml'); + FS::touch('.travis.yml'); + FS::touch('appveyor.yml'); - touch('phpdoc.dist.xml'); - touch('phpdoc.xml'); + FS::touch('phpdoc.dist.xml'); + FS::touch('phpdoc.xml'); - touch('psalm.xml'); + FS::touch('psalm.xml'); - touch('Vagrantfile'); + FS::touch('Vagrantfile'); - touch('phpstan.neon.dist'); - touch('phpstan.neon'); - touch('phpstan-test.neon'); + FS::touch('phpstan.neon.dist'); + FS::touch('phpstan.neon'); + FS::touch('phpstan-test.neon'); - touch('infection.json.dist'); - touch('infection.json'); + FS::touch('infection.json.dist'); + FS::touch('infection.json'); - touch('humbug.json.dist'); - touch('humbug.json'); + FS::touch('humbug.json.dist'); + FS::touch('humbug.json'); - touch('easy-coding-standard.neon'); - touch('easy-coding-standard.neon.dist'); + FS::touch('easy-coding-standard.neon'); + FS::touch('easy-coding-standard.neon.dist'); - touch('phpbench.json.dist'); - touch('phpbench.json'); + FS::touch('phpbench.json.dist'); + FS::touch('phpbench.json'); - touch('phpcs.xml.dist'); - touch('phpcs.xml'); + FS::touch('phpcs.xml.dist'); + FS::touch('phpcs.xml'); - touch('.php_cs.dist'); - touch('.php_cs'); - touch('.php_cs.cache'); + FS::touch('.php_cs.dist'); + FS::touch('.php_cs'); + FS::touch('.php_cs.cache'); - touch('.php-cs-fixer.dist.php'); - touch('.php-cs-fixer.php'); - touch('.php-cs-fixer.cache'); + FS::touch('.php-cs-fixer.dist.php'); + FS::touch('.php-cs-fixer.php'); + FS::touch('.php-cs-fixer.cache'); - touch('scoper.inc.php.dist'); - touch('scoper.inc.php'); + FS::touch('scoper.inc.php.dist'); + FS::touch('scoper.inc.php'); - mkdir('example'); - touch('example/file0'); + FS::mkdir('example'); + FS::touch('example/file0'); - mkdir('examples'); - touch('examples/file0'); + FS::mkdir('examples'); + FS::touch('examples/file0'); - mkdir('build'); - touch('build/file0'); + FS::mkdir('build'); + FS::touch('build/file0'); - mkdir('dist'); - touch('dist/file0'); + FS::mkdir('dist'); + FS::touch('dist/file0'); - mkdir('specs'); - touch('specs/file0'); + FS::mkdir('specs'); + FS::touch('specs/file0'); - mkdir('spec'); - touch('spec/MainSpec.php'); + FS::mkdir('spec'); + FS::touch('spec/MainSpec.php'); - mkdir('features'); - touch('features/acme.feature'); + FS::mkdir('features'); + FS::touch('features/acme.feature'); - touch('build.xml.dist'); - touch('build.xml'); + FS::touch('build.xml.dist'); + FS::touch('build.xml'); - touch('.editorconfig'); - touch('.gitattributes'); - touch('.gitignore'); + FS::touch('.editorconfig'); + FS::touch('.gitattributes'); + FS::touch('.gitignore'); - touch('behat.yml.dist'); - touch('behat.yml'); + FS::touch('behat.yml.dist'); + FS::touch('behat.yml'); - touch('box.json.dist'); - touch('box.json'); - touch('box_dev.json'); + FS::touch('box.json.dist'); + FS::touch('box.json'); + FS::touch('box_dev.json'); - touch('Dockerfile'); + FS::touch('Dockerfile'); - touch('codecov.yml.dist'); - touch('codecov.yml'); + FS::touch('codecov.yml.dist'); + FS::touch('codecov.yml'); - touch('.styleci.yml.dist'); - touch('.styleci.yml'); + FS::touch('.styleci.yml.dist'); + FS::touch('.styleci.yml'); - touch('.scrutiziner.yml.dist'); - touch('.scrutiziner.yml'); + FS::touch('.scrutiziner.yml.dist'); + FS::touch('.scrutiziner.yml'); - dump_file( + FS::dumpFile( 'composer.json', <<<'JSON' { @@ -743,7 +740,7 @@ public function test_it_ignores_the_most_common_non_needed_files_when_guess_the_ public function test_the_existing_phars_are_ignored_when_all_the_files_are_collected(): void { - touch('index.phar'); + FS::touch('index.phar'); // Relative to the current working directory for readability $expected = []; @@ -755,8 +752,8 @@ public function test_the_existing_phars_are_ignored_when_all_the_files_are_colle self::assertEquals($expected, $actual); self::assertCount(0, $this->config->getBinaryFiles()); - remove('index.phar'); - touch('default'); + FS::remove('index.phar'); + FS::touch('default'); // Relative to the current working directory for readability $expected = []; @@ -773,18 +770,18 @@ public function test_the_existing_phars_are_ignored_when_all_the_files_are_colle public function test_the_box_debug_directory_is_always_excluded(): void { - touch('file0'); - touch('file1'); + FS::touch('file0'); + FS::touch('file1'); - mkdir('.box_dump'); - touch('.box_dump/file0'); - touch('.box_dump/file1'); + FS::mkdir('.box_dump'); + FS::touch('.box_dump/file0'); + FS::touch('.box_dump/file1'); - mkdir('A'); - touch('A/fileA0'); - touch('A/fileA1'); + FS::mkdir('A'); + FS::touch('A/fileA0'); + FS::touch('A/fileA1'); - dump_file( + FS::dumpFile( 'composer.json', <<<'JSON' { @@ -814,9 +811,9 @@ public function test_the_box_debug_directory_is_always_excluded(): void public function test_it_includes_the_vendor_files_when_found(): void { - dump_file('vendor/composer/installed.json', '{}'); - dump_file('composer.json', '{}'); - dump_file('composer.lock', '{}'); + FS::dumpFile('vendor/composer/installed.json', '{}'); + FS::dumpFile('composer.json', '{}'); + FS::dumpFile('composer.lock', '{}'); // Relative to the current working directory for readability $expected = [ diff --git a/tests/Configuration/ConfigurationFileTest.php b/tests/Configuration/ConfigurationFileTest.php index adc1fc9f1..73c5040dd 100644 --- a/tests/Configuration/ConfigurationFileTest.php +++ b/tests/Configuration/ConfigurationFileTest.php @@ -14,16 +14,12 @@ namespace KevinGH\Box\Configuration; +use Fidry\FileSystem\FS; use InvalidArgumentException; use KevinGH\Box\Json\JsonValidationException; +use Symfony\Component\Filesystem\Path; use function chdir; use function file_get_contents; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\make_path_absolute; -use function KevinGH\Box\FileSystem\mkdir; -use function KevinGH\Box\FileSystem\rename; -use function KevinGH\Box\FileSystem\symlink; -use function KevinGH\Box\FileSystem\touch; use function Safe\json_decode; use function sprintf; use const DIRECTORY_SEPARATOR; @@ -41,42 +37,42 @@ class ConfigurationFileTest extends ConfigurationTestCase public function test_the_files_can_be_configured(): void { - touch('file0'); - touch('file1'); - - mkdir('B'); - touch('B/file1'); - touch('B/fileB0'); - touch('B/fileB1'); - touch('B/glob_finder_excluded_file'); - touch('B/glob-finder_excluded_file'); - - mkdir('C'); - touch('C/fileC0'); - touch('C/fileC1'); - - mkdir('D'); - touch('D/fileD0'); - touch('D/fileD1'); - touch('D/finder_excluded_file'); - - mkdir('E'); - touch('E/fileE0'); - touch('E/fileE1'); - touch('E/finder_excluded_file'); - - mkdir('F'); - touch('F/fileF0'); - touch('F/fileF1'); - touch('F/fileF2'); - touch('F/fileF3'); - - mkdir('vendor'); - touch('vendor/glob_finder_excluded_file'); - touch('vendor/glob-finder_excluded_file'); - - mkdir('vendor-bin'); - touch('vendor-bin/file1'); + FS::touch('file0'); + FS::touch('file1'); + + FS::mkdir('B'); + FS::touch('B/file1'); + FS::touch('B/fileB0'); + FS::touch('B/fileB1'); + FS::touch('B/glob_finder_excluded_file'); + FS::touch('B/glob-finder_excluded_file'); + + FS::mkdir('C'); + FS::touch('C/fileC0'); + FS::touch('C/fileC1'); + + FS::mkdir('D'); + FS::touch('D/fileD0'); + FS::touch('D/fileD1'); + FS::touch('D/finder_excluded_file'); + + FS::mkdir('E'); + FS::touch('E/fileE0'); + FS::touch('E/fileE1'); + FS::touch('E/finder_excluded_file'); + + FS::mkdir('F'); + FS::touch('F/fileF0'); + FS::touch('F/fileF1'); + FS::touch('F/fileF2'); + FS::touch('F/fileF3'); + + FS::mkdir('vendor'); + FS::touch('vendor/glob_finder_excluded_file'); + FS::touch('vendor/glob-finder_excluded_file'); + + FS::mkdir('vendor-bin'); + FS::touch('vendor-bin/file1'); $this->setConfig([ 'files' => [ @@ -175,41 +171,41 @@ public function test_the_generated_artefact_is_always_ignored(callable $setUp, a public function test_configured_files_are_relative_to_base_path(): void { - mkdir('sub-dir'); + FS::mkdir('sub-dir'); - rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); + FS::rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); chdir('sub-dir'); - touch('file0'); - touch('file1'); + FS::touch('file0'); + FS::touch('file1'); - mkdir('B'); - touch('B/fileB0'); - touch('B/fileB1'); - touch('B/glob_finder_excluded_file'); - touch('B/glob-finder_excluded_file'); + FS::mkdir('B'); + FS::touch('B/fileB0'); + FS::touch('B/fileB1'); + FS::touch('B/glob_finder_excluded_file'); + FS::touch('B/glob-finder_excluded_file'); - mkdir('C'); - touch('C/fileC0'); - touch('C/fileC1'); + FS::mkdir('C'); + FS::touch('C/fileC0'); + FS::touch('C/fileC1'); - mkdir('D'); - touch('D/fileD0'); - touch('D/fileD1'); - touch('D/finder_excluded_file'); + FS::mkdir('D'); + FS::touch('D/fileD0'); + FS::touch('D/fileD1'); + FS::touch('D/finder_excluded_file'); - mkdir('E'); - touch('E/fileE0'); - touch('E/fileE1'); - touch('E/finder_excluded_file'); + FS::mkdir('E'); + FS::touch('E/fileE0'); + FS::touch('E/fileE1'); + FS::touch('E/finder_excluded_file'); - mkdir('vendor'); - touch('vendor/glob_finder_excluded_file'); - touch('vendor/glob-finder_excluded_file'); + FS::mkdir('vendor'); + FS::touch('vendor/glob_finder_excluded_file'); + FS::touch('vendor/glob-finder_excluded_file'); - mkdir('vendor-bin'); - touch('vendor-bin/file1'); + FS::mkdir('vendor-bin'); + FS::touch('vendor-bin/file1'); chdir($this->tmp); @@ -267,29 +263,29 @@ public function test_configured_files_are_relative_to_base_path(): void public function test_configured_files_are_relative_to_base_path_unless_they_are_absolute_paths(): void { - mkdir('sub-dir'); + FS::mkdir('sub-dir'); chdir('sub-dir'); - touch('file0'); - touch('file1'); + FS::touch('file0'); + FS::touch('file1'); - mkdir('B'); - touch('B/fileB0'); - touch('B/fileB1'); + FS::mkdir('B'); + FS::touch('B/fileB0'); + FS::touch('B/fileB1'); - mkdir('C'); - touch('C/fileC0'); - touch('C/fileC1'); + FS::mkdir('C'); + FS::touch('C/fileC0'); + FS::touch('C/fileC1'); - mkdir('D'); - touch('D/fileD0'); - touch('D/fileD1'); - touch('D/finder_excluded_file'); + FS::mkdir('D'); + FS::touch('D/fileD0'); + FS::touch('D/fileD1'); + FS::touch('D/finder_excluded_file'); - mkdir('E'); - touch('E/fileE0'); - touch('E/fileE1'); - touch('E/finder_excluded_file'); + FS::mkdir('E'); + FS::touch('E/fileE0'); + FS::touch('E/fileE1'); + FS::touch('E/finder_excluded_file'); chdir($this->tmp); @@ -345,8 +341,8 @@ public function test_configured_files_are_relative_to_base_path_unless_they_are_ public function test_the_files_belonging_to_dev_packages_are_ignored_only_in_the_finder_config(): void { - dump_file('composer.json', '{}'); - dump_file( + FS::dumpFile('composer.json', '{}', ''); + FS::dumpFile( 'composer.lock', <<<'JSON' { @@ -358,33 +354,33 @@ public function test_the_files_belonging_to_dev_packages_are_ignored_only_in_the } JSON, ); - dump_file('vendor/composer/installed.json', '{}'); + FS::dumpFile('vendor/composer/installed.json', '{}', ''); - touch('file0'); - touch('file1'); + FS::touch('file0'); + FS::touch('file1'); - dump_file('vendor/acme/foo/af0'); - dump_file('vendor/acme/foo/af1'); + FS::dumpFile('vendor/acme/foo/af0', ''); + FS::dumpFile('vendor/acme/foo/af1', ''); - dump_file('vendor/acme/bar/ab0'); - dump_file('vendor/acme/bar/ab1'); + FS::dumpFile('vendor/acme/bar/ab0', ''); + FS::dumpFile('vendor/acme/bar/ab1', ''); - dump_file('vendor/acme/oof/ao0'); - dump_file('vendor/acme/oof/ao1'); + FS::dumpFile('vendor/acme/oof/ao0', ''); + FS::dumpFile('vendor/acme/oof/ao1', ''); - mkdir('C'); - touch('C/fileC0'); - touch('C/fileC1'); + FS::mkdir('C'); + FS::touch('C/fileC0'); + FS::touch('C/fileC1'); - mkdir('D'); - touch('D/fileD0'); - touch('D/fileD1'); - touch('D/finder_excluded_file'); + FS::mkdir('D'); + FS::touch('D/fileD0'); + FS::touch('D/fileD1'); + FS::touch('D/finder_excluded_file'); - mkdir('E'); - touch('E/fileE0'); - touch('E/fileE1'); - touch('E/finder_excluded_file'); + FS::mkdir('E'); + FS::touch('E/fileE0'); + FS::touch('E/fileE1'); + FS::touch('E/finder_excluded_file'); $this->setConfig([ 'files' => [ @@ -458,7 +454,7 @@ public function test_a_non_existent_file_cannot_be_added_to_the_list_of_files(): self::fail('Expected exception to be thrown.'); } catch (InvalidArgumentException $exception) { - $filePath = make_path_absolute('non-existent', $this->tmp); + $filePath = Path::makeAbsolute('non-existent', $this->tmp); self::assertSame( sprintf( @@ -472,16 +468,16 @@ public function test_a_non_existent_file_cannot_be_added_to_the_list_of_files(): public function test_symlinks_are_not_supported_in_finder_in_setting(): void { - mkdir('sub-dir'); + FS::mkdir('sub-dir'); - rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); + FS::rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); - mkdir('F'); - touch('F/fileF0'); - touch('F/fileF1'); - touch('F/finder_excluded_file'); + FS::mkdir('F'); + FS::touch('F/fileF0'); + FS::touch('F/fileF1'); + FS::touch('F/finder_excluded_file'); - symlink('F', 'sub-dir/F'); + FS::symlink('F', 'sub-dir/F'); try { $this->setConfig([ @@ -509,16 +505,16 @@ public function test_symlinks_are_not_supported_in_finder_in_setting(): void public function test_appending_a_file_from_a_symlinked_directory_is_not_supported(): void { - mkdir('sub-dir'); + FS::mkdir('sub-dir'); - rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); + FS::rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); - mkdir('F'); - touch('F/fileF0'); - touch('F/fileF1'); - touch('F/finder_excluded_file'); + FS::mkdir('F'); + FS::touch('F/fileF0'); + FS::touch('F/fileF1'); + FS::touch('F/finder_excluded_file'); - symlink('F', 'sub-dir/F'); + FS::symlink('F', 'sub-dir/F'); try { $this->setConfig([ @@ -546,16 +542,16 @@ public function test_appending_a_file_from_a_symlinked_directory_is_not_supporte public function test_appending_a_symlinked_file_is_not_supported(): void { - mkdir('sub-dir'); + FS::mkdir('sub-dir'); - rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); + FS::rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); - mkdir('F'); - touch('F/fileF0'); - touch('F/fileF1'); - touch('F/finder_excluded_file'); + FS::mkdir('F'); + FS::touch('F/fileF0'); + FS::touch('F/fileF1'); + FS::touch('F/finder_excluded_file'); - symlink('F/fileF0', 'sub-dir/F/fileF0'); + FS::symlink('F/fileF0', 'sub-dir/F/fileF0'); try { $this->setConfig([ @@ -583,16 +579,16 @@ public function test_appending_a_symlinked_file_is_not_supported(): void public function test_configuring_a_symlink_file_is_not_supported(): void { - mkdir('sub-dir'); + FS::mkdir('sub-dir'); - rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); + FS::rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); - mkdir('F'); - touch('F/fileF0'); - touch('F/fileF1'); - touch('F/finder_excluded_file'); + FS::mkdir('F'); + FS::touch('F/fileF0'); + FS::touch('F/fileF1'); + FS::touch('F/finder_excluded_file'); - symlink('F/fileF0', 'sub-dir/F/fileF0'); + FS::symlink('F/fileF0', 'sub-dir/F/fileF0'); try { $this->setConfig([ @@ -615,16 +611,16 @@ public function test_configuring_a_symlink_file_is_not_supported(): void public function test_configuring_a_symlink_directory_is_not_supported(): void { - mkdir('sub-dir'); + FS::mkdir('sub-dir'); - rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); + FS::rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); - mkdir('F'); - touch('F/fileF0'); - touch('F/fileF1'); - touch('F/finder_excluded_file'); + FS::mkdir('F'); + FS::touch('F/fileF0'); + FS::touch('F/fileF1'); + FS::touch('F/finder_excluded_file'); - symlink('F', 'sub-dir/F'); + FS::symlink('F', 'sub-dir/F'); try { $this->setConfig([ @@ -647,7 +643,7 @@ public function test_configuring_a_symlink_directory_is_not_supported(): void public function test_cannot_add_a_directory_to_the_list_of_files(): void { - mkdir('dirA'); + FS::mkdir('dirA'); try { $this->setConfig([ @@ -695,7 +691,7 @@ public function test_cannot_add_a_non_existent_directory_to_the_list_of_director public function test_cannot_add_a_file_to_the_list_of_directories(): void { - touch('foo'); + FS::touch('foo'); try { $this->setConfig([ @@ -720,30 +716,30 @@ public function test_cannot_add_a_file_to_the_list_of_directories(): void public function test_the_bin_files_iterator_can_be_configured(): void { - touch('file0'); - touch('file1'); + FS::touch('file0'); + FS::touch('file1'); - mkdir('B'); - touch('B/fileB0'); - touch('B/fileB1'); + FS::mkdir('B'); + FS::touch('B/fileB0'); + FS::touch('B/fileB1'); - mkdir('C'); - touch('C/fileC0'); - touch('C/fileC1'); + FS::mkdir('C'); + FS::touch('C/fileC0'); + FS::touch('C/fileC1'); - mkdir('D'); - touch('D/fileD0'); - touch('D/fileD1'); - touch('D/finder_excluded_file'); + FS::mkdir('D'); + FS::touch('D/fileD0'); + FS::touch('D/fileD1'); + FS::touch('D/finder_excluded_file'); - mkdir('E'); - touch('E/fileE0'); - touch('E/fileE1'); - touch('E/finder_excluded_file'); + FS::mkdir('E'); + FS::touch('E/fileE0'); + FS::touch('E/fileE1'); + FS::touch('E/finder_excluded_file'); - mkdir('F'); - touch('F/fileF0'); - touch('F/fileF1'); + FS::mkdir('F'); + FS::touch('F/fileF0'); + FS::touch('F/fileF1'); $this->setConfig([ 'files-bin' => [ @@ -799,32 +795,32 @@ public function test_the_bin_files_iterator_can_be_configured(): void public function test_configured_bin_files_are_relative_to_base_path(): void { - mkdir('sub-dir'); + FS::mkdir('sub-dir'); - rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); + FS::rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); chdir('sub-dir'); - touch('file0'); - touch('file1'); + FS::touch('file0'); + FS::touch('file1'); - mkdir('B'); - touch('B/fileB0'); - touch('B/fileB1'); + FS::mkdir('B'); + FS::touch('B/fileB0'); + FS::touch('B/fileB1'); - mkdir('C'); - touch('C/fileC0'); - touch('C/fileC1'); + FS::mkdir('C'); + FS::touch('C/fileC0'); + FS::touch('C/fileC1'); - mkdir('D'); - touch('D/fileD0'); - touch('D/fileD1'); - touch('D/finder_excluded_file'); + FS::mkdir('D'); + FS::touch('D/fileD0'); + FS::touch('D/fileD1'); + FS::touch('D/finder_excluded_file'); - mkdir('E'); - touch('E/fileE0'); - touch('E/fileE1'); - touch('E/finder_excluded_file'); + FS::mkdir('E'); + FS::touch('E/fileE0'); + FS::touch('E/fileE1'); + FS::touch('E/finder_excluded_file'); chdir($this->tmp); @@ -879,29 +875,29 @@ public function test_configured_bin_files_are_relative_to_base_path(): void public function test_configured_bin_files_are_relative_to_base_path_unless_they_are_absolute_paths(): void { - mkdir('sub-dir'); + FS::mkdir('sub-dir'); chdir('sub-dir'); - touch('file0'); - touch('file1'); + FS::touch('file0'); + FS::touch('file1'); - mkdir('B'); - touch('B/fileB0'); - touch('B/fileB1'); + FS::mkdir('B'); + FS::touch('B/fileB0'); + FS::touch('B/fileB1'); - mkdir('C'); - touch('C/fileC0'); - touch('C/fileC1'); + FS::mkdir('C'); + FS::touch('C/fileC0'); + FS::touch('C/fileC1'); - mkdir('D'); - touch('D/fileD0'); - touch('D/fileD1'); - touch('D/finder_excluded_file'); + FS::mkdir('D'); + FS::touch('D/fileD0'); + FS::touch('D/fileD1'); + FS::touch('D/finder_excluded_file'); - mkdir('E'); - touch('E/fileE0'); - touch('E/fileE1'); - touch('E/finder_excluded_file'); + FS::mkdir('E'); + FS::touch('E/fileE0'); + FS::touch('E/fileE1'); + FS::touch('E/finder_excluded_file'); chdir($this->tmp); @@ -980,7 +976,7 @@ public function test_cannot_add_a_non_existent_bin_file_to_the_list_of_files(): public function test_cannot_add_a_directory_to_the_list_of_bin_files(): void { - mkdir('dirA'); + FS::mkdir('dirA'); try { $this->setConfig([ @@ -1028,7 +1024,7 @@ public function test_cannot_add_a_non_existent_directory_to_the_list_of_bin_dire public function test_cannot_add_a_file_to_the_list_of_bin_directories(): void { - touch('foo'); + FS::touch('foo'); try { $this->setConfig([ @@ -1053,11 +1049,11 @@ public function test_cannot_add_a_file_to_the_list_of_bin_directories(): void public function test_the_cannot_be_included_twice(): void { - mkdir('A'); - touch('A/foo'); + FS::mkdir('A'); + FS::touch('A/foo'); - mkdir('B'); - touch('B/bar'); + FS::mkdir('B'); + FS::touch('B/bar'); $this->setConfig([ 'files' => [ @@ -1139,9 +1135,9 @@ public function test_blacklist_value_must_be_an_array_of_strings(mixed $value): public function test_the_blacklist_input_is_normalized(): void { - mkdir('B'); - touch('B/fileB0'); - touch('B/fileB1'); + FS::mkdir('B'); + FS::touch('B/fileB0'); + FS::touch('B/fileB1'); $this->setConfig([ 'directories' => [ @@ -1229,7 +1225,7 @@ public function test_bin_files_value_must_be_an_array_of_strings(mixed $value): public function test_the_files_and_bin_files_input_is_normalized(): void { - touch('foo'); + FS::touch('foo'); $this->setConfig([ 'files' => [ @@ -1306,8 +1302,8 @@ public function test_bin_directories_value_must_be_an_array_of_strings(mixed $va public function test_the_directories_and_bin_directories_input_is_normalized(): void { - mkdir('A'); - touch('A/foo'); + FS::mkdir('A'); + FS::touch('A/foo'); $this->setConfig([ 'directories' => [ @@ -1365,35 +1361,35 @@ public function test_a_recommendation_is_given_when_an_emtpy_array_is_given_for_ public function test_finder_and_bin_finder_input_is_normalized(): void { - mkdir('sub-dir'); + FS::mkdir('sub-dir'); - rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); + FS::rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); chdir('sub-dir'); - mkdir('A'); - touch('A/foo'); + FS::mkdir('A'); + FS::touch('A/foo'); - mkdir('A/D0'); - touch('A/D0/da0'); + FS::mkdir('A/D0'); + FS::touch('A/D0/da0'); - mkdir('A/D1'); - touch('A/D1/da1'); + FS::mkdir('A/D1'); + FS::touch('A/D1/da1'); - mkdir('B'); - touch('B/bar'); + FS::mkdir('B'); + FS::touch('B/bar'); - mkdir('D'); - touch('D/doo'); + FS::mkdir('D'); + FS::touch('D/doo'); - mkdir('D/D0'); - touch('D/D0/d0o'); + FS::mkdir('D/D0'); + FS::touch('D/D0/d0o'); - mkdir('D/D1'); - touch('D/D1/d1o'); + FS::mkdir('D/D1'); + FS::touch('D/D1/d1o'); - touch('oof'); - touch('rab'); + FS::touch('oof'); + FS::touch('rab'); chdir($this->tmp); @@ -1432,8 +1428,8 @@ public function test_finder_and_bin_finder_input_is_normalized(): void public function test_finder_and_bin_finder_exclude_files_or_directories_may_not_exists(): void { - mkdir('A'); - touch('A/foo'); + FS::mkdir('A'); + FS::touch('A/foo'); $finderConfig = [ [ @@ -1462,11 +1458,11 @@ public function test_finder_and_bin_finder_exclude_files_or_directories_may_not_ public function test_finder_array_arguments_are_called_as_single_arguments(): void { - mkdir('A'); - touch('A/foo'); + FS::mkdir('A'); + FS::touch('A/foo'); - mkdir('B'); - touch('B/bar'); + FS::mkdir('B'); + FS::touch('B/bar'); $this->setConfig([ 'files' => [], @@ -1513,15 +1509,15 @@ public function test_the_finder_config_cannot_include_invalid_methods(): void public function test_the_composer_json_and_lock_files_are_always_included_even_when_the_user_configure_which_files_to_pick(): void { - touch('file0'); - touch('file1'); + FS::touch('file0'); + FS::touch('file1'); - mkdir('B'); - touch('B/fileB0'); - touch('B/fileB1'); + FS::mkdir('B'); + FS::touch('B/fileB0'); + FS::touch('B/fileB1'); - dump_file('composer.json', '{}'); - dump_file('composer.lock', '{}'); + FS::dumpFile('composer.json', '{}', ''); + FS::dumpFile('composer.lock', '{}', ''); $this->setConfig([ 'files' => [ @@ -1586,65 +1582,65 @@ public function test_files_are_autodiscovered_unless_directory_or_finder_config_ public function test_append_autodiscovered_files_to_configured_files_if_the_autodiscovery_is_forced(): void { - touch('file0'); - touch('file1'); - touch('file2'); + FS::touch('file0'); + FS::touch('file1'); + FS::touch('file2'); - mkdir('B'); - touch('B/fileB0'); - touch('B/fileB1'); + FS::mkdir('B'); + FS::touch('B/fileB0'); + FS::touch('B/fileB1'); - mkdir('PSR4_0'); - touch('PSR4_0/file0'); - touch('PSR4_0/file1'); + FS::mkdir('PSR4_0'); + FS::touch('PSR4_0/file0'); + FS::touch('PSR4_0/file1'); - mkdir('PSR4_1'); - touch('PSR4_1/file0'); - touch('PSR4_1/file1'); + FS::mkdir('PSR4_1'); + FS::touch('PSR4_1/file0'); + FS::touch('PSR4_1/file1'); - mkdir('PSR4_2'); - touch('PSR4_2/file0'); - touch('PSR4_2/file1'); + FS::mkdir('PSR4_2'); + FS::touch('PSR4_2/file0'); + FS::touch('PSR4_2/file1'); - mkdir('DEV_PSR4_0'); - touch('DEV_PSR4_0/file0'); - touch('DEV_PSR4_0/file1'); + FS::mkdir('DEV_PSR4_0'); + FS::touch('DEV_PSR4_0/file0'); + FS::touch('DEV_PSR4_0/file1'); - mkdir('PSR0_0'); - touch('PSR0_0/file0'); - touch('PSR0_0/file1'); + FS::mkdir('PSR0_0'); + FS::touch('PSR0_0/file0'); + FS::touch('PSR0_0/file1'); - mkdir('PSR0_1'); - touch('PSR0_1/file0'); - touch('PSR0_1/file1'); + FS::mkdir('PSR0_1'); + FS::touch('PSR0_1/file0'); + FS::touch('PSR0_1/file1'); - mkdir('PSR0_2'); - touch('PSR0_2/file0'); - touch('PSR0_2/file1'); + FS::mkdir('PSR0_2'); + FS::touch('PSR0_2/file0'); + FS::touch('PSR0_2/file1'); - mkdir('DEV_PSR0_0'); - touch('DEV_PSR0_0/file0'); - touch('DEV_PSR0_0/file1'); + FS::mkdir('DEV_PSR0_0'); + FS::touch('DEV_PSR0_0/file0'); + FS::touch('DEV_PSR0_0/file1'); - mkdir('CLASSMAP_DIR'); - touch('CLASSMAP_DIR/file0'); - touch('CLASSMAP_DIR/file1'); + FS::mkdir('CLASSMAP_DIR'); + FS::touch('CLASSMAP_DIR/file0'); + FS::touch('CLASSMAP_DIR/file1'); - mkdir('CLASSMAP_DEV_DIR'); - touch('CLASSMAP_DEV_DIR/file0'); - touch('CLASSMAP_DEV_DIR/file1'); + FS::mkdir('CLASSMAP_DEV_DIR'); + FS::touch('CLASSMAP_DEV_DIR/file0'); + FS::touch('CLASSMAP_DEV_DIR/file1'); - mkdir('dir0'); - touch('dir0/file0'); - touch('dir0/file1'); - touch('dir0/blacklisted_file'); + FS::mkdir('dir0'); + FS::touch('dir0/file0'); + FS::touch('dir0/file1'); + FS::touch('dir0/blacklisted_file'); - mkdir('dir1'); - touch('dir1/file0'); - touch('dir1/file1'); - touch('dir1/blacklisted_file'); + FS::mkdir('dir1'); + FS::touch('dir1/file0'); + FS::touch('dir1/file1'); + FS::touch('dir1/blacklisted_file'); - dump_file( + FS::dumpFile( 'composer.json', <<<'JSON' { @@ -1844,8 +1840,8 @@ public function test_no_warning_is_given_when_the_installed_json_is_found_and_th public function test_dev_files_are_excluded_or_included_depending_of_the_exclude_dev_files_setting(): void { - dump_file('composer.json', '{}'); - dump_file( + FS::dumpFile('composer.json', '{}', ''); + FS::dumpFile( 'composer.lock', <<<'JSON' { @@ -1859,16 +1855,16 @@ public function test_dev_files_are_excluded_or_included_depending_of_the_exclude } JSON, ); - dump_file('vendor/composer/installed.json', '{}'); + FS::dumpFile('vendor/composer/installed.json', '{}', ''); - dump_file('vendor/acme/foo/af0'); - dump_file('vendor/acme/foo/af1'); + FS::dumpFile('vendor/acme/foo/af0', ''); + FS::dumpFile('vendor/acme/foo/af1', ''); - dump_file('vendor/acme/bar/ab0'); - dump_file('vendor/acme/bar/ab1'); + FS::dumpFile('vendor/acme/bar/ab0', ''); + FS::dumpFile('vendor/acme/bar/ab1', ''); - dump_file('vendor/acme/oof/ao0'); - dump_file('vendor/acme/oof/ao1'); + FS::dumpFile('vendor/acme/oof/ao0', ''); + FS::dumpFile('vendor/acme/oof/ao1', ''); $this->reloadConfig(); @@ -1917,9 +1913,9 @@ public static function configWithMainScriptProvider(): iterable { yield [ static function (): void { - touch('main-script'); - touch('file0'); - touch('file1'); + FS::touch('main-script'); + FS::touch('file0'); + FS::touch('file1'); }, [ 'main' => 'main-script', @@ -1938,11 +1934,11 @@ static function (): void { yield [ static function (): void { - mkdir('sub-dir'); + FS::mkdir('sub-dir'); - touch('sub-dir/main-script'); - touch('sub-dir/file0'); - touch('sub-dir/file1'); + FS::touch('sub-dir/main-script'); + FS::touch('sub-dir/file0'); + FS::touch('sub-dir/file1'); }, [ 'base-path' => 'sub-dir', @@ -1962,10 +1958,10 @@ static function (): void { yield [ static function (): void { - mkdir('A'); - touch('A/main-script'); - touch('A/file0'); - touch('A/file1'); + FS::mkdir('A'); + FS::touch('A/main-script'); + FS::touch('A/file0'); + FS::touch('A/file1'); }, [ 'main' => 'A/main-script', @@ -1982,11 +1978,11 @@ static function (): void { yield [ static function (): void { - mkdir('sub-dir'); - mkdir('sub-dir/A'); - touch('sub-dir/A/main-script'); - touch('sub-dir/A/file0'); - touch('sub-dir/A/file1'); + FS::mkdir('sub-dir'); + FS::mkdir('sub-dir/A'); + FS::touch('sub-dir/A/main-script'); + FS::touch('sub-dir/A/file0'); + FS::touch('sub-dir/A/file1'); }, [ 'base-path' => 'sub-dir', @@ -2004,11 +2000,11 @@ static function (): void { yield [ static function (): void { - mkdir('A'); + FS::mkdir('A'); - touch('A/main-script'); - touch('A/file0'); - touch('A/file1'); + FS::touch('A/main-script'); + FS::touch('A/file0'); + FS::touch('A/file1'); }, [ 'main' => 'A/main-script', @@ -2033,9 +2029,9 @@ static function (): void { yield [ static function (): void { - touch('main-script'); - touch('file0'); - touch('file1'); + FS::touch('main-script'); + FS::touch('file0'); + FS::touch('file1'); }, [ 'main' => 'main-script', @@ -2065,11 +2061,11 @@ static function (): void { // The main script is blacklisted but ensures this does not affect the other files collected, like here // the files found in a directory which has the same name as the main script static function (): void { - dump_file('acme'); - dump_file('src/file00'); - dump_file('src/file10'); - dump_file('src/acme/file00'); - dump_file('src/acme/file10'); + FS::dumpFile('acme', ''); + FS::dumpFile('src/file00', ''); + FS::dumpFile('src/file10', ''); + FS::dumpFile('src/acme/file00', ''); + FS::dumpFile('src/acme/file10', ''); }, [ 'main' => 'acme', @@ -2089,10 +2085,10 @@ public static function configWithGeneratedArtefactProvider(): iterable { yield [ static function (): void { - touch('acme.phar'); - touch('index.php'); - touch('file0'); - touch('file1'); + FS::touch('acme.phar'); + FS::touch('index.php'); + FS::touch('file0'); + FS::touch('file1'); }, [ 'output' => 'acme.phar', @@ -2111,12 +2107,12 @@ static function (): void { yield [ static function (): void { - mkdir('sub-dir'); + FS::mkdir('sub-dir'); - touch('sub-dir/acme.phar'); - touch('sub-dir/index.php'); - touch('sub-dir/file0'); - touch('sub-dir/file1'); + FS::touch('sub-dir/acme.phar'); + FS::touch('sub-dir/index.php'); + FS::touch('sub-dir/file0'); + FS::touch('sub-dir/file1'); }, [ 'base-path' => 'sub-dir', @@ -2136,11 +2132,11 @@ static function (): void { yield [ static function (): void { - touch('index.php'); - mkdir('A'); - touch('A/acme.phar'); - touch('A/file0'); - touch('A/file1'); + FS::touch('index.php'); + FS::mkdir('A'); + FS::touch('A/acme.phar'); + FS::touch('A/file0'); + FS::touch('A/file1'); }, [ 'output' => 'A/acme.phar', @@ -2157,12 +2153,12 @@ static function (): void { yield [ static function (): void { - mkdir('sub-dir'); - touch('sub-dir/index.php'); - mkdir('sub-dir/A'); - touch('sub-dir/A/acme.phar'); - touch('sub-dir/A/file0'); - touch('sub-dir/A/file1'); + FS::mkdir('sub-dir'); + FS::touch('sub-dir/index.php'); + FS::mkdir('sub-dir/A'); + FS::touch('sub-dir/A/acme.phar'); + FS::touch('sub-dir/A/file0'); + FS::touch('sub-dir/A/file1'); }, [ 'base-path' => 'sub-dir', @@ -2180,12 +2176,12 @@ static function (): void { yield [ static function (): void { - mkdir('A'); + FS::mkdir('A'); - touch('index.php'); - touch('A/acme.phar'); - touch('A/file0'); - touch('A/file1'); + FS::touch('index.php'); + FS::touch('A/acme.phar'); + FS::touch('A/file0'); + FS::touch('A/file1'); }, [ 'output' => 'A/acme.phar', @@ -2210,10 +2206,10 @@ static function (): void { yield [ static function (): void { - touch('acme.phar'); - touch('index.php'); - touch('file0'); - touch('file1'); + FS::touch('acme.phar'); + FS::touch('index.php'); + FS::touch('file0'); + FS::touch('file1'); }, [ 'output' => 'acme.phar', @@ -2243,12 +2239,12 @@ static function (): void { // The main script is blacklisted but ensures this does not affect the other files collected, like here // the files found in a directory which has the same name as the main script static function (): void { - dump_file('index.php'); - dump_file('acme'); - dump_file('src/file00'); - dump_file('src/file10'); - dump_file('src/acme/file00'); - dump_file('src/acme/file10'); + FS::dumpFile('index.php', ''); + FS::dumpFile('acme', ''); + FS::dumpFile('src/file00', ''); + FS::dumpFile('src/file10', ''); + FS::dumpFile('src/acme/file00', ''); + FS::dumpFile('src/acme/file10', ''); }, [ 'output' => 'acme', @@ -2317,11 +2313,11 @@ static function (): void {}, foreach ([true, false] as $booleanValue) { yield [ static function (): void { - touch('main-script'); - touch('file0'); - touch('file-bin0'); - dump_file('directory-bin0/file00'); - dump_file('directory-bin1/file10'); + FS::touch('main-script'); + FS::touch('file0'); + FS::touch('file-bin0'); + FS::dumpFile('directory-bin0/file00', ''); + FS::dumpFile('directory-bin1/file10', ''); }, [ 'main' => 'main-script', @@ -2342,7 +2338,7 @@ static function (): void { yield [ static function (): void { - dump_file('directory0/file00'); + FS::dumpFile('directory0/file00', ''); }, [ 'directories' => ['directory0'], @@ -2352,7 +2348,7 @@ static function (): void { yield [ static function (): void { - dump_file('directory0/file00'); + FS::dumpFile('directory0/file00', ''); }, [ 'directories' => ['directory0'], @@ -2363,7 +2359,7 @@ static function (): void { yield [ static function (): void { - dump_file('directory1/file10'); + FS::dumpFile('directory1/file10', ''); }, [ 'finder' => [ @@ -2377,7 +2373,7 @@ static function (): void { yield [ static function (): void { - dump_file('directory1/file10'); + FS::dumpFile('directory1/file10', ''); }, [ 'finder' => [ @@ -2392,8 +2388,8 @@ static function (): void { yield [ static function (): void { - dump_file('directory0/file00'); - dump_file('directory1/file10'); + FS::dumpFile('directory0/file00', ''); + FS::dumpFile('directory1/file10', ''); }, [ 'directories' => ['directory0'], @@ -2408,8 +2404,8 @@ static function (): void { yield [ static function (): void { - dump_file('directory0/file00'); - dump_file('directory1/file10'); + FS::dumpFile('directory0/file00', ''); + FS::dumpFile('directory1/file10', ''); }, [ 'directories' => ['directory0'], diff --git a/tests/Configuration/ConfigurationLoaderTest.php b/tests/Configuration/ConfigurationLoaderTest.php index dd821664b..9b083ebf8 100644 --- a/tests/Configuration/ConfigurationLoaderTest.php +++ b/tests/Configuration/ConfigurationLoaderTest.php @@ -14,10 +14,9 @@ namespace KevinGH\Box\Configuration; +use Fidry\FileSystem\FS; use KevinGH\Box\Json\JsonValidationException; use KevinGH\Box\Test\FileSystemTestCase; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\touch; /** * @covers \KevinGH\Box\Configuration\ConfigurationLoader @@ -37,8 +36,8 @@ protected function setUp(): void public function test_it_can_load_a_configuration(): void { - touch('index.php'); - dump_file('box.json.dist', '{}'); + FS::touch('index.php'); + FS::dumpFile('box.json.dist', '{}'); self::assertInstanceOf( Configuration::class, @@ -48,7 +47,7 @@ public function test_it_can_load_a_configuration(): void public function test_it_can_load_a_configuration_without_a_file(): void { - touch('index.php'); + FS::touch('index.php'); self::assertInstanceOf( Configuration::class, @@ -58,8 +57,8 @@ public function test_it_can_load_a_configuration_without_a_file(): void public function test_it_cannot_load_an_invalid_config_file(): void { - touch('index.php'); - dump_file('box.json.dist', '{"foo": "bar"}'); + FS::touch('index.php'); + FS::dumpFile('box.json.dist', '{"foo": "bar"}'); $this->expectException(JsonValidationException::class); diff --git a/tests/Configuration/ConfigurationSigningTest.php b/tests/Configuration/ConfigurationSigningTest.php index c898e44ab..91e6b38e4 100644 --- a/tests/Configuration/ConfigurationSigningTest.php +++ b/tests/Configuration/ConfigurationSigningTest.php @@ -14,11 +14,11 @@ namespace KevinGH\Box\Configuration; +use Fidry\FileSystem\FS; use InvalidArgumentException; use Phar; use function array_unshift; use function in_array; -use function KevinGH\Box\FileSystem\touch; use const DIRECTORY_SEPARATOR; /** @@ -192,7 +192,7 @@ public function test_it_generates_a_warning_when_a_key_pass_is_provided_but_the_ */ public function test_it_generates_a_warning_when_a_key_path_is_provided_but_the_algorithm_is_not__open_ssl(string $algorithm): void { - touch('key-file'); + FS::touch('key-file'); $this->setConfig([ 'algorithm' => $algorithm, @@ -233,7 +233,7 @@ public function test_it_generates_a_warning_when_a_key_path_is_provided_but_the_ public function test_the_key_can_be_configured(): void { - touch('key-file'); + FS::touch('key-file'); $this->setConfig([ 'algorithm' => 'OPENSSL', @@ -250,7 +250,7 @@ public function test_the_key_can_be_configured(): void public function test_the_key_pass_can_be_configured(): void { - touch('key-file'); + FS::touch('key-file'); $this->setConfig([ 'algorithm' => 'OPENSSL', diff --git a/tests/Configuration/ConfigurationTest.php b/tests/Configuration/ConfigurationTest.php index a57a9d42c..77d5f3d51 100644 --- a/tests/Configuration/ConfigurationTest.php +++ b/tests/Configuration/ConfigurationTest.php @@ -15,6 +15,7 @@ namespace KevinGH\Box\Configuration; use DateTimeImmutable; +use Fidry\FileSystem\FS; use InvalidArgumentException; use KevinGH\Box\Compactor\DummyCompactor; use KevinGH\Box\Compactor\InvalidCompactor; @@ -36,12 +37,6 @@ use function exec; use function getcwd; use function json_decode; -use function KevinGH\Box\FileSystem\chmod; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\file_contents; -use function KevinGH\Box\FileSystem\mkdir; -use function KevinGH\Box\FileSystem\rename; -use function KevinGH\Box\FileSystem\touch; use function KevinGH\Box\get_box_version; use function mt_getrandmax; use function random_int; @@ -172,7 +167,7 @@ public function test_the_alias_must_be_a_string(): void public function test_a_warning_is_given_if_the_alias_has_been_set_but_a_custom_stub_is_provided(): void { - touch('stub-path.php'); + FS::touch('stub-path.php'); $this->setConfig([ 'alias' => 'test.phar', @@ -190,8 +185,8 @@ public function test_a_warning_is_given_if_the_alias_has_been_set_but_a_custom_s public function test_the_default_base_path_used_is_the_configuration_file_location(): void { - dump_file('sub-dir/box.json', '{}'); - dump_file('sub-dir/index.php'); + FS::dumpFile('sub-dir/box.json', '{}'); + FS::dumpFile('sub-dir/index.php'); $this->file = $this->tmp.'/sub-dir/box.json'; @@ -210,8 +205,8 @@ public function test_if_there_is_no_file_the_default_base_path_used_is_the_curre public function test_the_base_path_can_be_configured(): void { - mkdir($basePath = $this->tmp.DIRECTORY_SEPARATOR.'test'); - rename(self::DEFAULT_FILE, $basePath.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); + FS::mkdir($basePath = $this->tmp.DIRECTORY_SEPARATOR.'test'); + FS::rename(self::DEFAULT_FILE, $basePath.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); $this->setConfig([ 'base-path' => $basePath, @@ -263,7 +258,7 @@ public function test_a_non_existent_directory_cannot_be_used_as_a_base_path(): v public function test_a_file_path_cannot_be_used_as_a_base_path(): void { - touch('foo'); + FS::touch('foo'); try { $this->setConfig([ @@ -282,8 +277,8 @@ public function test_a_file_path_cannot_be_used_as_a_base_path(): void public function test_if_the_base_path_is_relative_then_it_is_relative_to_the_current_working_directory(): void { - mkdir('dir'); - rename(self::DEFAULT_FILE, 'dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); + FS::mkdir('dir'); + FS::rename(self::DEFAULT_FILE, 'dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); $this->setConfig([ 'base-path' => 'dir', @@ -299,8 +294,8 @@ public function test_if_the_base_path_is_relative_then_it_is_relative_to_the_cur public function test_the_base_path_value_is_normalized(): void { - mkdir('dir'); - rename(self::DEFAULT_FILE, 'dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); + FS::mkdir('dir'); + FS::rename(self::DEFAULT_FILE, 'dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); $this->setConfig([ 'base-path' => ' dir ', @@ -348,7 +343,7 @@ public function test_it_attempts_to_get_and_decode_the_json_and_lock_files( public function test_it_throws_an_error_when_a_composer_file_is_found_but_invalid(): void { - dump_file('composer.json', ''); + FS::dumpFile('composer.json', ''); try { $this->reloadConfig(); @@ -371,7 +366,7 @@ public function test_it_throws_an_error_when_a_composer_file_is_found_but_invali public function test_it_throws_an_error_when_a_composer_lock_is_found_but_invalid(): void { - dump_file('composer.lock', ''); + FS::dumpFile('composer.lock', ''); try { $this->reloadConfig(); @@ -415,7 +410,7 @@ public function test_the_autoloader_is_dumped_by_default_if_a_composer_json_file $this->config->getWarnings(), ); - dump_file('composer.json', '{}'); + FS::dumpFile('composer.json', '{}'); $this->setConfig([]); @@ -435,7 +430,7 @@ public function test_the_autoloader_is_dumped_by_default_if_a_composer_json_file public function test_the_autoloader_dumping_can_be_configured(): void { - dump_file('composer.json', '{}'); + FS::dumpFile('composer.json', '{}'); $this->setConfig([ 'dump-autoload' => false, @@ -663,7 +658,7 @@ public function test_it_cannot_configure_an_invalid_compactor(): void public function test_the_php_scoper_configuration_location_can_be_configured(): void { - dump_file('custom.scoper.ini.php', " 'custom'];"); + FS::dumpFile('custom.scoper.ini.php', " 'custom'];"); $this->setConfig([ 'php-scoper' => 'custom.scoper.ini.php', @@ -682,7 +677,7 @@ public function test_the_php_scoper_configuration_location_can_be_configured(): public function test_a_default_scoper_path_is_configured_by_default(): void { - dump_file('scoper.inc.php', " 'custom'];"); + FS::dumpFile('scoper.inc.php', " 'custom'];"); $this->setConfig([ 'compactors' => [ @@ -860,7 +855,7 @@ public function test_configure_file_mode(): void public function test_a_main_script_path_is_configured_by_default(): void { - dump_file('composer.json', '{"bin": []}'); + FS::dumpFile('composer.json', '{"bin": []}'); self::assertTrue($this->config->hasMainScript()); self::assertSame($this->tmp.DIRECTORY_SEPARATOR.'index.php', $this->config->getMainScriptPath()); @@ -872,9 +867,9 @@ public function test_a_main_script_path_is_configured_by_default(): void public function test_a_main_script_path_is_inferred_by_the_composer_json_by_default(): void { - dump_file('bin/foo'); + FS::dumpFile('bin/foo'); - dump_file( + FS::dumpFile( 'composer.json', <<<'JSON' { @@ -897,10 +892,10 @@ public function test_a_main_script_path_is_inferred_by_the_composer_json_by_defa public function test_the_first_composer_bin_is_used_as_the_main_script_by_default(): void { - dump_file('bin/foo'); - dump_file('bin/bar'); + FS::dumpFile('bin/foo'); + FS::dumpFile('bin/bar'); - dump_file( + FS::dumpFile( 'composer.json', <<<'JSON' { @@ -924,12 +919,12 @@ public function test_the_first_composer_bin_is_used_as_the_main_script_by_defaul public function test_the_main_script_can_be_configured(): void { - dump_file('test.php', 'Main script contents'); + FS::dumpFile('test.php', 'Main script contents'); - dump_file('bin/foo'); - dump_file('bin/bar'); + FS::dumpFile('bin/foo'); + FS::dumpFile('bin/bar'); - dump_file( + FS::dumpFile( 'composer.json', <<<'JSON' { @@ -953,7 +948,7 @@ public function test_the_main_script_can_be_configured(): void public function test_the_main_script_path_is_normalized(): void { - touch('test.php'); + FS::touch('test.php'); $this->setConfig(['main' => ' test.php ']); @@ -965,7 +960,7 @@ public function test_the_main_script_path_is_normalized(): void public function test_main_script_content_ignores_shebang_line(): void { - dump_file('test.php', "#!/usr/bin/env php\ntest"); + FS::dumpFile('test.php', "#!/usr/bin/env php\ntest"); $this->setConfig(['main' => 'test.php']); @@ -991,10 +986,10 @@ public function test_it_cannot_get_the_main_script_if_file_does_not_exists(): vo public function test_the_main_script_can_be_disabled(): void { - dump_file('bin/foo'); - dump_file('bin/bar'); + FS::dumpFile('bin/foo'); + FS::dumpFile('bin/bar'); - dump_file( + FS::dumpFile( 'composer.json', <<<'JSON' { @@ -1216,8 +1211,8 @@ public function test_a_recommendation_is_given_when_the_default_path_is_given(): public function test_the_output_path_is_relative_to_the_base_path(): void { - mkdir('sub-dir'); - rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); + FS::mkdir('sub-dir'); + FS::rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); $this->setConfig([ 'output' => 'test.phar', @@ -1239,8 +1234,8 @@ public function test_the_output_path_is_relative_to_the_base_path(): void public function test_the_output_path_is_not_relative_to_the_base_path_if_is_absolute(): void { - mkdir('sub-dir'); - rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); + FS::mkdir('sub-dir'); + FS::rename(self::DEFAULT_FILE, 'sub-dir'.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); $this->setConfig([ 'output' => $this->tmp.'/test.phar', @@ -1302,7 +1297,7 @@ public function test_the_output_path_can_omit_the_phar_extension(): void public function test_get_default_output_path_depends_on_the_input(): void { - dump_file('bin/acme'); + FS::dumpFile('bin/acme'); $this->setConfig([ 'main' => 'bin/acme', @@ -1327,7 +1322,7 @@ public function test_no_replacements_are_configured_by_default(): void public function test_the_replacement_map_can_be_configured(): void { - touch('test'); + FS::touch('test'); exec('git init -b main'); exec('git config user.name "Test User"'); exec('git config user.email test@test.test'); @@ -1365,7 +1360,7 @@ public function test_the_replacement_map_can_be_configured(): void self::assertSame([], $this->config->getRecommendations()); self::assertSame([], $this->config->getWarnings()); - touch('foo'); + FS::touch('foo'); exec('git add foo'); exec('git commit -m "Adding another test file."'); @@ -1409,10 +1404,10 @@ public function test_the_replacement_map_can_be_configured_when_base_path_is_dif { // Make another directory level to have config not in base-path. $basePath = $this->tmp.DIRECTORY_SEPARATOR.'subdir'; - mkdir($basePath); - rename(self::DEFAULT_FILE, $basePath.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); + FS::mkdir($basePath); + FS::rename(self::DEFAULT_FILE, $basePath.DIRECTORY_SEPARATOR.self::DEFAULT_FILE); chdir($basePath); - touch('test'); + FS::touch('test'); exec('git init -b main'); exec('git config user.name "Test User"'); exec('git config user.email test@test.test'); @@ -1445,7 +1440,7 @@ public function test_the_replacement_map_can_be_configured_when_base_path_is_dif self::assertSame([], $this->config->getWarnings()); chdir($basePath); - touch('foo'); + FS::touch('foo'); exec('git add foo'); exec('git commit -m "Adding another test file."'); chdir($this->tmp); @@ -1628,7 +1623,7 @@ public function test_a_recommendation_is_given_if_the_shebang_configured_to_its_ public function test_a_warning_is_given_if_the_shebang_configured_but_a_custom_stub_is_used(): void { - touch('my-stub.php'); + FS::touch('my-stub.php'); $this->setConfig([ 'shebang' => $expected = '#!/bin/php', @@ -1662,7 +1657,7 @@ public function test_a_warning_is_given_if_the_shebang_configured_but_the_phar_d public function test_a_recommendation_is_given_if_the_shebang_disabled_and_a_custom_stub_is_used(): void { - touch('my-stub.php'); + FS::touch('my-stub.php'); $this->setConfig([ 'shebang' => false, @@ -2046,7 +2041,7 @@ public function test_a_custom_banner_can_be_registered(string $banner): void public function test_a_warning_is_given_when_the_banner_is_configured_but_the_box_stub_is_not_used(): void { - touch('my-stub.php'); + FS::touch('my-stub.php'); foreach (['my-stub.php', false] as $stub) { $this->setConfig([ @@ -2067,7 +2062,7 @@ public function test_a_warning_is_given_when_the_banner_is_configured_but_the_bo public function test_a_recommendation_is_given_when_the_banner_is_disabled_but_the_box_stub_is_not_used(): void { - touch('my-stub.php'); + FS::touch('my-stub.php'); foreach (['my-stub.php', false] as $stub) { $this->setConfig([ @@ -2186,7 +2181,7 @@ public function test_a_custom_banner_from_a_file_can_be_registered(): void comment. COMMENT; - dump_file('banner', $comment); + FS::dumpFile('banner', $comment); $this->setConfig([ 'banner-file' => 'banner', @@ -2223,7 +2218,7 @@ public function test_a_recommendation_is_given_if_the_default_stub_banner_path_i ); self::assertSame([], $this->config->getWarnings()); - dump_file('custom-banner', $defaultBanner); + FS::dumpFile('custom-banner', $defaultBanner); $this->setConfig([ 'banner-file' => 'custom-banner', @@ -2240,7 +2235,7 @@ public function test_a_recommendation_is_given_if_the_default_stub_banner_path_i $version = self::$version; - dump_file( + FS::dumpFile( 'custom-banner', <<setConfig([ @@ -2295,7 +2290,7 @@ public function test_the_banner_value_is_discarded_if_a_banner_file_is_registere comment. COMMENT; - dump_file('banner', $comment); + FS::dumpFile('banner', $comment); $this->setConfig([ 'banner' => 'discarded banner', @@ -2328,7 +2323,7 @@ public function test_the_content_of_the_custom_banner_file_is_normalized(): void comment. COMMENT; - dump_file('banner', $comment); + FS::dumpFile('banner', $comment); $this->setConfig([ 'banner-file' => 'banner', @@ -2396,7 +2391,7 @@ public function test_by_default_there_is_no_stub_and_the_stub_is_generated(): vo public function test_a_custom_stub_can_be_provided(): void { - dump_file('custom-stub.php', ''); + FS::dumpFile('custom-stub.php', ''); $this->setConfig([ 'stub' => 'custom-stub.php', @@ -2490,7 +2485,7 @@ public function test_the_intercept_funcs_can_be_enabled(): void public function test_a_warning_is_given_when_the_intercept_funcs_is_configured_but_the_box_stub_is_not_used(): void { - touch('my-stub.php'); + FS::touch('my-stub.php'); foreach (['my-stub.php', false] as $stub) { $this->setConfig([ @@ -2510,7 +2505,7 @@ public function test_a_warning_is_given_when_the_intercept_funcs_is_configured_b public function test_a_recommendation_is_given_when_the_intercept_funcs_is_disabled_but_the_box_stub_is_not_used(): void { - touch('my-stub.php'); + FS::touch('my-stub.php'); foreach (['my-stub.php', false] as $stub) { $this->setConfig([ @@ -2539,7 +2534,7 @@ public function test_the_requirement_checker_can_be_disabled(): void self::assertSame([], $this->config->getRecommendations()); self::assertSame([], $this->config->getWarnings()); - dump_file('composer.lock', '{}'); + FS::dumpFile('composer.lock', '{}'); $this->reloadConfig(); @@ -2554,7 +2549,7 @@ public function test_the_requirement_checker_is_enabled_by_default_if_a_composer // Sanity check self::assertFalse($this->config->checkRequirements()); - dump_file('composer.json', '{}'); + FS::dumpFile('composer.json', '{}'); $this->reloadConfig(); @@ -2569,7 +2564,7 @@ public function test_the_requirement_checker_is_enabled_by_default_if_a_composer // Sanity check self::assertFalse($this->config->checkRequirements()); - dump_file('composer.lock', '{}'); + FS::dumpFile('composer.lock', '{}'); $this->reloadConfig(); @@ -2584,8 +2579,8 @@ public function test_the_requirement_checker_is_enabled_by_default_if_a_composer // Sanity check self::assertFalse($this->config->checkRequirements()); - dump_file('composer.json', '{}'); - dump_file('composer.lock', '{}'); + FS::dumpFile('composer.json', '{}'); + FS::dumpFile('composer.lock', '{}'); $this->reloadConfig(); @@ -2597,8 +2592,8 @@ public function test_the_requirement_checker_is_enabled_by_default_if_a_composer public function test_the_requirement_checker_can_be_enabled(): void { - dump_file('composer.json', '{}'); - dump_file('composer.lock', '{}'); + FS::dumpFile('composer.json', '{}'); + FS::dumpFile('composer.lock', '{}'); $this->setConfig([ 'check-requirements' => true, @@ -2633,7 +2628,7 @@ public function test_the_requirement_checker_is_forcibly_disabled_if_the_compose public function test_the_requirement_checker_is_not_disabled_but_a_warning_is_emitted_if_enabled_without_a_composer_lock_file(): void { - dump_file('composer.json', '{}'); + FS::dumpFile('composer.json', '{}'); $this->setConfig([ 'check-requirements' => true, @@ -2683,9 +2678,9 @@ public function test_a_recommendation_is_given_if_the_default_check_requirement_ $this->config->getWarnings(), ); - dump_file('composer.json', '{}'); - dump_file('composer.lock', '{}'); - dump_file('vendor/composer/installed.json', '{}'); + FS::dumpFile('composer.json', '{}'); + FS::dumpFile('composer.lock', '{}'); + FS::dumpFile('vendor/composer/installed.json', '{}'); $this->setConfig([ 'check-requirements' => null, @@ -2714,9 +2709,9 @@ public function test_a_recommendation_is_given_if_the_default_check_requirement_ public function test_warning_is_given_if_the_check_requirement_is_configured_but_the_phar_stub_used(): void { - dump_file('composer.json', '{}'); - dump_file('composer.lock', '{}'); - dump_file('vendor/composer/installed.json', '{}'); + FS::dumpFile('composer.json', '{}'); + FS::dumpFile('composer.lock', '{}'); + FS::dumpFile('vendor/composer/installed.json', '{}'); $this->setConfig([ 'check-requirements' => true, @@ -2755,7 +2750,7 @@ public function test_by_default_dev_files_are_excluded_if_dump_autoload_is_enabl ); self::assertSame([], $this->config->getWarnings()); - dump_file('composer.json', '{}'); + FS::dumpFile('composer.json', '{}'); $this->setConfig([]); @@ -2811,7 +2806,7 @@ public function test_by_default_dev_files_are_excluded_if_dump_autoload_is_enabl public function test_a_recommendation_is_given_if_exclude_dev_files_is_enabled_when_the_autoload_is_dumped(): void { - dump_file('composer.json', '{}'); + FS::dumpFile('composer.json', '{}'); $this->setConfig([ 'dump-autoload' => true, @@ -2836,7 +2831,7 @@ public function test_a_recommendation_is_given_if_exclude_dev_files_is_enabled_w public function test_a_recommendation_is_given_if_exclude_dev_files_is_disabled_when_the_autoload_is_not_dumped(): void { - dump_file('composer.json', '{}'); + FS::dumpFile('composer.json', '{}'); $this->setConfig([ 'dump-autoload' => false, @@ -2858,7 +2853,7 @@ public function test_a_recommendation_is_given_if_exclude_dev_files_is_disabled_ public function test_the_dev_files_can_be_not_excluded_when_the_autoloader_is_dumped(): void { - dump_file('composer.json', '{}'); + FS::dumpFile('composer.json', '{}'); $this->setConfig([ 'dump-autoload' => true, @@ -2880,7 +2875,7 @@ public function test_the_dev_files_can_be_not_excluded_when_the_autoloader_is_du public function test_a_warning_is_given_if_dev_files_are_explicitly_excluded_but_the_autoloader_not_dumped(): void { - dump_file('composer.json', '{}'); + FS::dumpFile('composer.json', '{}'); $this->setConfig([ 'dump-autoload' => false, @@ -2959,10 +2954,10 @@ public function test_it_can_be_created_with_only_default_values(): void public function test_it_can_be_exported(): void { - touch('foo.php'); - touch('bar.php'); + FS::touch('foo.php'); + FS::touch('bar.php'); - dump_file( + FS::dumpFile( 'composer.json', <<<'JSON' { @@ -2976,8 +2971,8 @@ public function test_it_can_be_exported(): void } JSON, ); - dump_file('composer.lock', '{}'); - dump_file('vendor/composer/installed.json', '{}'); + FS::dumpFile('composer.lock', '{}'); + FS::dumpFile('vendor/composer/installed.json', '{}'); $this->setConfig([ 'alias' => 'test.phar', @@ -3190,7 +3185,7 @@ static function (): void {}, yield [ static function (): void { - dump_file('composer.json', '{}'); + FS::dumpFile('composer.json', '{}'); }, 'composer.json', [], @@ -3200,7 +3195,7 @@ static function (): void { yield [ static function (): void { - dump_file('composer.json', '{"name": "acme/foo"}'); + FS::dumpFile('composer.json', '{"name": "acme/foo"}'); }, 'composer.json', ['name' => 'acme/foo'], @@ -3210,7 +3205,7 @@ static function (): void { yield [ static function (): void { - dump_file('composer.lock', '{}'); + FS::dumpFile('composer.lock', '{}'); }, null, null, @@ -3220,7 +3215,7 @@ static function (): void { yield [ static function (): void { - dump_file('composer.lock', '{"name": "acme/foo"}'); + FS::dumpFile('composer.lock', '{"name": "acme/foo"}'); }, null, null, @@ -3230,8 +3225,8 @@ static function (): void { yield [ static function (): void { - dump_file('composer.json', '{"name": "acme/foo"}'); - dump_file('composer.lock', '{"name": "acme/bar"}'); + FS::dumpFile('composer.json', '{"name": "acme/foo"}'); + FS::dumpFile('composer.lock', '{"name": "acme/bar"}'); }, 'composer.json', ['name' => 'acme/foo'], @@ -3241,7 +3236,7 @@ static function (): void { yield [ static function (): void { - mkdir('composer.json'); + FS::mkdir('composer.json'); }, null, null, @@ -3251,7 +3246,7 @@ static function (): void { yield [ static function (): void { - mkdir('composer.lock'); + FS::mkdir('composer.lock'); }, null, null, @@ -3261,8 +3256,8 @@ static function (): void { yield [ static function (): void { - touch('composer.json'); - chmod('composer.json', 0); + FS::touch('composer.json'); + FS::chmod('composer.json', 0); }, null, null, @@ -3272,8 +3267,8 @@ static function (): void { yield [ static function (): void { - touch('composer.lock'); - chmod('composer.lock', 0); + FS::touch('composer.lock'); + FS::chmod('composer.lock', 0); }, null, null, @@ -3296,7 +3291,7 @@ public static function PassFileFreeSigningAlgorithmProvider(): iterable private function retrieveSchemaKeys(): array { $schema = json_decode( - file_contents(__DIR__.'/../../res/schema.json'), + FS::getFileContents(__DIR__.'/../../res/schema.json'), true, 512, JSON_THROW_ON_ERROR, diff --git a/tests/Configuration/ConfigurationTestCase.php b/tests/Configuration/ConfigurationTestCase.php index 8dc094021..4659a029b 100644 --- a/tests/Configuration/ConfigurationTestCase.php +++ b/tests/Configuration/ConfigurationTestCase.php @@ -14,12 +14,11 @@ namespace KevinGH\Box\Configuration; +use Fidry\FileSystem\FS; use KevinGH\Box\Test\FileSystemTestCase; use stdClass; +use Symfony\Component\Filesystem\Path; use function json_encode; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\make_path_absolute; -use function KevinGH\Box\FileSystem\touch; use const JSON_PRETTY_PRINT; use const PHP_OS; @@ -37,17 +36,17 @@ protected function setUp(): void { parent::setUp(); - $this->file = make_path_absolute('box.json', $this->tmp); + $this->file = Path::makeAbsolute('box.json', $this->tmp); - touch(self::DEFAULT_FILE); - dump_file($this->file, '{}'); + FS::touch(self::DEFAULT_FILE); + FS::dumpFile($this->file, '{}'); $this->config = Configuration::create($this->file, new stdClass()); } final protected function setConfig(array $config): void { - dump_file($this->file, json_encode($config, JSON_PRETTY_PRINT)); + FS::dumpFile($this->file, json_encode($config, JSON_PRETTY_PRINT)); $this->reloadConfig(); } diff --git a/tests/Console/Command/CompileTest.php b/tests/Console/Command/CompileTest.php index f8ccadb48..cb5edd9f2 100644 --- a/tests/Console/Command/CompileTest.php +++ b/tests/Console/Command/CompileTest.php @@ -21,6 +21,7 @@ use Fidry\Console\ExitCode; use Fidry\Console\Test\CommandTester; use Fidry\Console\Test\OutputAssertions; +use Fidry\FileSystem\FS; use InvalidArgumentException; use KevinGH\Box\Compactor\Php; use KevinGH\Box\Console\Application; @@ -46,13 +47,6 @@ use function iterator_to_array; use function json_decode; use function json_encode; -use function KevinGH\Box\FileSystem\chmod; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\file_contents; -use function KevinGH\Box\FileSystem\mirror; -use function KevinGH\Box\FileSystem\remove; -use function KevinGH\Box\FileSystem\rename; -use function KevinGH\Box\FileSystem\touch; use function KevinGH\Box\format_size; use function KevinGH\Box\get_box_version; use function KevinGH\Box\memory_to_bytes; @@ -172,7 +166,7 @@ protected function setUp(): void ), ); - remove(self::FIXTURES_DIR.'/dir010/index.phar'); + FS::remove(self::FIXTURES_DIR.'/dir010/index.phar'); } protected function tearDown(): void @@ -191,17 +185,17 @@ protected function getCommand(): Command public function test_it_can_build_a_phar_file(): void { - mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); - dump_file('composer.json', '{}'); - dump_file('composer.lock', '{}'); - dump_file('vendor/composer/installed.json', '{}'); + FS::dumpFile('composer.json', '{}'); + FS::dumpFile('composer.lock', '{}'); + FS::dumpFile('vendor/composer/installed.json', '{}'); $shebang = sprintf('#!%s', (new PhpExecutableFinder())->find()); $numberOfFiles = self::NUMBER_OF_FILES; - dump_file( + FS::dumpFile( 'box.json', json_encode( [ @@ -357,11 +351,11 @@ public function test_it_can_build_a_phar_file(): void public function test_it_can_build_a_phar_from_a_different_directory(): void { - mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); $shebang = sprintf('#!%s', (new PhpExecutableFinder())->find()); - dump_file( + FS::dumpFile( 'box.json', json_encode( [ @@ -409,9 +403,9 @@ public function test_it_can_build_a_phar_from_a_different_directory(): void public function test_it_can_build_a_phar_without_any_configuration(): void { - mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); - rename('run.php', 'index.php'); + FS::rename('run.php', 'index.php'); $this->commandTester->execute( [ @@ -561,9 +555,9 @@ public function test_it_can_build_a_phar_without_any_configuration(): void public function test_it_can_build_a_phar_with_complete_mapping(): void { - mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); - dump_file( + FS::dumpFile( 'box.json', json_encode( [ @@ -724,9 +718,9 @@ public function test_it_can_build_a_phar_with_complete_mapping(): void public function test_it_can_build_a_phar_with_complete_mapping_without_an_alias(): void { - mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); - dump_file( + FS::dumpFile( 'box.json', json_encode( [ @@ -801,14 +795,14 @@ public function test_it_can_build_a_phar_file_in_verbose_mode(): void self::markTestSkipped('Skipping this test since xdebug changes the Composer output.'); } - mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); $shebang = sprintf('#!%s', (new PhpExecutableFinder())->find()); $expectedNumberOfClasses = 1; $expectedNumberOfFiles = self::NUMBER_OF_FILES; - dump_file( + FS::dumpFile( 'box.json', json_encode( [ @@ -926,14 +920,14 @@ public function test_it_can_build_a_phar_file_in_very_verbose_mode(): void self::markTestSkipped('Skipping this test since xdebug changes the Composer output'); } - mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); $shebang = sprintf('#!%s', (new PhpExecutableFinder())->find()); $expectedNumberOfClasses = 1; $expectedNumberOfFiles = self::NUMBER_OF_FILES; - dump_file( + FS::dumpFile( 'box.json', json_encode( [ @@ -1057,7 +1051,7 @@ public function test_it_can_build_a_phar_file_in_very_verbose_mode(): void public function test_it_can_build_a_phar_file_in_debug_mode(): void { - dump_file( + FS::dumpFile( 'index.php', $indexContents = <<<'PHP' tmp, - file_contents('.box_dump/.box_configuration'), + FS::getFileContents('.box_dump/.box_configuration'), ); // Replace objects IDs @@ -1324,11 +1318,11 @@ public function test_it_can_build_a_phar_file_in_debug_mode(): void public function test_it_can_build_a_phar_file_in_quiet_mode(): void { - mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); $shebang = sprintf('#!%s', (new PhpExecutableFinder())->find()); - dump_file( + FS::dumpFile( 'box.json', json_encode( [ @@ -1391,11 +1385,11 @@ public function test_it_can_build_a_phar_file_in_quiet_mode(): void public function test_it_can_build_a_phar_file_using_the_phar_default_stub(): void { - mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); $shebang = sprintf('#!%s', (new PhpExecutableFinder())->find()); - dump_file( + FS::dumpFile( 'box.json', json_encode( [ @@ -1440,11 +1434,11 @@ public function test_it_can_build_a_phar_file_using_the_phar_default_stub(): voi public function test_it_can_build_a_phar_file_using_a_custom_stub(): void { - mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); $shebang = sprintf('#!%s', (new PhpExecutableFinder())->find()); - dump_file( + FS::dumpFile( 'custom_stub', $stub = <<<'PHP' #!/usr/bin/php @@ -1464,7 +1458,7 @@ public function test_it_can_build_a_phar_file_using_a_custom_stub(): void PHP, ); - dump_file( + FS::dumpFile( 'box.json', json_encode( [ @@ -1516,9 +1510,9 @@ public function test_it_can_build_a_phar_file_using_a_custom_stub(): void public function test_it_can_build_a_phar_file_using_the_default_stub(): void { - mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); - dump_file( + FS::dumpFile( 'box.json', json_encode( [ @@ -1552,11 +1546,11 @@ public function test_it_can_build_a_phar_file_using_the_default_stub(): void public function test_it_cannot_build_a_phar_using_unreadable_files(): void { - touch('index.php'); - touch('unreadable-file.php'); - chmod('unreadable-file.php', 0); + FS::touch('index.php'); + FS::touch('unreadable-file.php'); + FS::chmod('unreadable-file.php', 0); - dump_file( + FS::dumpFile( 'box.json', json_encode( [ @@ -1582,7 +1576,7 @@ public function test_it_cannot_build_a_phar_using_unreadable_files(): void public function test_it_can_build_a_phar_overwriting_an_existing_one_in_verbose_mode(): void { - mirror(self::FIXTURES_DIR.'/dir002', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir002', $this->tmp); $this->commandTester->execute( [ @@ -1659,9 +1653,9 @@ public function test_it_can_build_a_phar_overwriting_an_existing_one_in_verbose_ public function test_it_can_dump_the_autoloader(): void { - mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); - rename('run.php', 'index.php'); + FS::rename('run.php', 'index.php'); self::assertFileDoesNotExist($this->tmp.'/vendor/autoload.php'); @@ -1698,13 +1692,13 @@ public function test_it_can_dump_the_autoloader(): void public function test_it_can_build_a_phar_without_dumping_the_autoloader(): void { - mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); - rename('run.php', 'index.php'); + FS::rename('run.php', 'index.php'); self::assertFileDoesNotExist($this->tmp.'/vendor/autoload.php'); - dump_file( + FS::dumpFile( 'box.json', json_encode( [ @@ -1746,9 +1740,9 @@ public function test_it_can_build_a_phar_without_dumping_the_autoloader(): void public function test_it_can_dump_the_autoloader_and_exclude_the_composer_files(): void { - mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); - rename('run.php', 'index.php'); + FS::rename('run.php', 'index.php'); self::assertFileDoesNotExist($this->tmp.'/vendor/autoload.php'); @@ -1795,11 +1789,11 @@ public function test_it_can_dump_the_autoloader_and_exclude_the_composer_files() public function test_it_can_dump_the_autoloader_and_keep_the_composer_files(): void { - mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir000', $this->tmp); - rename('run.php', 'index.php'); + FS::rename('run.php', 'index.php'); - dump_file( + FS::dumpFile( 'box.json', json_encode(['exclude-composer-files' => false]), ); @@ -1851,7 +1845,7 @@ public function test_it_can_dump_the_autoloader_and_keep_the_composer_files(): v public function test_it_can_build_a_phar_with_a_custom_banner(): void { - mirror(self::FIXTURES_DIR.'/dir003', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir003', $this->tmp); $this->commandTester->execute( [ @@ -1920,7 +1914,7 @@ public function test_it_can_build_a_phar_with_a_custom_banner(): void public function test_it_can_build_a_phar_with_a_stub_file(): void { - mirror(self::FIXTURES_DIR.'/dir004', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir004', $this->tmp); $this->commandTester->execute( [ @@ -1987,7 +1981,7 @@ public function test_it_can_build_a_phar_with_a_stub_file(): void public function test_it_can_build_a_phar_with_the_default_stub_file(): void { - mirror(self::FIXTURES_DIR.'/dir005', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir005', $this->tmp); $this->commandTester->execute( [ @@ -2055,9 +2049,9 @@ public function test_it_can_build_a_phar_with_the_default_stub_file(): void public function test_it_can_build_a_phar_without_a_main_script(): void { - mirror(self::FIXTURES_DIR.'/dir004', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir004', $this->tmp); - dump_file( + FS::dumpFile( 'box.json', <<<'JSON' { @@ -2133,9 +2127,9 @@ public function test_it_can_build_a_phar_without_a_main_script(): void public function test_it_can_build_an_empty_phar(): void { - mirror(self::FIXTURES_DIR.'/dir004', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir004', $this->tmp); - dump_file( + FS::dumpFile( 'box.json', <<<'JSON' { @@ -2218,7 +2212,7 @@ public function test_it_can_build_an_empty_phar(): void public function test_it_can_build_a_phar_with_compressed_code(): void { - mirror(self::FIXTURES_DIR.'/dir006', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir006', $this->tmp); $this->commandTester->execute( [ @@ -2298,7 +2292,7 @@ public function test_it_can_build_a_phar_with_compressed_code(): void public function test_it_can_build_a_phar_in_a_non_existent_directory(): void { - mirror(self::FIXTURES_DIR.'/dir007', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir007', $this->tmp); $this->commandTester->execute( [ @@ -2376,9 +2370,9 @@ public function test_it_can_build_a_phar_in_a_non_existent_directory(): void public function test_it_configures_the_phar_alias(bool $stub): void { $this->skipIfDefaultStubNotFound(); - mirror(self::FIXTURES_DIR.'/dir008', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir008', $this->tmp); - dump_file( + FS::dumpFile( 'box.json', json_encode( [ @@ -2455,11 +2449,11 @@ public function test_it_configures_the_phar_alias(bool $stub): void public function test_it_can_build_a_phar_file_without_a_shebang_line(): void { - mirror(self::FIXTURES_DIR.'/dir006', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir006', $this->tmp); $boxRawConfig = json_decode(file_get_contents('box.json'), true, 512, JSON_PRETTY_PRINT); $boxRawConfig['shebang'] = false; - dump_file('box.json', json_encode($boxRawConfig, JSON_PRETTY_PRINT)); + FS::dumpFile('box.json', json_encode($boxRawConfig, JSON_PRETTY_PRINT)); $this->commandTester->execute( [ @@ -2539,9 +2533,9 @@ public function test_it_can_build_a_phar_file_without_a_shebang_line(): void public function test_it_can_build_a_phar_with_an_output_which_does_not_have_a_phar_extension(): void { - mirror(self::FIXTURES_DIR.'/dir004', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir004', $this->tmp); - dump_file( + FS::dumpFile( 'box.json', json_encode( array_merge( @@ -2622,7 +2616,7 @@ public function test_it_can_build_a_phar_with_an_output_which_does_not_have_a_ph public function test_it_can_build_a_phar_ignoring_the_configuration(): void { - mirror(self::FIXTURES_DIR.'/dir009', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir009', $this->tmp); $this->commandTester->execute( [ @@ -2642,7 +2636,7 @@ public function test_it_can_build_a_phar_ignoring_the_configuration(): void public function test_it_ignores_the_config_given_when_the_no_config_setting_is_set(): void { - mirror(self::FIXTURES_DIR.'/dir009', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir009', $this->tmp); $this->commandTester->execute( [ @@ -2663,7 +2657,7 @@ public function test_it_ignores_the_config_given_when_the_no_config_setting_is_s public function test_it_can_build_a_phar_with_a_php_scoper_config(): void { - mirror(self::FIXTURES_DIR.'/dir010', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir010', $this->tmp); $this->commandTester->execute( [ @@ -2700,9 +2694,9 @@ public function test_it_can_build_a_phar_with_a_php_scoper_config(): void public function test_it_can_build_a_phar_with_a_php_scoper_config_with_a_specific_prefix(): void { - mirror(self::FIXTURES_DIR.'/dir010', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir010', $this->tmp); - rename('scoper-fixed-prefix.inc.php', 'scoper.inc.php', true); + FS::rename('scoper-fixed-prefix.inc.php', 'scoper.inc.php', true); $this->commandTester->execute( [ @@ -2739,9 +2733,9 @@ public function test_it_can_build_a_phar_with_a_php_scoper_config_with_a_specifi public function test_it_cannot_sign_a_phar_with_the_openssl_algorithm_without_a_private_key(): void { - mirror(self::FIXTURES_DIR.'/dir010', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir010', $this->tmp); - dump_file( + FS::dumpFile( 'box.json', json_encode( [ @@ -2764,11 +2758,11 @@ public function test_it_cannot_sign_a_phar_with_the_openssl_algorithm_without_a_ public function test_it_displays_recommendations_and_warnings(): void { - mirror(self::FIXTURES_DIR.'/dir010', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir010', $this->tmp); - remove('composer.json'); + FS::remove('composer.json'); - dump_file( + FS::dumpFile( 'box.json', json_encode( [ @@ -2842,9 +2836,9 @@ public function test_it_displays_recommendations_and_warnings(): void public function test_it_skips_the_compression_when_in_dev_mode(): void { - mirror(self::FIXTURES_DIR.'/dir010', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir010', $this->tmp); - dump_file( + FS::dumpFile( 'box.json', json_encode( [ @@ -2921,10 +2915,10 @@ public function test_it_can_generate_a_phar_with_docker(): void self::markTestSkipped('Skipping this test since xdebug has an include wrapper causing this test to fail'); } - mirror(self::FIXTURES_DIR.'/dir010', $this->tmp); + FS::mirror(self::FIXTURES_DIR.'/dir010', $this->tmp); - dump_file('box.json', '{}'); - dump_file('composer.json', '{}'); + FS::dumpFile('box.json', '{}'); + FS::dumpFile('composer.json', '{}'); $this->commandTester->execute( [ diff --git a/tests/Console/Command/ConfigOptionTest.php b/tests/Console/Command/ConfigOptionTest.php index a377cea55..ca4d1fee8 100644 --- a/tests/Console/Command/ConfigOptionTest.php +++ b/tests/Console/Command/ConfigOptionTest.php @@ -15,14 +15,13 @@ namespace KevinGH\Box\Console\Command; use Fidry\Console\Command\Command; +use Fidry\FileSystem\FS; use InvalidArgumentException; use KevinGH\Box\Configuration\Configuration; use KevinGH\Box\Configuration\NoConfigurationFound; use KevinGH\Box\Json\JsonValidationException; use KevinGH\Box\Test\CommandTestCase; use Symfony\Component\Console\Input\InputOption; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\touch; /** * @covers \KevinGH\Box\Console\Command\ConfigOption @@ -50,9 +49,9 @@ public function test_it_has_a_configure_option(): void public function test_it_can_get_the_configuration(): void { - touch('index.php'); + FS::touch('index.php'); - dump_file('box.json', '{"alias": "foo"}'); + FS::dumpFile('box.json', '{"alias": "foo"}'); $config = $this->executeAndGetConfig([]); @@ -61,9 +60,9 @@ public function test_it_can_get_the_configuration(): void public function test_it_can_get_the_configuration_with_a_custom_path(): void { - touch('index.php'); + FS::touch('index.php'); - dump_file('mybox.json', '{"alias": "foo"}'); + FS::dumpFile('mybox.json', '{"alias": "foo"}'); $config = $this->executeAndGetConfig(['--config' => 'mybox.json']); @@ -72,7 +71,7 @@ public function test_it_can_get_the_configuration_with_a_custom_path(): void public function test_it_throws_an_error_when_cannot_load_the_config(): void { - touch('index.php'); + FS::touch('index.php'); $this->expectException(NoConfigurationFound::class); $this->expectExceptionMessage('The configuration file could not be found.'); @@ -82,7 +81,7 @@ public function test_it_throws_an_error_when_cannot_load_the_config(): void public function test_it_loads_an_empty_configuration_if_no_configuration_is_allowed_and_no_config_file_is_found(): void { - touch('index.php'); + FS::touch('index.php'); $config = $this->executeAndGetConfig([], true); @@ -91,9 +90,9 @@ public function test_it_loads_an_empty_configuration_if_no_configuration_is_allo public function test_it_throws_an_error_when_the_config_schema_is_invalid(): void { - touch('index.php'); + FS::touch('index.php'); - dump_file('box.json', '{"foo": "foo"}'); + FS::dumpFile('box.json', '{"foo": "foo"}'); $this->expectException(JsonValidationException::class); $this->expectExceptionMessage('"'.$this->tmp.'/box.json" does not match the expected JSON schema: @@ -104,7 +103,7 @@ public function test_it_throws_an_error_when_the_config_schema_is_invalid(): voi public function test_it_throws_an_error_when_the_config_is_invalid(): void { - dump_file('box.json', '{}'); + FS::dumpFile('box.json', '{}'); $this->expectException(InvalidArgumentException::class); $this->expectExceptionMessage('The file "'.$this->tmp.'/index.php" does not exist.'); diff --git a/tests/Console/Command/ExtractTest.php b/tests/Console/Command/ExtractTest.php index 295a3f687..9f6ed27c9 100644 --- a/tests/Console/Command/ExtractTest.php +++ b/tests/Console/Command/ExtractTest.php @@ -20,10 +20,10 @@ use KevinGH\Box\Phar\PharMeta; use KevinGH\Box\Pharaoh\InvalidPhar; use KevinGH\Box\Test\CommandTestCase; +use Symfony\Component\Filesystem\Path; use Symfony\Component\Finder\Finder; use Symfony\Component\Finder\SplFileInfo; use function count; -use function KevinGH\Box\FileSystem\make_path_relative; use function rtrim; use function Safe\file_get_contents; @@ -371,7 +371,7 @@ private function collectExtractedFiles(): array foreach ($finder as $file) { /** @var SplFileInfo $file */ - $filePath = make_path_relative($file->getPathname(), $this->tmp); + $filePath = Path::makeRelative($file->getPathname(), $this->tmp); $files[$filePath] = $file->getContents(); } diff --git a/tests/Console/Command/Namespace_Test.php b/tests/Console/Command/Namespace_Test.php index f7c769989..4908cc8ed 100644 --- a/tests/Console/Command/Namespace_Test.php +++ b/tests/Console/Command/Namespace_Test.php @@ -16,8 +16,8 @@ use Fidry\Console\Command\Command; use Fidry\Console\ExitCode; +use Fidry\FileSystem\FS; use KevinGH\Box\Test\CommandTestCase; -use function KevinGH\Box\FileSystem\dump_file; /** * @covers \KevinGH\Box\Console\Command\Namespace_ @@ -33,7 +33,7 @@ protected function getCommand(): Command public function test_it_show_the_ng(): void { - dump_file('index.php', ''); + FS::dumpFile('index.php', ''); $this->commandTester->execute( [ diff --git a/tests/Console/Command/ProcessTest.php b/tests/Console/Command/ProcessTest.php index 3b77bc157..fd76b5710 100644 --- a/tests/Console/Command/ProcessTest.php +++ b/tests/Console/Command/ProcessTest.php @@ -16,11 +16,10 @@ use Fidry\Console\Command\Command; use Fidry\Console\ExitCode; +use Fidry\FileSystem\FS; use KevinGH\Box\Console\DisplayNormalizer; use KevinGH\Box\Test\CommandTestCase; use Symfony\Component\Console\Output\OutputInterface; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\touch; /** * @covers \KevinGH\Box\Console\Command\Process @@ -36,7 +35,7 @@ protected function getCommand(): Command public function test_it_processes_a_file_and_displays_the_processed_contents_with_no_config(): void { - dump_file('index.php', ''); + FS::dumpFile('index.php', ''); $this->commandTester->execute( [ @@ -71,8 +70,8 @@ public function test_it_processes_a_file_and_displays_the_processed_contents_wit public function test_it_processes_a_file_and_displays_the_processed_contents_with_a_config(): void { - touch('index.php'); - dump_file( + FS::touch('index.php'); + FS::dumpFile( 'acme.json', <<<'JSON' { @@ -80,7 +79,7 @@ public function test_it_processes_a_file_and_displays_the_processed_contents_wit } JSON, ); - dump_file( + FS::dumpFile( 'box.json', <<<'JSON' { @@ -129,7 +128,7 @@ public function test_it_processes_a_file_and_displays_the_processed_contents_wit public function test_it_processes_the_file_relative_to_the_config_base_path(): void { - dump_file( + FS::dumpFile( 'index.php', <<<'PHP' commandTester->execute( [ @@ -71,8 +70,8 @@ public function test_it_validates_a_given_file(): void public function test_it_reports_the_recommendations_found(): void { - touch('index.php'); - dump_file( + FS::touch('index.php'); + FS::dumpFile( 'test.json', <<<'JSON' { @@ -109,8 +108,8 @@ public function test_it_reports_the_recommendations_found(): void public function test_it_does_not_fail_when_recommendations_are_found_but_ignore_message_is_passed(): void { - touch('index.php'); - dump_file( + FS::touch('index.php'); + FS::dumpFile( 'test.json', <<<'JSON' { @@ -148,8 +147,8 @@ public function test_it_does_not_fail_when_recommendations_are_found_but_ignore_ public function test_it_reports_the_warnings_found(): void { - touch('index.php'); - dump_file( + FS::touch('index.php'); + FS::dumpFile( 'test.json', <<<'JSON' { @@ -186,8 +185,8 @@ public function test_it_reports_the_warnings_found(): void public function test_it_does_not_fail_when_warnings_are_found_but_ignore_message_is_passed(): void { - touch('index.php'); - dump_file( + FS::touch('index.php'); + FS::dumpFile( 'test.json', <<<'JSON' { @@ -225,8 +224,8 @@ public function test_it_does_not_fail_when_warnings_are_found_but_ignore_message public function test_it_reports_the_recommendations_and_warnings_found(): void { - touch('index.php'); - dump_file( + FS::touch('index.php'); + FS::dumpFile( 'test.json', <<<'JSON' { @@ -304,7 +303,7 @@ public function test_an_unknown_file_is_invalid_in_verbose_mode(): void public function test_an_invalid_json_file_is_invalid(): void { - dump_file('box.json', '{'); + FS::dumpFile('box.json', '{'); $this->commandTester->execute( [ @@ -332,7 +331,7 @@ public function test_an_invalid_json_file_is_invalid(): void public function test_an_invalid_json_file_is_invalid_in_verbose_mode(): void { - dump_file('box.json.dist', '{'); + FS::dumpFile('box.json.dist', '{'); try { $this->commandTester->execute( @@ -361,7 +360,7 @@ public function test_an_invalid_json_file_is_invalid_in_verbose_mode(): void public function test_an_incorrect_config_file_is_invalid(): void { - dump_file('box.json', '{"test": true}'); + FS::dumpFile('box.json', '{"test": true}'); $this->commandTester->execute( [ @@ -392,7 +391,7 @@ public function test_an_incorrect_config_file_is_invalid(): void public function test_an_incorrect_config_file_is_invalid_in_verbose_mode(): void { - dump_file('box.json', '{"test": true}'); + FS::dumpFile('box.json', '{"test": true}'); try { $this->commandTester->execute( diff --git a/tests/Console/ConfigurationLocatorTest.php b/tests/Console/ConfigurationLocatorTest.php index 13076e22a..e044e49c1 100644 --- a/tests/Console/ConfigurationLocatorTest.php +++ b/tests/Console/ConfigurationLocatorTest.php @@ -14,9 +14,9 @@ namespace KevinGH\Box\Console; +use Fidry\FileSystem\FS; use KevinGH\Box\Configuration\NoConfigurationFound; use KevinGH\Box\Test\FileSystemTestCase; -use function KevinGH\Box\FileSystem\touch; use const DIRECTORY_SEPARATOR; /** @@ -28,7 +28,7 @@ class ConfigurationLocatorTest extends FileSystemTestCase { public function test_it_finds_the_default_path(): void { - touch('box.json'); + FS::touch('box.json'); self::assertSame( $this->tmp.DIRECTORY_SEPARATOR.'box.json', @@ -38,7 +38,7 @@ public function test_it_finds_the_default_path(): void public function test_it_finds_the_default_dist_path(): void { - touch('box.json.dist'); + FS::touch('box.json.dist'); self::assertSame( $this->tmp.DIRECTORY_SEPARATOR.'box.json.dist', @@ -48,8 +48,8 @@ public function test_it_finds_the_default_dist_path(): void public function test_it_non_dist_file_takes_priority_over_dist_file(): void { - touch('box.json'); - touch('box.json.dist'); + FS::touch('box.json'); + FS::touch('box.json.dist'); self::assertSame( $this->tmp.DIRECTORY_SEPARATOR.'box.json', diff --git a/tests/Json/JsonTest.php b/tests/Json/JsonTest.php index d433a7cff..74cd029d1 100644 --- a/tests/Json/JsonTest.php +++ b/tests/Json/JsonTest.php @@ -14,6 +14,7 @@ namespace KevinGH\Box\Json; +use Fidry\FileSystem\FS; use KevinGH\Box\Test\FileSystemTestCase; use PHPUnit\Framework\AssertionFailedError; use Seld\JsonLint\ParsingException; @@ -22,8 +23,6 @@ use Webmozart\Assert\Assert; use function is_object; use function json_decode; -use function KevinGH\Box\FileSystem\dump_file; -use function KevinGH\Box\FileSystem\touch; use function mb_convert_encoding; /** @@ -108,7 +107,7 @@ public function test_it_can_decode_a_json_string(string $json, bool $assoc, mixe public function test_it_can_decode_a_file(): void { - dump_file('data.json', '{}'); + FS::dumpFile('data.json', '{}'); $decoded = $this->json->decodeFile('data.json'); @@ -118,7 +117,7 @@ public function test_it_can_decode_a_file(): void self::assertSame([], $decoded); - dump_file('data.json', ''); + FS::dumpFile('data.json', ''); try { $this->json->decodeFile('data.json', true); @@ -154,7 +153,7 @@ public function test_it_can_validate_a_file_against_a_schema(): void false, ); - touch('data.json'); + FS::touch('data.json'); $this->json->validate( 'data.json', diff --git a/tests/Json/JsonValidationExceptionTest.php b/tests/Json/JsonValidationExceptionTest.php index 6132fe2ba..ab8629250 100644 --- a/tests/Json/JsonValidationExceptionTest.php +++ b/tests/Json/JsonValidationExceptionTest.php @@ -15,9 +15,9 @@ namespace KevinGH\Box\Json; use Error; +use Fidry\FileSystem\FS; use InvalidArgumentException; use KevinGH\Box\Test\FileSystemTestCase; -use function KevinGH\Box\FileSystem\dump_file; /** * @covers \KevinGH\Box\Json\JsonValidationException @@ -60,7 +60,7 @@ public function test_it_cannot_be_instantiated(): void self::assertNull($exception->getValidatedFile()); self::assertSame([], $exception->getErrors()); - dump_file($file = 'dummy_file', ''); + FS::dumpFile($file = 'dummy_file', ''); $errors = ['foo', 'bar']; $code = 10; $error = new Error();