Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Laravel 12 support #54

Merged
merged 8 commits into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,16 @@ jobs:
fail-fast: true
matrix:
os: [ubuntu-latest, windows-latest]
php: [8.2, 8.3]
laravel: [10.*, 11.*]
php: [8.2, 8.3, 8.4]
laravel: [10.*, 11.*, 12.*]
stability: [prefer-lowest, prefer-stable]
include:
- laravel: 10.*
testbench: 8.*
- laravel: 11.*
testbench: 9.*
- laravel: 12.*
testbench: 10.*

name: P${{ matrix.php }} - L${{ matrix.laravel }} - ${{ matrix.stability }} - ${{ matrix.os }}

Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
.php_cs
.php_cs.cache
.phpunit.result.cache
.phpunit.cache
build
composer.lock
coverage
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
],
"require": {
"php": "^8.2",
"illuminate/contracts": "^10.0 || ^11.0"
"illuminate/contracts": "^10.0 || ^11.0 || ^12.0"
},
"require-dev": {
"larastan/larastan": "^2.8",
"larastan/larastan": "^2.8 || ^3.0",
"nunomaduro/collision": "^7.0 || ^8.0",
"orchestra/testbench": "^8.20 || ^9.0",
"pestphp/pest": "^2.30",
"pestphp/pest-plugin-laravel": "^2.2",
"worksome/coding-style": "^2.7"
"orchestra/testbench": "^8.20 || ^9.0 || ^10.0",
"pestphp/pest": "^2.30 || ^3.0",
"pestphp/pest-plugin-laravel": "^2.2 || ^3.0",
"worksome/coding-style": "^2.15 || ^3.1"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 1 addition & 1 deletion src/Actions/CreateFactoryResultSteps/RecursiveStep.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public static function using(CreateFactoryResultStep $decoratedStep): self
public function handle(Collection $data, Closure $next): Collection
{
return $this->decoratedStep->handle(
$data->map(fn(mixed $item) => $this->walk($item)),
$data->map(fn (mixed $item) => $this->walk($item)),
$next,
);
}
Expand Down
2 changes: 1 addition & 1 deletion src/RequestFactoriesServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private function declareFactoryMethodOnFormRequests(): void

FormRequest::macro(
'factory',
static fn() => app(Map::class)->formRequestToFactory(static::class)::new()
static fn () => app(Map::class)->formRequestToFactory(static::class)::new()
);
}

Expand Down
2 changes: 1 addition & 1 deletion src/RequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public function fake(): void
*
* @return FileFactory|File
*/
protected function file(string $name = null): FileFactory|File
protected function file(string|null $name = null): FileFactory|File
{
if ($name === null) {
return UploadedFile::fake();
Expand Down
1 change: 1 addition & 0 deletions src/Support/HigherOrderRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function __call(string $name, array $arguments): mixed
}

$result->fake();

return new self($result);
}

Expand Down
2 changes: 1 addition & 1 deletion src/Support/Map.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function formRequestToFactory(string $formRequest): string
return $formRequest::$factory;
}

$requestPartialFQCN = Str::after($formRequest, "App\\Http\\Requests\\");
$requestPartialFQCN = Str::after($formRequest, 'App\\Http\\Requests\\');
$factoryNamespace = $this->finder->requestFactoriesNamespace();
$guessedFactoryFQCN = $factoryNamespace . '\\' . $requestPartialFQCN . 'Factory';

Expand Down
3 changes: 2 additions & 1 deletion tests/Doubles/Factories/Models/UserFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
class UserFactory extends Factory
{
private static int $id = 1;

protected $model = User::class;

public function definition(): array
Expand All @@ -33,6 +34,6 @@ public static function resetId(): void
*/
protected function store(Collection $results): void
{
$results->each(fn(Model $model, int $key) => $model->{$model->getKeyName()} = self::$id++);
$results->each(fn (Model $model, int $key) => $model->{$model->getKeyName()} = self::$id++);
}
}
4 changes: 2 additions & 2 deletions tests/Doubles/Factories/NestedArrayRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public function definition(): array
'baz' => [
'boom' => [
'bang' => fn () => 'whizz',
]
],
],
'factory' => AddressFormRequestFactory::new(),
]
],
];
}
}
2 changes: 1 addition & 1 deletion tests/Feature/Faking/HasFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
ExampleFormRequest::fake();

post('/example', [
'email' => '[email protected]'
'email' => '[email protected]',
])
->assertJsonStructure(['email', 'name', 'address'])
->assertJson(['email' => '[email protected]']);
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/Faking/PestMethodTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@

