Skip to content

Commit

Permalink
Merge branch '7.x' into 8.x
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <crynobone@gmail.com>
  • Loading branch information
crynobone committed Jan 7, 2025
2 parents 3b3e70b + eb0a8d8 commit 58fc301
Show file tree
Hide file tree
Showing 9 changed files with 89 additions and 12 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG-7.x.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ includes:
parameters:
paths:
- src
- types

# The level 8 is the highest level
level: 8
Expand Down
2 changes: 2 additions & 0 deletions src/Attributes/WithMigration.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ final class WithMigration implements InvokableContract

/**
* Construct a new attribute.
*
* @no-named-arguments
*/
public function __construct()
{
Expand Down
5 changes: 0 additions & 5 deletions src/Bootstrap/LoadConfigurationWithWorkbench.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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);
}
Expand Down
2 changes: 1 addition & 1 deletion src/Concerns/InteractsWithWorkbench.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

Expand Down
10 changes: 7 additions & 3 deletions src/Workbench/Workbench.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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',
]);
]));
}

/**
Expand Down Expand Up @@ -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,
};
}
Expand Down
24 changes: 21 additions & 3 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ function transform_relative_path(string $path, string $workingPath): string
*
* @api
*
* @param array|string $path
* @no-named-arguments
*
* @param array<int, string|null>|string ...$path
* @return string
*/
function default_skeleton_path(array|string $path = ''): string
Expand Down Expand Up @@ -316,7 +318,9 @@ function default_migration_path(?string $type = null): string
*
* @api
*
* @param array|string $path
* @no-named-arguments
*
* @param array<int, string|null>|string ...$path
* @return string
*/
function package_path(array|string $path = ''): string
Expand Down Expand Up @@ -360,7 +364,9 @@ function workbench(): array
*
* @api
*
* @param array|string $path
* @no-named-arguments
*
* @param array<int, string|null>|string ...$path
* @return string
*/
function workbench_path(array|string $path = ''): string
Expand Down Expand Up @@ -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)
{
Expand All @@ -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)
{
Expand Down
19 changes: 19 additions & 0 deletions tests/PHPUnit/AttributeParserTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Orchestra\Testbench\Tests\PHPUnit;

use Orchestra\Testbench\PHPUnit\AttributeParser;
use PHPUnit\Framework\TestCase;

class AttributeParserTest extends TestCase
{
/** @test */
public function it_can_validate_attribute()
{
$this->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'));
}
}
29 changes: 29 additions & 0 deletions types/functions.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use function Orchestra\Testbench\default_skeleton_path;
use function Orchestra\Testbench\laravel_version_compare;
use function Orchestra\Testbench\package_path;
use function Orchestra\Testbench\phpunit_version_compare;
use function Orchestra\Testbench\workbench_path;
use function PHPStan\Testing\assertType;

assertType('string', default_skeleton_path());
assertType('string', default_skeleton_path('app'));
assertType('string', default_skeleton_path('app', '.gitkeep'));
assertType('string', default_skeleton_path(['app', '.gitkeep']));

assertType('string', package_path());
assertType('string', package_path('laravel'));
assertType('string', package_path('laravel', 'app', '.gitkeep'));
assertType('string', package_path(['laravel', 'app', '.gitkeep']));

assertType('string', workbench_path());
assertType('string', workbench_path('app'));
assertType('string', workbench_path('app', 'Providers'));
assertType('string', workbench_path(['app', 'Providers']));

assertType('bool', laravel_version_compare('7.0.0', '>='));
assertType('int', laravel_version_compare('7.0.0'));

assertType('bool', phpunit_version_compare('9.0.0', '>='));
assertType('int', phpunit_version_compare('9.0.0'));

0 comments on commit 58fc301

Please sign in to comment.