diff --git a/.github/workflows/composer-root-version.yaml b/.github/workflows/composer-root-version.yaml index f230596d3..28071e0df 100644 --- a/.github/workflows/composer-root-version.yaml +++ b/.github/workflows/composer-root-version.yaml @@ -3,7 +3,15 @@ name: RootVersionChecker on: push: branches: [ main ] - pull_request: + pull_request: ~ + schedule: + # Do not make it the first of the month and/or midnight since it is a very busy time + - cron: "* 10 5 * *" + +# See https://stackoverflow.com/a/72408109 +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true jobs: cs-lint: diff --git a/.github/workflows/e2e-tests.yaml b/.github/workflows/e2e-tests.yaml index d3ea23faf..e23216931 100644 --- a/.github/workflows/e2e-tests.yaml +++ b/.github/workflows/e2e-tests.yaml @@ -3,9 +3,17 @@ name: End-to-End Tests on: push: branches: [ main ] - pull_request: + pull_request: ~ release: types: [ created ] + schedule: + # Do not make it the first of the month and/or midnight since it is a very busy time + - cron: "* 10 5 * *" + +# See https://stackoverflow.com/a/72408109 +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true jobs: build-test-phar: diff --git a/.github/workflows/lint.yaml b/.github/workflows/lint.yaml index 14c315dc4..ab14c5e59 100644 --- a/.github/workflows/lint.yaml +++ b/.github/workflows/lint.yaml @@ -3,7 +3,15 @@ name: Lint on: push: branches: [ main ] - pull_request: + pull_request: ~ + schedule: + # Do not make it the first of the month and/or midnight since it is a very busy time + - cron: "* 10 5 * *" + +# See https://stackoverflow.com/a/72408109 +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true jobs: cs: diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index b675fba6e..0116a7953 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -3,9 +3,17 @@ name: Release on: push: branches: [ main ] - pull_request: + pull_request: ~ release: types: [ created ] + schedule: + # Do not make it the first of the month and/or midnight since it is a very busy time + - cron: "* 10 5 * *" + +# See https://stackoverflow.com/a/72408109 +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true jobs: build-phar: diff --git a/.github/workflows/security.yaml b/.github/workflows/security.yaml index 8d4367aeb..7664b8599 100644 --- a/.github/workflows/security.yaml +++ b/.github/workflows/security.yaml @@ -3,9 +3,17 @@ name: Security on: push: branches: [ main ] - pull_request: + pull_request: ~ release: types: [ created ] + schedule: + # Do not make it the first of the month and/or midnight since it is a very busy time + - cron: "* 10 5 * *" + +# See https://stackoverflow.com/a/72408109 +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true jobs: security: diff --git a/.github/workflows/tests.yaml b/.github/workflows/tests.yaml index f11b74ece..4fceb0d45 100644 --- a/.github/workflows/tests.yaml +++ b/.github/workflows/tests.yaml @@ -3,9 +3,17 @@ name: Tests on: push: branches: [ main ] - pull_request: + pull_request: ~ release: - types: [ created ] + types: [ created ] ~ + schedule: + # Do not make it the first of the month and/or midnight since it is a very busy time + - cron: "* 10 5 * *" + +# See https://stackoverflow.com/a/72408109 +concurrency: + group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref }} + cancel-in-progress: true jobs: root-version: diff --git a/composer-root-version-checker/src/CouldNotParseTag.php b/composer-root-version-checker/src/CouldNotParseTag.php index 14359bc5e..dba81f7f4 100644 --- a/composer-root-version-checker/src/CouldNotParseTag.php +++ b/composer-root-version-checker/src/CouldNotParseTag.php @@ -44,7 +44,7 @@ public static function noNameTagFound( } public static function withReason( - null|bool|int|float|string $tag, + null|bool|float|int|string $tag, string $reason ): self { return new self( diff --git a/composer-root-version-checker/src/Logger.php b/composer-root-version-checker/src/Logger.php index 6ffbadaeb..ac5b66459 100644 --- a/composer-root-version-checker/src/Logger.php +++ b/composer-root-version-checker/src/Logger.php @@ -31,7 +31,7 @@ public function __destruct() $this->writeRecords(); } - public function log($level, Stringable|string $message, array $context = []): void + public function log($level, string|Stringable $message, array $context = []): void { $record = sprintf('[%s] %s', $level, $message).PHP_EOL; diff --git a/composer.json b/composer.json index f2283add6..75242c8f9 100644 --- a/composer.json +++ b/composer.json @@ -18,13 +18,14 @@ ], "require": { "php": "^8.1", - "fidry/console": "^0.5.0", + "fidry/console": "^0.5.0 || ^0.6.0", + "fidry/filesystem": "^1.1", "jetbrains/phpstorm-stubs": "^v2022.2", "nikic/php-parser": "^4.12", "symfony/console": "^5.2 || ^6.0", "symfony/filesystem": "^5.2 || ^6.0", "symfony/finder": "^5.2 || ^6.0", - "thecodingmachine/safe": "^1.3 || ^2.0" + "thecodingmachine/safe": "^2.0" }, "require-dev": { "bamarni/composer-bin-plugin": "^1.1", diff --git a/composer.lock b/composer.lock index 50d8de1e4..be04dc352 100644 --- a/composer.lock +++ b/composer.lock @@ -4,48 +4,48 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "dcd68062c3ca5bcf7fa8494490081303", + "content-hash": "3a91c4aeab38b553f08275f378b3b1f3", "packages": [ { "name": "fidry/console", - "version": "0.5.5", + "version": "0.6.0", "source": { "type": "git", "url": "https://github.com/theofidry/console.git", - "reference": "bc1fe03f600c63f12ec0a39c6b746c1a1fb77bf7" + "reference": "7203f6aafc5b7203e6f1bf0df17593ba4159a276" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/theofidry/console/zipball/bc1fe03f600c63f12ec0a39c6b746c1a1fb77bf7", - "reference": "bc1fe03f600c63f12ec0a39c6b746c1a1fb77bf7", + "url": "https://api.github.com/repos/theofidry/console/zipball/7203f6aafc5b7203e6f1bf0df17593ba4159a276", + "reference": "7203f6aafc5b7203e6f1bf0df17593ba4159a276", "shasum": "" }, "require": { - "php": "^7.4.0 || ^8.0.0", - "symfony/console": "^4.4 || ^5.4 || ^6.1", - "symfony/event-dispatcher-contracts": "^1.0 || ^2.5 || ^3.0", - "symfony/service-contracts": "^1.0 || ^2.5 || ^3.0", - "thecodingmachine/safe": "^1.3 || ^2.0", + "php": "^8.1", + "symfony/console": "^5.4 || ^6.3", + "symfony/event-dispatcher-contracts": "^2.5 || ^3.0", + "symfony/service-contracts": "^2.5 || ^3.0", + "thecodingmachine/safe": "^2.0", "webmozart/assert": "^1.11" }, "conflict": { - "symfony/dependency-injection": "<5.3.0", - "symfony/framework-bundle": "<5.3.0", - "symfony/http-kernel": "<5.3.0" + "symfony/dependency-injection": "<5.4.0 || >=6.0.0 <6.1.0", + "symfony/framework-bundle": "<5.4.0 || >=6.0.0 <6.1.0", + "symfony/http-kernel": "<5.4.0 || >=6.0.0 <6.1.0" }, "require-dev": { - "bamarni/composer-bin-plugin": "^1.4", - "composer/semver": "^3.3", - "ergebnis/composer-normalize": "^2.28", - "infection/infection": "^0.26", + "bamarni/composer-bin-plugin": "^1.8.2", + "composer/semver": "^3.3.2", + "ergebnis/composer-normalize": "^2.33", + "fidry/makefile": "^0.2.1", + "infection/infection": "^0.27", "phpspec/prophecy-phpunit": "^2.0", - "phpunit/phpunit": "^9.4.3", - "symfony/dependency-injection": "^4.4 || ^5.4 || ^6.1", - "symfony/framework-bundle": "^4.4 || ^5.4 || ^6.1", - "symfony/http-kernel": "^4.4 || ^5.4 || ^6.1", - "symfony/phpunit-bridge": "^4.4.47 || ^5.4 || ^6.0", - "symfony/yaml": "^4.4 || ^5.4 || ^6.1", - "webmozarts/strict-phpunit": "^7.3" + "phpunit/phpunit": "^10.2", + "symfony/dependency-injection": "^5.4 || ^6.1", + "symfony/flex": "^2.3.1", + "symfony/framework-bundle": "^5.4 || ^6.1", + "symfony/http-kernel": "^5.4 || ^6.1", + "symfony/yaml": "^5.4 || ^6.1" }, "type": "library", "extra": { @@ -80,7 +80,76 @@ ], "support": { "issues": "https://github.com/theofidry/console/issues", - "source": "https://github.com/theofidry/console/tree/0.5.5" + "source": "https://github.com/theofidry/console/tree/0.6.0" + }, + "funding": [ + { + "url": "https://github.com/theofidry", + "type": "github" + } + ], + "time": "2023-09-24T20:12:42+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": [ { @@ -88,7 +157,7 @@ "type": "github" } ], - "time": "2022-12-18T10:49:34+00:00" + "time": "2023-10-07T07:32:54+00:00" }, { "name": "jetbrains/phpstorm-stubs", @@ -2709,75 +2778,6 @@ }, "time": "2023-10-10T14:16:57+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": "fidry/makefile", "version": "0.2.3", diff --git a/src/Autoload/ScoperAutoloadGenerator.php b/src/Autoload/ScoperAutoloadGenerator.php index f2b01aa76..6b4c1e794 100644 --- a/src/Autoload/ScoperAutoloadGenerator.php +++ b/src/Autoload/ScoperAutoloadGenerator.php @@ -217,7 +217,7 @@ private static function createClassAliasStatement( * * @return list */ - private static function wrapStatementsInNamespaceBlock(string $namespace, string|array $statements): array + private static function wrapStatementsInNamespaceBlock(string $namespace, array|string $statements): array { if (is_string($statements)) { $statements = explode(self::$eol, $statements); diff --git a/src/Configuration/Configuration.php b/src/Configuration/Configuration.php index cbd1cb505..4ad285aa9 100644 --- a/src/Configuration/Configuration.php +++ b/src/Configuration/Configuration.php @@ -29,15 +29,15 @@ final class Configuration private readonly string $prefix; /** - * @param non-empty-string|null $path Absolute canonical path to the configuration file loaded. - * @param non-empty-string|null $outputDir Absolute canonical path to the output directory. - * @param non-empty-string $prefix The prefix applied. - * @param array $filesWithContents Array of tuple with the - * first argument being the file path and the second - * its contents + * @param non-empty-string|null $path Absolute canonical path to the configuration file loaded. + * @param non-empty-string|null $outputDir Absolute canonical path to the output directory. + * @param non-empty-string $prefix The prefix applied. + * @param array $filesWithContents Array of tuple with the + * first argument being the file path and the second + * its contents * @param array $excludedFilesWithContents Array of tuple - * with the first argument being the file path and - * the second its contents + * with the first argument being the file path and + * the second its contents */ public function __construct( private ?string $path, diff --git a/src/Scoper/Composer/AutoloadPrefixer.php b/src/Scoper/Composer/AutoloadPrefixer.php index 5c9fa0a9c..74afc85b6 100644 --- a/src/Scoper/Composer/AutoloadPrefixer.php +++ b/src/Scoper/Composer/AutoloadPrefixer.php @@ -133,7 +133,7 @@ private static function prefixAutoload( /** * @param array $psr0 * @param (string|string[])[] $psr4 - * @param string[] $classMap + * @param string[] $classMap */ private static function transformPsr0ToPsr4AndClassmap(array $psr0, array $psr4, array $classMap): array { @@ -168,7 +168,7 @@ private static function transformPsr0ToPsr4AndClassmap(array $psr0, array $psr4, * * @return string|string[] */ - private static function updatePSR0Path(string|array $path, string $namespace): string|array + private static function updatePSR0Path(array|string $path, string $namespace): array|string { $namespaceForPsr = rtrim( str_replace('\\', '/', $namespace), @@ -204,12 +204,12 @@ private static function updatePSR0Path(string|array $path, string $namespace): s * string | * or simply the namespace not existing as a psr-4 entry. * - * @param string|string[] $psr0Path + * @param string|string[] $psr0Path * @param (string|string[])[] $psr4 * * @return string|string[] */ - private static function mergeNamespaces(string $psr0Namespace, string|array $psr0Path, array $psr4): string|array + private static function mergeNamespaces(string $psr0Namespace, array|string $psr0Path, array $psr4): array|string { // Both strings if (is_string($psr0Path) && is_string($psr4[$psr0Namespace])) { diff --git a/tests/Configuration/ConfigurationFactoryTest.php b/tests/Configuration/ConfigurationFactoryTest.php index 968e91b91..4ce49f11c 100644 --- a/tests/Configuration/ConfigurationFactoryTest.php +++ b/tests/Configuration/ConfigurationFactoryTest.php @@ -14,6 +14,7 @@ namespace Humbug\PhpScoper\Configuration; +use Fidry\FileSystem\FS; use Humbug\PhpScoper\Container; use Humbug\PhpScoper\FileSystemTestCase; use Humbug\PhpScoper\Patcher\ComposerPatcher; @@ -24,7 +25,6 @@ use Humbug\PhpScoper\Symbol\SymbolRegistry; use InvalidArgumentException; use function array_keys; -use function KevinGH\Box\FileSystem\dump_file; use function Safe\touch; use const DIRECTORY_SEPARATOR; @@ -168,7 +168,7 @@ public function test_it_can_create_a_complete_configuration(): void private static function dumpStandardConfigFile(string $contents): void { - dump_file('scoper.inc.php', $contents); + FS::dumpFile('scoper.inc.php', $contents); } private function createConfigFromStandardFile(): Configuration diff --git a/tests/Console/Command/AddPrefixCommandIntegrationTest.php b/tests/Console/Command/AddPrefixCommandIntegrationTest.php index 92bcd3da2..356ad4226 100644 --- a/tests/Console/Command/AddPrefixCommandIntegrationTest.php +++ b/tests/Console/Command/AddPrefixCommandIntegrationTest.php @@ -286,6 +286,7 @@ public function test_scope_in_very_verbose_mode(): void $extraDisplayNormalization = static function (string $display): string { $display = preg_replace('/(Could not parse the file ".+?"\.: \w+).*(\n)/', '$1$2', $display); $display = preg_replace('/(#\d+).*(\n)/', '$1$2', $display); + // Remove overly lengthy stack-trace return preg_replace('/(Stack trace:(?:\n\#\d)+)\n?((?:\n\#\d{2,})+)/', '$1', $display); }; diff --git a/tests/Console/Command/AddPrefixCommandTest.php b/tests/Console/Command/AddPrefixCommandTest.php index 0e0413971..4d5b8f5dc 100644 --- a/tests/Console/Command/AddPrefixCommandTest.php +++ b/tests/Console/Command/AddPrefixCommandTest.php @@ -16,6 +16,7 @@ use Fidry\Console\Application\SymfonyApplication; use Fidry\Console\Command\SymfonyCommand; +use Fidry\FileSystem\FS; use Humbug\PhpScoper\Configuration\ConfigurationFactory; use Humbug\PhpScoper\Configuration\RegexChecker; use Humbug\PhpScoper\Configuration\SymbolsConfigurationFactory; @@ -38,7 +39,6 @@ use Symfony\Component\Console\Tester\ApplicationTester; use Symfony\Component\Filesystem\Filesystem; use function count; -use function Humbug\PhpScoper\escape_path; use function Safe\chdir; use function Safe\file_get_contents; use function Safe\realpath; @@ -121,8 +121,8 @@ public function test_scope_the_given_paths(): void ->shouldBeCalled(); foreach ($expectedFiles as $expectedFile => $prefixedContents) { - $inputPath = escape_path($root.'/'.$expectedFile); - $outputPath = escape_path($this->tmp.'/'.$expectedFile); + $inputPath = FS::escapePath($root.'/'.$expectedFile); + $outputPath = FS::escapePath($this->tmp.'/'.$expectedFile); $inputContents = file_get_contents($inputPath); @@ -183,8 +183,8 @@ public function test_let_the_file_unchanged_when_cannot_scope_a_file(): void ->shouldBeCalled(); foreach ($expectedFiles as $expectedFile => $prefixedContents) { - $inputPath = escape_path($root.'/'.$expectedFile); - $outputPath = escape_path($this->tmp.'/'.$expectedFile); + $inputPath = FS::escapePath($root.'/'.$expectedFile); + $outputPath = FS::escapePath($this->tmp.'/'.$expectedFile); $inputContents = file_get_contents($inputPath); @@ -239,8 +239,8 @@ public function test_do_not_scope_duplicated_given_paths(): void ]; foreach ($expectedFiles as $expectedFile => $prefixedContents) { - $inputPath = escape_path($root.'/'.$expectedFile); - $outputPath = escape_path($this->tmp.'/'.$expectedFile); + $inputPath = FS::escapePath($root.'/'.$expectedFile); + $outputPath = FS::escapePath($this->tmp.'/'.$expectedFile); $inputContents = file_get_contents($inputPath); @@ -262,7 +262,7 @@ public function test_do_not_scope_duplicated_given_paths(): void public function test_scope_the_given_paths_and_the_ones_found_by_the_finder(): void { - chdir($rootPath = escape_path(self::FIXTURE_PATH.'/set012')); + chdir($rootPath = FS::escapePath(self::FIXTURE_PATH.'/set012')); $input = [ 'add-prefix', @@ -289,7 +289,7 @@ public function test_scope_the_given_paths_and_the_ones_found_by_the_finder(): v foreach ($expectedFiles as $inputPath => $outputPath) { $inputPath = realpath($inputPath); - $outputPath = escape_path($outputPath); + $outputPath = FS::escapePath($outputPath); $inputContents = file_get_contents($inputPath); $prefixedFileContents = 'Random string'; @@ -347,8 +347,8 @@ public function test_scope_the_current_working_directory_if_no_path_given(): voi ->shouldBeCalled(); foreach ($expectedFiles as $expectedFile => $prefixedContents) { - $inputPath = escape_path($root.'/'.$expectedFile); - $outputPath = escape_path($this->tmp.'/'.$expectedFile); + $inputPath = FS::escapePath($root.'/'.$expectedFile); + $outputPath = FS::escapePath($this->tmp.'/'.$expectedFile); $inputContents = file_get_contents($inputPath); @@ -405,8 +405,8 @@ public function test_an_output_directory_can_be_given(): void ->shouldBeCalled(); foreach ($expectedFiles as $expectedFile => $prefixedContents) { - $inputPath = escape_path($root.'/'.$expectedFile); - $outputPath = escape_path($outDir.'/'.$expectedFile); + $inputPath = FS::escapePath($root.'/'.$expectedFile); + $outputPath = FS::escapePath($outDir.'/'.$expectedFile); $inputContents = file_get_contents($inputPath); @@ -464,8 +464,8 @@ public function test_relative_output_directory_are_made_absolute(): void ->shouldBeCalled(); foreach ($expectedFiles as $expectedFile => $prefixedContents) { - $inputPath = escape_path($root.'/'.$expectedFile); - $outputPath = escape_path($this->tmp.DIRECTORY_SEPARATOR.$outDir.'/'.$expectedFile); + $inputPath = FS::escapePath($root.'/'.$expectedFile); + $outputPath = FS::escapePath($this->tmp.DIRECTORY_SEPARATOR.$outDir.'/'.$expectedFile); $inputContents = file_get_contents($inputPath); @@ -520,7 +520,7 @@ public function test_throws_an_error_when_passing_a_non_existent_config(): void public function test_throws_an_error_if_patch_file_returns_an_array_with_invalid_values(): void { - chdir(escape_path(self::FIXTURE_PATH.'/set009')); + chdir(FS::escapePath(self::FIXTURE_PATH.'/set009')); $input = [ 'add-prefix', @@ -551,7 +551,7 @@ public function test_throws_an_error_if_patch_file_returns_an_array_with_invalid public function test_can_scope_projects_with_invalid_files(): void { - chdir(escape_path($root = self::FIXTURE_PATH.'/set010')); + chdir(FS::escapePath($root = self::FIXTURE_PATH.'/set010')); $input = [ 'add-prefix', @@ -575,8 +575,8 @@ public function test_can_scope_projects_with_invalid_files(): void $root = realpath($root); foreach ($expectedFiles as $expectedFile => $prefixedContents) { - $inputPath = escape_path($root.'/'.$expectedFile); - $outputPath = escape_path($this->tmp.'/'.$expectedFile); + $inputPath = FS::escapePath($root.'/'.$expectedFile); + $outputPath = FS::escapePath($this->tmp.'/'.$expectedFile); $fileContents = file_get_contents($inputPath); @@ -635,8 +635,8 @@ public function test_it_outputs_in_the_build_directory_if_no_output_dir_is_given ->shouldBeCalled(); foreach ($expectedFiles as $expectedFile => $prefixedContents) { - $inputPath = escape_path($root.'/'.$expectedFile); - $outputPath = escape_path($this->tmp.DIRECTORY_SEPARATOR.$outDir.'/'.$expectedFile); + $inputPath = FS::escapePath($root.'/'.$expectedFile); + $outputPath = FS::escapePath($this->tmp.DIRECTORY_SEPARATOR.$outDir.'/'.$expectedFile); $inputContents = file_get_contents($inputPath); diff --git a/tests/FileSystemTestCase.php b/tests/FileSystemTestCase.php index b31b92805..a4808562c 100644 --- a/tests/FileSystemTestCase.php +++ b/tests/FileSystemTestCase.php @@ -14,39 +14,12 @@ namespace Humbug\PhpScoper; -use PHPUnit\Framework\TestCase; -use function Safe\chdir; -use function Safe\getcwd; -use function Safe\realpath; -use function str_replace; -use function sys_get_temp_dir; +use Fidry\FileSystem\Test\FileSystemTestCase as FidryFileSystemTestCase; -abstract class FileSystemTestCase extends TestCase +abstract class FileSystemTestCase extends FidryFileSystemTestCase { - protected string $cwd; - - protected string $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_dir(str_replace('\\', '/', realpath(sys_get_temp_dir())).'/php-scoper'); - - $this->cwd = getcwd(); - $this->tmp = make_tmp_dir('php-scoper', self::class); - - chdir($this->tmp); - } - - protected function tearDown(): void + public static function getTmpDirNamespace(): string { - parent::tearDown(); - - chdir($this->cwd); - - remove_dir($this->tmp); + return 'PHP-Scoper'; } } diff --git a/tests/FunctionsTest.php b/tests/FunctionsTest.php index 3d1d14d51..8f7171796 100644 --- a/tests/FunctionsTest.php +++ b/tests/FunctionsTest.php @@ -88,10 +88,14 @@ public static function provideGenerators(): iterable yield [ [ (static function (): Generator { - yield from ['a' => 'alpha', 'b' => 'beta', 2 => 'two']; + yield 'a' => 'alpha'; + yield 'b' => 'beta'; + yield 2 => 'two'; })(), (static function (): Generator { - yield from [0, 1, 2]; + yield 0; + yield 1; + yield 2; })(), ], [ diff --git a/tests/Scoper/PhpScoperSpecTest.php b/tests/Scoper/PhpScoperSpecTest.php index ff5af1b86..164a90cc5 100644 --- a/tests/Scoper/PhpScoperSpecTest.php +++ b/tests/Scoper/PhpScoperSpecTest.php @@ -300,7 +300,7 @@ private static function createScoper( ); } - private static function parseSpecFile(string $file, array $meta, string|int $fixtureTitle, string|array $fixtureSet): iterable + private static function parseSpecFile(string $file, array $meta, int|string $fixtureTitle, array|string $fixtureSet): iterable { static $specMetaKeys; static $specKeys; @@ -377,7 +377,7 @@ private static function parseSpecFile(string $file, array $meta, string|int $fix private static function createSymbolsConfiguration( string $file, - string|array $fixtureSet, + array|string $fixtureSet, array $meta ): SymbolsConfiguration { if (is_string($fixtureSet)) { diff --git a/tests/Symbol/SymbolsRegistryTest.php b/tests/Symbol/SymbolsRegistryTest.php index 7009dcb16..f9bb04b88 100644 --- a/tests/Symbol/SymbolsRegistryTest.php +++ b/tests/Symbol/SymbolsRegistryTest.php @@ -30,8 +30,8 @@ final class SymbolsRegistryTest extends TestCase * * @param array $functions * @param array $classes - * @param list $expectedRecordedFunctions - * @param list $expectedRecordedClasses + * @param list $expectedRecordedFunctions + * @param list $expectedRecordedClasses */ public function test_it_records_functions_and_classes( array $functions, diff --git a/tests/functions.php b/tests/functions.php index 17ffb9260..94e4fec21 100644 --- a/tests/functions.php +++ b/tests/functions.php @@ -15,72 +15,6 @@ namespace Humbug\PhpScoper; use PhpParser\Parser; -use RuntimeException; -use Symfony\Component\Filesystem\Filesystem; -use function mkdir as native_mkdir; -use function Safe\realpath; -use function sprintf; -use function str_replace; -use function strrpos; -use function substr; -use function sys_get_temp_dir; -use const DIRECTORY_SEPARATOR; - -/** - * 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. - */ -function make_tmp_dir(string $namespace, string $className): string -{ - if (false !== ($pos = strrpos($className, '\\'))) { - $shortClass = 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; - - $i = 0; - - while (false === @native_mkdir($tempDir = escape_path($basePath.random_int(10000, 99999)), 0o777, true)) { - // Run until we are able to create a directory - if ($i > 100) { - throw new RuntimeException( - sprintf( - 'Could not create temporary directory for "%s:%s" after 100 attempts', - $namespace, - $className, - ), - ); - } - - ++$i; - } - - return $tempDir; -} - -function escape_path(string $path): string -{ - return str_replace('/', DIRECTORY_SEPARATOR, $path); -} - -function remove_dir(string $path): void -{ - $path = escape_path($path); - - (new Filesystem())->remove($path); -} /** * @private diff --git a/vendor-bin/php-cs-fixer/composer.json b/vendor-bin/php-cs-fixer/composer.json index a88a56c8a..5fe23739f 100644 --- a/vendor-bin/php-cs-fixer/composer.json +++ b/vendor-bin/php-cs-fixer/composer.json @@ -1,6 +1,6 @@ { "require-dev": { "friendsofphp/php-cs-fixer": "^3.12", - "theofidry/php-cs-fixer-config": "^1.0" + "fidry/php-cs-fixer-config": "^1.0" } } diff --git a/vendor-bin/php-cs-fixer/composer.lock b/vendor-bin/php-cs-fixer/composer.lock index bf21ed0c5..46a6b9468 100644 --- a/vendor-bin/php-cs-fixer/composer.lock +++ b/vendor-bin/php-cs-fixer/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": "38beeb771ff7647b6b3202b50bdefebf", + "content-hash": "f2c6f30e9e818a2b9269bc287dbd5183", "packages": [], "packages-dev": [ { @@ -225,6 +225,56 @@ ], "time": "2022-02-25T21:32:43+00:00" }, + { + "name": "fidry/php-cs-fixer-config", + "version": "1.1.3", + "source": { + "type": "git", + "url": "https://github.com/theofidry/php-cs-fixer-config.git", + "reference": "1a8730ed7e28f7eab456843544a8e1a337253175" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/theofidry/php-cs-fixer-config/zipball/1a8730ed7e28f7eab456843544a8e1a337253175", + "reference": "1a8730ed7e28f7eab456843544a8e1a337253175", + "shasum": "" + }, + "require": { + "php": "^7.2 || ^8.0" + }, + "conflict": { + "friendsofphp/php-cs-fixer": "<3.19.0,>=4.0" + }, + "require-dev": { + "ergebnis/composer-normalize": "~2.13.0", + "fidry/makefile": "^0.2.1", + "friendsofphp/php-cs-fixer": "^3.19.0", + "phpunit/phpunit": "^9.4.3", + "symfony/filesystem": "^5.4 || ^6.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Fidry\\PhpCsFixerConfig\\": "src" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Théo FIDRY", + "email": "theo.fidry@gmail.com" + } + ], + "description": "The PHP-CS-Fixer default config for my projects", + "support": { + "issues": "https://github.com/theofidry/php-cs-fixer-config/issues", + "source": "https://github.com/theofidry/php-cs-fixer-config/tree/1.1.3" + }, + "time": "2023-09-17T21:19:26+00:00" + }, { "name": "friendsofphp/php-cs-fixer", "version": "v3.35.1", @@ -1827,57 +1877,6 @@ } ], "time": "2023-09-18T10:38:32+00:00" - }, - { - "name": "theofidry/php-cs-fixer-config", - "version": "1.1.3", - "source": { - "type": "git", - "url": "https://github.com/theofidry/php-cs-fixer-config.git", - "reference": "1a8730ed7e28f7eab456843544a8e1a337253175" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/theofidry/php-cs-fixer-config/zipball/1a8730ed7e28f7eab456843544a8e1a337253175", - "reference": "1a8730ed7e28f7eab456843544a8e1a337253175", - "shasum": "" - }, - "require": { - "php": "^7.2 || ^8.0" - }, - "conflict": { - "friendsofphp/php-cs-fixer": "<3.19.0,>=4.0" - }, - "require-dev": { - "ergebnis/composer-normalize": "~2.13.0", - "fidry/makefile": "^0.2.1", - "friendsofphp/php-cs-fixer": "^3.19.0", - "phpunit/phpunit": "^9.4.3", - "symfony/filesystem": "^5.4 || ^6.1" - }, - "type": "library", - "autoload": { - "psr-4": { - "Fidry\\PhpCsFixerConfig\\": "src" - } - }, - "notification-url": "https://packagist.org/downloads/", - "license": [ - "MIT" - ], - "authors": [ - { - "name": "Théo FIDRY", - "email": "theo.fidry@gmail.com" - } - ], - "description": "The PHP-CS-Fixer default config for my projects", - "support": { - "issues": "https://github.com/theofidry/php-cs-fixer-config/issues", - "source": "https://github.com/theofidry/php-cs-fixer-config/tree/1.1.3" - }, - "abandoned": "fidry/php-cs-fixer-config", - "time": "2023-09-17T21:19:26+00:00" } ], "aliases": [],