diff --git a/CHANGELOG-7.x.md b/CHANGELOG-7.x.md index a6d293b8..9ce33c2e 100644 --- a/CHANGELOG-7.x.md +++ b/CHANGELOG-7.x.md @@ -2,6 +2,15 @@ This changelog references the relevant changes (bug and security fixes) done to `orchestra/testbench-core`. +## 7.51.1 + +Released: 2025-01-07 + +### Fixes + +* Fix `Orchestra\Testbench\Workbench\Workbench::applicationUserModel()` to detect `App\Models\User`. +* Fix authentication route registrations from being loaded with `auth: false` configuration when executed Testbench CLI. + ## 7.51.0 Released: 2024-12-24 diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 9c0fd211..c9b2c8b5 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -4,6 +4,7 @@ includes: parameters: paths: - src + - types # The level 8 is the highest level level: 8 diff --git a/src/Attributes/WithMigration.php b/src/Attributes/WithMigration.php index efa82646..3bc0f06d 100644 --- a/src/Attributes/WithMigration.php +++ b/src/Attributes/WithMigration.php @@ -21,6 +21,8 @@ final class WithMigration implements InvokableContract /** * Construct a new attribute. + * + * @no-named-arguments */ public function __construct() { diff --git a/src/Bootstrap/LoadConfigurationWithWorkbench.php b/src/Bootstrap/LoadConfigurationWithWorkbench.php index 0021512d..cba05253 100644 --- a/src/Bootstrap/LoadConfigurationWithWorkbench.php +++ b/src/Bootstrap/LoadConfigurationWithWorkbench.php @@ -9,7 +9,6 @@ use Orchestra\Testbench\Workbench\Workbench; use Symfony\Component\Finder\Finder; -use function Orchestra\Testbench\join_paths; use function Orchestra\Testbench\workbench_path; /** @@ -41,10 +40,6 @@ public function bootstrap(Application $app): void $userModel = Workbench::applicationUserModel(); - if (\is_null($userModel) && is_file($app->basePath(join_paths('Models', 'User.php')))) { - $userModel = 'App\Models\User'; - } - if (! \is_null($userModel) && is_a($userModel, Authenticatable::class, true)) { $app->make('config')->set('auth.providers.users.model', $userModel); } diff --git a/src/Concerns/InteractsWithWorkbench.php b/src/Concerns/InteractsWithWorkbench.php index 98589677..6cb12971 100644 --- a/src/Concerns/InteractsWithWorkbench.php +++ b/src/Concerns/InteractsWithWorkbench.php @@ -74,7 +74,7 @@ protected function getPackageProvidersUsingWorkbench($app): ?array $hasAuthentication = $config?->getWorkbenchAttributes()['auth'] ?? false; $providers = $config?->getExtraAttributes()['providers'] ?? []; - if ($hasAuthentication && class_exists('Orchestra\Workbench\AuthServiceProvider')) { + if ($hasAuthentication === true && class_exists('Orchestra\Workbench\AuthServiceProvider')) { $providers[] = 'Orchestra\Workbench\AuthServiceProvider'; } diff --git a/src/Workbench/Workbench.php b/src/Workbench/Workbench.php index 435aeb5d..aec47d42 100644 --- a/src/Workbench/Workbench.php +++ b/src/Workbench/Workbench.php @@ -16,6 +16,7 @@ use Symfony\Component\Finder\Finder; use function Orchestra\Testbench\after_resolving; +use function Orchestra\Testbench\join_paths; use function Orchestra\Testbench\package_path; use function Orchestra\Testbench\workbench_path; @@ -85,10 +86,12 @@ public static function start(ApplicationContract $app, ConfigContract $config, a */ public static function startWithProviders(ApplicationContract $app, ConfigContract $config): void { - static::start($app, $config, [ - 'Orchestra\Workbench\AuthServiceProvider', + $hasAuthentication = $config->getWorkbenchAttributes()['auth'] ?? false; + + static::start($app, $config, array_filter([ + $hasAuthentication === true && class_exists('Orchestra\Workbench\AuthServiceProvider') ? 'Orchestra\Workbench\AuthServiceProvider' : null, 'Orchestra\Workbench\WorkbenchServiceProvider', - ]); + ])); } /** @@ -310,6 +313,7 @@ public static function applicationUserModel(): ?string static::$cachedUserModel = match (true) { Env::has('AUTH_MODEL') => Env::get('AUTH_MODEL'), is_file(workbench_path('app', 'Models', 'User.php')) => \sprintf('%sModels\User', static::detectNamespace('app')), + is_file(base_path(join_paths('Models', 'User.php'))) => 'App\Models\User', default => false, }; } diff --git a/src/functions.php b/src/functions.php index 17a638f2..b242bcb9 100644 --- a/src/functions.php +++ b/src/functions.php @@ -280,7 +280,9 @@ function transform_relative_path(string $path, string $workingPath): string * * @api * - * @param array|string $path + * @no-named-arguments + * + * @param array|string ...$path * @return string */ function default_skeleton_path(array|string $path = ''): string @@ -316,7 +318,9 @@ function default_migration_path(?string $type = null): string * * @api * - * @param array|string $path + * @no-named-arguments + * + * @param array|string ...$path * @return string */ function package_path(array|string $path = ''): string @@ -360,7 +364,9 @@ function workbench(): array * * @api * - * @param array|string $path + * @no-named-arguments + * + * @param array|string ...$path * @return string */ function workbench_path(array|string $path = ''): string @@ -410,9 +416,15 @@ function laravel_vendor_exists(ApplicationContract $app, ?string $workingPath = * * @api * + * @template TOperator of string|null + * * @param string $version * @param string|null $operator * @return int|bool + * + * @phpstan-param TOperator $operator + * + * @phpstan-return (TOperator is null ? int : bool) */ function laravel_version_compare(string $version, ?string $operator = null) { @@ -431,11 +443,17 @@ function laravel_version_compare(string $version, ?string $operator = null) * * @api * + * @template TOperator of string|null + * * @param string $version * @param string|null $operator * @return int|bool * * @throws \RuntimeException + * + * @phpstan-param TOperator $operator + * + * @phpstan-return (TOperator is null ? int : bool) */ function phpunit_version_compare(string $version, ?string $operator = null) { diff --git a/tests/PHPUnit/AttributeParserTest.php b/tests/PHPUnit/AttributeParserTest.php new file mode 100644 index 00000000..485dcd3d --- /dev/null +++ b/tests/PHPUnit/AttributeParserTest.php @@ -0,0 +1,19 @@ +assertFalse(AttributeParser::validAttribute('TestCase::class')); + $this->assertFalse(AttributeParser::validAttribute(TestCase::class)); + $this->assertFalse(AttributeParser::validAttribute('Orchestra\Testbench\Support\FluentDecorator')); + + $this->assertTrue(AttributeParser::validAttribute('Orchestra\Testbench\Attributes\Define')); + } +} diff --git a/types/functions.php b/types/functions.php new file mode 100644 index 00000000..6182e764 --- /dev/null +++ b/types/functions.php @@ -0,0 +1,29 @@ +=')); +assertType('int', laravel_version_compare('7.0.0')); + +assertType('bool', phpunit_version_compare('9.0.0', '>=')); +assertType('int', phpunit_version_compare('9.0.0'));