From 73dc8070d72d165647ed1985d56fd76e9506d94a Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Fri, 15 Mar 2024 08:10:50 +0400 Subject: [PATCH 1/6] Added `composer-dependency-analyser`. --- composer.json | 8 +- .../composer.json | 5 ++ .../composer.lock | 84 +++++++++++++++++++ 3 files changed, 95 insertions(+), 2 deletions(-) create mode 100644 vendor-bin/composer-dependency-analyser/composer.json create mode 100644 vendor-bin/composer-dependency-analyser/composer.lock diff --git a/composer.json b/composer.json index 6f2bab823..d69d3ad18 100644 --- a/composer.json +++ b/composer.json @@ -166,8 +166,9 @@ ], "validate:dependencies": [ "@monorepo-builder", - "@composer-unused", - "@composer-require-checker" + "@composer-dependency-analyser", + "@composer-require-checker", + "@composer-unused" ], "phpstan": [ "./vendor-bin/phpstan/vendor/bin/phpstan analyse" @@ -187,6 +188,9 @@ "composer-require-checker": [ "./vendor-bin/composer-require-checker/vendor/bin/composer-require-checker check" ], + "composer-dependency-analyser": [ + "vendor-bin/composer-dependency-analyser/vendor/bin/composer-dependency-analyser --verbose" + ], "monorepo-builder": [ "./vendor-bin/monorepo-builder/vendor/bin/monorepo-builder validate" ], diff --git a/vendor-bin/composer-dependency-analyser/composer.json b/vendor-bin/composer-dependency-analyser/composer.json new file mode 100644 index 000000000..012b4c23c --- /dev/null +++ b/vendor-bin/composer-dependency-analyser/composer.json @@ -0,0 +1,5 @@ +{ + "require-dev": { + "shipmonk/composer-dependency-analyser": "dev-master" + } +} diff --git a/vendor-bin/composer-dependency-analyser/composer.lock b/vendor-bin/composer-dependency-analyser/composer.lock new file mode 100644 index 000000000..faa8fcfbd --- /dev/null +++ b/vendor-bin/composer-dependency-analyser/composer.lock @@ -0,0 +1,84 @@ +{ + "_readme": [ + "This file locks the dependencies of your project to a known state", + "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", + "This file is @generated automatically" + ], + "content-hash": "e2204491a6b7d5bd80c4b4c41f20dc20", + "packages": [], + "packages-dev": [ + { + "name": "shipmonk/composer-dependency-analyser", + "version": "dev-master", + "source": { + "type": "git", + "url": "https://github.com/shipmonk-rnd/composer-dependency-analyser.git", + "reference": "ddf83da43a3d7a0db546842682f4cca3f6d76807" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/shipmonk-rnd/composer-dependency-analyser/zipball/ddf83da43a3d7a0db546842682f4cca3f6d76807", + "reference": "ddf83da43a3d7a0db546842682f4cca3f6d76807", + "shasum": "" + }, + "require": { + "ext-json": "*", + "php": "^7.2 || ^8.0" + }, + "require-dev": { + "editorconfig-checker/editorconfig-checker": "^10.3.0", + "ergebnis/composer-normalize": "^2.19", + "phpstan/phpstan": "^1.10.30", + "phpstan/phpstan-phpunit": "^1.1.1", + "phpstan/phpstan-strict-rules": "^1.2.3", + "phpunit/phpunit": "^8.5.28 || ^9.5.20", + "shipmonk/name-collision-detector": "^2.0.0", + "slevomat/coding-standard": "^8.0.1" + }, + "default-branch": true, + "bin": [ + "bin/composer-dependency-analyser" + ], + "type": "library", + "autoload": { + "psr-4": { + "ShipMonk\\ComposerDependencyAnalyser\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "Fast detection of composer dependency issues (dead dependencies, shadow dependencies, misplaced dependencies)", + "keywords": [ + "analyser", + "composer", + "composer dependency", + "dead code", + "dead dependency", + "detector", + "dev", + "misplaced dependency", + "shadow dependency", + "static analysis", + "unused code", + "unused dependency" + ], + "support": { + "issues": "https://github.com/shipmonk-rnd/composer-dependency-analyser/issues", + "source": "https://github.com/shipmonk-rnd/composer-dependency-analyser/tree/master" + }, + "time": "2024-03-15T15:20:59+00:00" + } + ], + "aliases": [], + "minimum-stability": "stable", + "stability-flags": { + "shipmonk/composer-dependency-analyser": 20 + }, + "prefer-stable": false, + "prefer-lowest": false, + "platform": [], + "platform-dev": [], + "plugin-api-version": "2.6.0" +} From ffe976509f5aa8a20c7e2708871e1a47d967b1e3 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Fri, 15 Mar 2024 08:16:45 +0400 Subject: [PATCH 2/6] Added to `ci.yml`. --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index de1d64d78..fa406ab92 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -30,6 +30,9 @@ jobs: - name: Check package versions run: | composer run-script monorepo-builder + - name: Check dependencies + run: | + composer run-script composer-dependency-analyser - name: Check packages run: | composer run-script composer-require-checker @@ -66,6 +69,9 @@ jobs: uses: ramsey/composer-install@v2 with: working-directory: ${{ needs.settings.outputs.packages-directory }}/${{ matrix.package }} + - name: Check dependencies + run: | + composer run-script composer-dependency-analyser -- --composer-json="${{ needs.settings.outputs.packages-directory }}/${{ matrix.package }}/composer.json" - name: Check packages run: | composer run-script composer-require-checker -- "${{ needs.settings.outputs.packages-directory }}/${{ matrix.package }}/composer.json" From 312ad580c6117264e662812968499a34da329919 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Fri, 15 Mar 2024 08:21:10 +0400 Subject: [PATCH 3/6] Dev `App` fix. --- dev/App/App.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/dev/App/App.php b/dev/App/App.php index a37d83881..38d44d597 100644 --- a/dev/App/App.php +++ b/dev/App/App.php @@ -7,7 +7,6 @@ use Illuminate\Foundation\Application; use Illuminate\Foundation\Console\Kernel as ConsoleKernel; use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler; -use Laravel\Prompts\Output\ConsoleOutput; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; @@ -38,7 +37,7 @@ public static function run(InputInterface $input, OutputInterface $output = null $app = static::create(); $kernel = $app->make(ConsoleKernelContract::class); - $status = $kernel->handle($input, $output ?? new ConsoleOutput()); + $status = $kernel->handle($input, $output); $kernel->terminate($input, $status); From 77847df1db3023ca26cf9e2385588b859d511be6 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Fri, 15 Mar 2024 10:25:47 +0400 Subject: [PATCH 4/6] General configuration. --- composer-dependency-analyser.php | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 composer-dependency-analyser.php diff --git a/composer-dependency-analyser.php b/composer-dependency-analyser.php new file mode 100644 index 000000000..f0220f76b --- /dev/null +++ b/composer-dependency-analyser.php @@ -0,0 +1,18 @@ +enableAnalysisOfUnusedDevDependencies() + ->disableReportingUnmatchedIgnores() + ->ignoreUnknownClasses([ + Example::class, + ]) + ->ignoreErrorsOnPackage('symfony/polyfill-php83', [ErrorType::UNUSED_DEPENDENCY]) + ->ignoreErrorsOnPackage('bamarni/composer-bin-plugin', [ErrorType::UNUSED_DEPENDENCY]) + ->ignoreErrorsOnPackage('orchestra/testbench', [ErrorType::UNUSED_DEPENDENCY]) + ->ignoreErrorsOnPackage('orchestra/testbench-core', [ErrorType::SHADOW_DEPENDENCY]) + ->ignoreErrorsOnPackage('phpstan/phpstan', [ErrorType::SHADOW_DEPENDENCY]) + ->ignoreErrorsOnPackage('laravel/scout', [ErrorType::DEV_DEPENDENCY_IN_PROD]); From a6221b2adb2ed719a98161c37dd538f527e8a3e1 Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Fri, 15 Mar 2024 11:21:09 +0400 Subject: [PATCH 5/6] `*Test.php` will be treatment as a "dev" paths. --- composer-dependency-analyser.php | 60 +++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) diff --git a/composer-dependency-analyser.php b/composer-dependency-analyser.php index f0220f76b..81ae3ef2b 100644 --- a/composer-dependency-analyser.php +++ b/composer-dependency-analyser.php @@ -1,10 +1,20 @@ enableAnalysisOfUnusedDevDependencies() ->disableReportingUnmatchedIgnores() ->ignoreUnknownClasses([ @@ -16,3 +26,51 @@ ->ignoreErrorsOnPackage('orchestra/testbench-core', [ErrorType::SHADOW_DEPENDENCY]) ->ignoreErrorsOnPackage('phpstan/phpstan', [ErrorType::SHADOW_DEPENDENCY]) ->ignoreErrorsOnPackage('laravel/scout', [ErrorType::DEV_DEPENDENCY_IN_PROD]); + +// Configure paths +// +// In our case, tests located inside the same directory with class and +// `exclude-from-classmap` is used to exclude them from the class map. +// So we need to mark these excluded files as "dev". +$path = Path::resolve($this->cwd, ($options->composerJson ?? 'composer.json')); +$json = (string) file_get_contents($path); +$json = json_decode($json, true, JSON_THROW_ON_ERROR); +$excluded = $json['autoload']['exclude-from-classmap'] ?? []; + +if ($excluded) { + $config = $config->disableComposerAutoloadPathScan(); + $regexp = array_map( + static function (string $exclude) use ($path): string { + // Similar to how composer process it, but not the exact match. + $exclude = dirname($path)."/{$exclude}"; + $exclude = preg_replace('{/+}', '/', preg_quote(trim(strtr($exclude, '\\', '/'), '/'))); + $exclude = strtr($exclude, ['\\*\\*' => '.+?', '\\*' => '[^/]+?']); + + return $exclude; + }, + $excluded, + ); + $regexp = '{('.implode(')|(', $regexp).')}'; + + foreach ($composerJson->autoloadPaths as $absolutePath => $isDevPath) { + if ($isDevPath) { + $config = $config->addPathToScan($absolutePath, $isDevPath); + } elseif (is_file($absolutePath)) { + $config = $config->addPathToScan($absolutePath, (bool) preg_match($regexp, $absolutePath)); + } else { + $iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($absolutePath)); + + foreach ($iterator as $entry) { + if (!$entry->isFile() || !in_array($entry->getExtension(), $config->getFileExtensions(), true)) { + continue; + } + + $entryPath = $entry->getPathname(); + $config = $config->addPathToScan($entryPath, (bool) preg_match($regexp, $entryPath)); + } + } + } +} + +// Return +return $config; From 98bd58b0039d6d5c8f3724edd68438195b9a872b Mon Sep 17 00:00:00 2001 From: Aleksei Lebedev <1329824+LastDragon-ru@users.noreply.github.com> Date: Fri, 15 Mar 2024 15:37:58 +0400 Subject: [PATCH 6/6] Dependencies fix. --- packages/core/composer.json | 1 + packages/documentator/composer.json | 1 + packages/eloquent/composer.json | 1 + packages/migrator/composer.json | 2 +- packages/serializer/composer.json | 1 + packages/spa/composer.json | 2 +- packages/testing/composer.json | 4 +++- .../testing/docs/Assertions/AssertScoutQueryEqualsTest.php | 4 ++-- 8 files changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/core/composer.json b/packages/core/composer.json index 17f9d7a69..34c2f7d9f 100644 --- a/packages/core/composer.json +++ b/packages/core/composer.json @@ -26,6 +26,7 @@ "require-dev": { "phpunit/phpunit": "^10.1.0", "lastdragon-ru/lara-asp-testing": "self.version", + "mockery/mockery": "^1.6.2", "orchestra/testbench": "^8.0.0" }, "autoload": { diff --git a/packages/documentator/composer.json b/packages/documentator/composer.json index 640c6b30d..b9d0af749 100644 --- a/packages/documentator/composer.json +++ b/packages/documentator/composer.json @@ -35,6 +35,7 @@ }, "require-dev": { "lastdragon-ru/lara-asp-testing": "self.version", + "mockery/mockery": "^1.6.2", "orchestra/testbench": "^8.0.0", "phpunit/phpunit": "^10.1.0" }, diff --git a/packages/eloquent/composer.json b/packages/eloquent/composer.json index 0a93a63e8..af242d027 100644 --- a/packages/eloquent/composer.json +++ b/packages/eloquent/composer.json @@ -25,6 +25,7 @@ "require-dev": { "ext-pdo_sqlite": "*", "lastdragon-ru/lara-asp-testing": "self.version", + "mockery/mockery": "^1.6.2", "orchestra/testbench": "^8.0.0", "phpunit/phpunit": "^10.1.0" }, diff --git a/packages/migrator/composer.json b/packages/migrator/composer.json index 1482b5ee4..d60ee22a5 100644 --- a/packages/migrator/composer.json +++ b/packages/migrator/composer.json @@ -24,7 +24,7 @@ "ext-json": "*", "laravel/framework": "^10.34.0", "lastdragon-ru/lara-asp-core": "self.version", - "symfony/filesystem": "^6.3.0", + "symfony/console": "^6.3.0", "symfony/finder": "^6.3.0", "symfony/polyfill-php83": "^1.28" }, diff --git a/packages/serializer/composer.json b/packages/serializer/composer.json index b9b513cd0..4b824fcbb 100644 --- a/packages/serializer/composer.json +++ b/packages/serializer/composer.json @@ -29,6 +29,7 @@ }, "require-dev": { "lastdragon-ru/lara-asp-testing": "self.version", + "mockery/mockery": "^1.6.2", "orchestra/testbench": "^8.0.0", "phpunit/phpunit": "^10.1.0" }, diff --git a/packages/spa/composer.json b/packages/spa/composer.json index 1b3bb138d..6ec5f73d7 100644 --- a/packages/spa/composer.json +++ b/packages/spa/composer.json @@ -29,7 +29,7 @@ "require-dev": { "phpunit/phpunit": "^10.1.0", "lastdragon-ru/lara-asp-testing": "self.version", - "symfony/filesystem": "^6.3.0", + "mockery/mockery": "^1.6.2", "orchestra/testbench": "^8.0.0" }, "autoload": { diff --git a/packages/testing/composer.json b/packages/testing/composer.json index cc985e432..2ab5b9e53 100644 --- a/packages/testing/composer.json +++ b/packages/testing/composer.json @@ -44,7 +44,9 @@ "require-dev": { "guzzlehttp/psr7": "^1.9.1|^2.4.5", "laravel/scout": "^9.8.0|^10.0.0", - "orchestra/testbench": "^8.0.0" + "orchestra/testbench": "^8.0.0", + "symfony/console": "^6.3.0", + "symfony/http-kernel": "^6.3.0" }, "autoload": { "files": [ diff --git a/packages/testing/docs/Assertions/AssertScoutQueryEqualsTest.php b/packages/testing/docs/Assertions/AssertScoutQueryEqualsTest.php index 1ad0a3e9a..5a3fdb673 100644 --- a/packages/testing/docs/Assertions/AssertScoutQueryEqualsTest.php +++ b/packages/testing/docs/Assertions/AssertScoutQueryEqualsTest.php @@ -4,8 +4,8 @@ use Illuminate\Database\Eloquent\Model; use Laravel\Scout\Builder; -use LastDragon_ru\LaraASP\GraphQL\Testing\Package\Requirements\RequiresLaravelScout; use LastDragon_ru\LaraASP\Testing\Assertions\ScoutAssertions; +use LastDragon_ru\LaraASP\Testing\Requirements\Requirements\RequiresComposerPackage; use Orchestra\Testbench\TestCase; use PHPUnit\Framework\Attributes\CoversNothing; @@ -13,7 +13,7 @@ * @internal */ #[CoversNothing] -#[RequiresLaravelScout] +#[RequiresComposerPackage('laravel/scout')] final class AssertScoutQueryEqualsTest extends TestCase { /** * Trait where assertion defined.