Skip to content

Commit 58fc301

Browse files
committed
Merge branch '7.x' into 8.x
Signed-off-by: Mior Muhammad Zaki <[email protected]>
2 parents 3b3e70b + eb0a8d8 commit 58fc301

9 files changed

+89
-12
lines changed

CHANGELOG-7.x.md

+9
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,15 @@
22

33
This changelog references the relevant changes (bug and security fixes) done to `orchestra/testbench-core`.
44

5+
## 7.51.1
6+
7+
Released: 2025-01-07
8+
9+
### Fixes
10+
11+
* Fix `Orchestra\Testbench\Workbench\Workbench::applicationUserModel()` to detect `App\Models\User`.
12+
* Fix authentication route registrations from being loaded with `auth: false` configuration when executed Testbench CLI.
13+
514
## 7.51.0
615

716
Released: 2024-12-24

phpstan.neon.dist

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ includes:
44
parameters:
55
paths:
66
- src
7+
- types
78

89
# The level 8 is the highest level
910
level: 8

src/Attributes/WithMigration.php

+2
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ final class WithMigration implements InvokableContract
2121

2222
/**
2323
* Construct a new attribute.
24+
*
25+
* @no-named-arguments
2426
*/
2527
public function __construct()
2628
{

src/Bootstrap/LoadConfigurationWithWorkbench.php

-5
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
use Orchestra\Testbench\Workbench\Workbench;
1010
use Symfony\Component\Finder\Finder;
1111

12-
use function Orchestra\Testbench\join_paths;
1312
use function Orchestra\Testbench\workbench_path;
1413

1514
/**
@@ -41,10 +40,6 @@ public function bootstrap(Application $app): void
4140

4241
$userModel = Workbench::applicationUserModel();
4342

44-
if (\is_null($userModel) && is_file($app->basePath(join_paths('Models', 'User.php')))) {
45-
$userModel = 'App\Models\User';
46-
}
47-
4843
if (! \is_null($userModel) && is_a($userModel, Authenticatable::class, true)) {
4944
$app->make('config')->set('auth.providers.users.model', $userModel);
5045
}

src/Concerns/InteractsWithWorkbench.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ protected function getPackageProvidersUsingWorkbench($app): ?array
7474
$hasAuthentication = $config?->getWorkbenchAttributes()['auth'] ?? false;
7575
$providers = $config?->getExtraAttributes()['providers'] ?? [];
7676

77-
if ($hasAuthentication && class_exists('Orchestra\Workbench\AuthServiceProvider')) {
77+
if ($hasAuthentication === true && class_exists('Orchestra\Workbench\AuthServiceProvider')) {
7878
$providers[] = 'Orchestra\Workbench\AuthServiceProvider';
7979
}
8080

src/Workbench/Workbench.php

+7-3
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use Symfony\Component\Finder\Finder;
1717

1818
use function Orchestra\Testbench\after_resolving;
19+
use function Orchestra\Testbench\join_paths;
1920
use function Orchestra\Testbench\package_path;
2021
use function Orchestra\Testbench\workbench_path;
2122

@@ -85,10 +86,12 @@ public static function start(ApplicationContract $app, ConfigContract $config, a
8586
*/
8687
public static function startWithProviders(ApplicationContract $app, ConfigContract $config): void
8788
{
88-
static::start($app, $config, [
89-
'Orchestra\Workbench\AuthServiceProvider',
89+
$hasAuthentication = $config->getWorkbenchAttributes()['auth'] ?? false;
90+
91+
static::start($app, $config, array_filter([
92+
$hasAuthentication === true && class_exists('Orchestra\Workbench\AuthServiceProvider') ? 'Orchestra\Workbench\AuthServiceProvider' : null,
9093
'Orchestra\Workbench\WorkbenchServiceProvider',
91-
]);
94+
]));
9295
}
9396

9497
/**
@@ -310,6 +313,7 @@ public static function applicationUserModel(): ?string
310313
static::$cachedUserModel = match (true) {
311314
Env::has('AUTH_MODEL') => Env::get('AUTH_MODEL'),
312315
is_file(workbench_path('app', 'Models', 'User.php')) => \sprintf('%sModels\User', static::detectNamespace('app')),
316+
is_file(base_path(join_paths('Models', 'User.php'))) => 'App\Models\User',
313317
default => false,
314318
};
315319
}

src/functions.php

+21-3
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,9 @@ function transform_relative_path(string $path, string $workingPath): string
280280
*
281281
* @api
282282
*
283-
* @param array|string $path
283+
* @no-named-arguments
284+
*
285+
* @param array<int, string|null>|string ...$path
284286
* @return string
285287
*/
286288
function default_skeleton_path(array|string $path = ''): string
@@ -316,7 +318,9 @@ function default_migration_path(?string $type = null): string
316318
*
317319
* @api
318320
*
319-
* @param array|string $path
321+
* @no-named-arguments
322+
*
323+
* @param array<int, string|null>|string ...$path
320324
* @return string
321325
*/
322326
function package_path(array|string $path = ''): string
@@ -360,7 +364,9 @@ function workbench(): array
360364
*
361365
* @api
362366
*
363-
* @param array|string $path
367+
* @no-named-arguments
368+
*
369+
* @param array<int, string|null>|string ...$path
364370
* @return string
365371
*/
366372
function workbench_path(array|string $path = ''): string
@@ -410,9 +416,15 @@ function laravel_vendor_exists(ApplicationContract $app, ?string $workingPath =
410416
*
411417
* @api
412418
*
419+
* @template TOperator of string|null
420+
*
413421
* @param string $version
414422
* @param string|null $operator
415423
* @return int|bool
424+
*
425+
* @phpstan-param TOperator $operator
426+
*
427+
* @phpstan-return (TOperator is null ? int : bool)
416428
*/
417429
function laravel_version_compare(string $version, ?string $operator = null)
418430
{
@@ -431,11 +443,17 @@ function laravel_version_compare(string $version, ?string $operator = null)
431443
*
432444
* @api
433445
*
446+
* @template TOperator of string|null
447+
*
434448
* @param string $version
435449
* @param string|null $operator
436450
* @return int|bool
437451
*
438452
* @throws \RuntimeException
453+
*
454+
* @phpstan-param TOperator $operator
455+
*
456+
* @phpstan-return (TOperator is null ? int : bool)
439457
*/
440458
function phpunit_version_compare(string $version, ?string $operator = null)
441459
{

tests/PHPUnit/AttributeParserTest.php

+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<?php
2+
3+
namespace Orchestra\Testbench\Tests\PHPUnit;
4+
5+
use Orchestra\Testbench\PHPUnit\AttributeParser;
6+
use PHPUnit\Framework\TestCase;
7+
8+
class AttributeParserTest extends TestCase
9+
{
10+
/** @test */
11+
public function it_can_validate_attribute()
12+
{
13+
$this->assertFalse(AttributeParser::validAttribute('TestCase::class'));
14+
$this->assertFalse(AttributeParser::validAttribute(TestCase::class));
15+
$this->assertFalse(AttributeParser::validAttribute('Orchestra\Testbench\Support\FluentDecorator'));
16+
17+
$this->assertTrue(AttributeParser::validAttribute('Orchestra\Testbench\Attributes\Define'));
18+
}
19+
}

types/functions.php

+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
use function Orchestra\Testbench\default_skeleton_path;
4+
use function Orchestra\Testbench\laravel_version_compare;
5+
use function Orchestra\Testbench\package_path;
6+
use function Orchestra\Testbench\phpunit_version_compare;
7+
use function Orchestra\Testbench\workbench_path;
8+
use function PHPStan\Testing\assertType;
9+
10+
assertType('string', default_skeleton_path());
11+
assertType('string', default_skeleton_path('app'));
12+
assertType('string', default_skeleton_path('app', '.gitkeep'));
13+
assertType('string', default_skeleton_path(['app', '.gitkeep']));
14+
15+
assertType('string', package_path());
16+
assertType('string', package_path('laravel'));
17+
assertType('string', package_path('laravel', 'app', '.gitkeep'));
18+
assertType('string', package_path(['laravel', 'app', '.gitkeep']));
19+
20+
assertType('string', workbench_path());
21+
assertType('string', workbench_path('app'));
22+
assertType('string', workbench_path('app', 'Providers'));
23+
assertType('string', workbench_path(['app', 'Providers']));
24+
25+
assertType('bool', laravel_version_compare('7.0.0', '>='));
26+
assertType('int', laravel_version_compare('7.0.0'));
27+
28+
assertType('bool', phpunit_version_compare('9.0.0', '>='));
29+
assertType('int', phpunit_version_compare('9.0.0'));

0 commit comments

Comments
 (0)