it('can pass a RequestFactory to the Pest fakeRequest helper via a Closure', function () {
post('/example')->assertJson(['foo' => 'bar']);
})->fakeRequest(fn() => ExampleFormRequest::factory()->state(['foo' => 'bar']));
})->fakeRequest(fn () => ExampleFormRequest::factory()->state(['foo' => 'bar']));

it('can chain RequestFactory methods onto the fakeRequest helper', function () {
post('/example')->assertJson([
'foo' => 'bar',
'profession' => 'Clown'
'profession' => 'Clown',
]);
})
->skip(false) // Note that we can call Pest methods before...
Expand Down
8 changes: 4 additions & 4 deletions tests/Unit/Actions/UndotArrayKeysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
})->with([
[
['foo.bar' => 'baz'],
['foo' => ['bar' => 'baz']]
['foo' => ['bar' => 'baz']],
],
[
['foo.bar.baz' => 'boom'],
Expand All @@ -22,7 +22,7 @@
[
['foo.bar' => 'baz', 'luke' => 'downing'],
['foo' => ['bar' => 'baz'], 'luke' => 'downing'],
]
],
]);

it('can escape dots with the \\ character', function ($givenArray, $resultingArray) {
Expand All @@ -34,7 +34,7 @@
})->with([
[
['foo\.bar' => 'baz'],
['foo.bar' => 'baz']
['foo.bar' => 'baz'],
],
[
['foo\.bar\.baz' => 'boom'],
Expand All @@ -43,5 +43,5 @@
[
['foo.bar\.baz' => 'boom'],
['foo' => ['bar.baz' => 'boom']],
]
],
]);
16 changes: 8 additions & 8 deletions tests/Unit/RequestFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
use Worksome\RequestFactories\Tests\Doubles\Factories\NestedArrayRequestFactory;

beforeEach(function () {
RequestFactory::setFakerResolver(fn() => Factory::create());
RequestFactory::setFakerResolver(fn () => Factory::create());
UserFactory::resetId();
});

Expand Down Expand Up @@ -82,8 +82,8 @@
it('can resolve nested form request factories', function () {
$data = creator(ExampleFormRequestFactory::new()->state([
'secret_identity' => ExampleFormRequestFactory::new()->state([
'super_secret_identity' => ExampleFormRequestFactory::new()
])
'super_secret_identity' => ExampleFormRequestFactory::new(),
]),
]));

expect($data)
Expand All @@ -95,7 +95,7 @@
it('can resolve property closures, and passes those closures all other parameters', function () {
$data = creator(ExampleFormRequestFactory::new()->state([
'name' => 'Luke Downing',
'description' => fn(array $attributes) => "Hello, my name is {$attributes['name']}"
'description' => fn (array $attributes) => "Hello, my name is {$attributes['name']}",
]));

expect($data['description'])->toBe('Hello, my name is Luke Downing');
Expand All @@ -118,7 +118,7 @@
* on ExampleFormRequestFactory to override the functionality.
*/
ExampleFormRequestFactory::configureUsing(function (ExampleFormRequestFactory $factory) {
return $factory->afterCreating(fn() => ['foo' => 'bar']);
return $factory->afterCreating(fn () => ['foo' => 'bar']);
});

expect(creator(ExampleFormRequestFactory::new())->all())->toBe(['foo' => 'bar']);
Expand Down Expand Up @@ -156,7 +156,7 @@
expect($data)->not->toHaveKeys($expectedMissingKeys);
})->with([
'string' => ['address.line_one', ['address.line_one']],
'array' => [['name', 'address.line_one'], ['name', 'address.line_one']]
'array' => [['name', 'address.line_one'], ['name', 'address.line_one']],
]);

it('can overwrite deeply nested array data', function () {
Expand All @@ -172,10 +172,10 @@
$testGenerator = new class() extends \Faker\Generator {
};

ExampleFormRequestFactory::setFakerResolver(fn() => $testGenerator);
ExampleFormRequestFactory::setFakerResolver(fn () => $testGenerator);
expect(ExampleFormRequestFactory::new()->faker())->toBe($testGenerator);

ExampleFormRequestFactory::setFakerResolver(fn() => Factory::create('en_US'));
ExampleFormRequestFactory::setFakerResolver(fn () => Factory::create('en_US'));
expect(ExampleFormRequestFactory::new()->faker())->not->toBe($testGenerator);
});

Expand Down
Loading