diff --git a/tests/ChecksLaravelVersionTrait.php b/tests/ChecksLaravelVersionTrait.php index 9667fb56..20a14dc0 100644 --- a/tests/ChecksLaravelVersionTrait.php +++ b/tests/ChecksLaravelVersionTrait.php @@ -2,25 +2,40 @@ namespace Dingo\Api\Tests; -use Dingo\Api\Tests\Stubs\Application7Stub; use Dingo\Api\Tests\Stubs\ApplicationStub; +use Dingo\Api\Tests\Stubs\Application8Stub; +use Dingo\Api\Tests\Stubs\Application7Stub; use Dingo\Api\Tests\Stubs\Application6Stub; use Dingo\Api\Tests\Stubs\Application58Stub; trait ChecksLaravelVersionTrait { public $installed_file_path = __DIR__.'/../vendor/composer/installed.json'; - public $current_release = '7.0'; + public $current_release = '8.0'; private function getFrameworkVersion() { $contents = file_get_contents($this->installed_file_path); $parsed_data = json_decode($contents, true); - $just_laravel = array_filter($parsed_data, function ($val) { - if ('laravel/framework' === $val['name'] || 'laravel/lumen-framework' === $val['name']) { - return true; + + // Changed array format in newer versions of composer (v2?) + if (array_key_exists('packages', $parsed_data)) { + $parsed_data = $parsed_data['packages']; + } + + // Find laravel/framework or lumen package + $just_laravel = array_filter($parsed_data, function ($composerPackageData) { + if (is_array($composerPackageData) && array_key_exists('name', $composerPackageData)) { + if ('laravel/framework' === $composerPackageData['name'] || 'laravel/lumen-framework' === $composerPackageData['name']) { + return true; + } } }); + + if (empty($just_laravel)) { + exit(PHP_EOL.'No Laravel version detected, please do a "composer require laravel/framework:x" prior to testing'.PHP_EOL); + } + $laravelVersion = array_map(function ($val) { return $val['version']; }, array_values($just_laravel))[0]; @@ -39,7 +54,9 @@ private function getApplicationStub() $version = str_replace('v', '', $version); // Return the version stub for the right version - if (version_compare($version, '7.0.0', '>=')) { + if (version_compare($version, '8.0.0', '>=')) { + return new Application8Stub; + } elseif (version_compare($version, '7.0.0', '>=')) { return new Application7Stub; } elseif (version_compare($version, '6.0.0', '>=')) { return new Application6Stub; diff --git a/tests/Stubs/Application8Stub.php b/tests/Stubs/Application8Stub.php new file mode 100644 index 00000000..0c70ce69 --- /dev/null +++ b/tests/Stubs/Application8Stub.php @@ -0,0 +1,199 @@ +