Skip to content

Commit

Permalink
Merge pull request #1118 from mfn/mfn-legacy-factories
Browse files Browse the repository at this point in the history
laravel: use new factory approach
  • Loading branch information
mfn authored Feb 18, 2024
2 parents b181329 + ef54f63 commit 030ad0b
Show file tree
Hide file tree
Showing 27 changed files with 266 additions and 195 deletions.
1 change: 0 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
"require-dev": {
"ext-pdo_sqlite": "*",
"friendsofphp/php-cs-fixer": "3.37.1",
"laravel/legacy-factories": "^1.0",
"mfn/php-cs-fixer-config": "^2",
"mockery/mockery": "^1.2",
"phpstan/phpstan": "1.10.40",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ protected function getEnvironmentSetUp($app): void
public function testUniquePassRulePass(): void
{
/* @var User $user */
factory(User::class)
User::factory()
->create([
'name' => 'name_unique',
]);
Expand Down Expand Up @@ -62,7 +62,7 @@ public function testUniquePassRulePass(): void
public function testUniqueFailRulePass(): void
{
/* @var User $user */
factory(User::class)
User::factory()
->create([
'name' => 'name_unique',
]);
Expand Down Expand Up @@ -118,7 +118,7 @@ public function testUniqueFailRulePass(): void
public function testUniquePassRuleFail(): void
{
/* @var User $user */
factory(User::class)
User::factory()
->create([
'name' => 'name_unique',
]);
Expand Down Expand Up @@ -168,7 +168,7 @@ public function testUniquePassRuleFail(): void
public function testUniqueFailRuleFail(): void
{
/* @var User $user */
factory(User::class)
User::factory()
->create([
'name' => 'name_unique',
]);
Expand Down Expand Up @@ -225,7 +225,7 @@ public function testUniqueFailRuleFail(): void
public function testErrorExtension(): void
{
/* @var User $user */
factory(User::class)
User::factory()
->create([
'name' => 'name_unique',
]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ protected function getEnvironmentSetUp($app): void
public function testAlwaysSingleHasManyRelationField(): void
{
/** @var User $user */
$user = factory(User::class)->create([
$user = User::factory()->create([
'name' => 'User Name',
]);

/** @var Post $post */
$post = factory(Post::class)->create([
$post = Post::factory()->create([
'user_id' => $user->id,
]);

factory(Comment::class)->create([
Comment::factory()->create([
'post_id' => $post->id,
]);

Expand Down Expand Up @@ -101,14 +101,14 @@ public function testAlwaysSingleHasManyRelationField(): void

public function testAlwaysSingleMorphRelationField(): void
{
$user = factory(User::class)->create([
$user = User::factory()->create([
'name' => 'User Name',
]);

/** @var Post $post */
$post = factory(Post::class)->create();
$post = Post::factory()->create();

$comment = factory(Comment::class)
$comment = Comment::factory()
->create([
'post_id' => $post->id,
]);
Expand Down
16 changes: 8 additions & 8 deletions tests/Database/SelectFields/AlwaysTests/AlwaysTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ protected function getEnvironmentSetUp($app): void
public function testAlwaysSingleField(): void
{
/** @var Post $post */
$post = factory(Post::class)
$post = Post::factory()
->create([
'body' => 'post body',
'title' => 'post title',
]);
/** @var Comment $comment */
$comment = factory(Comment::class)
$comment = Comment::factory()
->create([
'body' => 'comment body',
'post_id' => $post->id,
Expand Down Expand Up @@ -86,13 +86,13 @@ public function testAlwaysSingleField(): void
public function testAlwaysSingleMultipleFieldInString(): void
{
/** @var Post $post */
$post = factory(Post::class)
$post = Post::factory()
->create([
'body' => 'post body',
'title' => 'post title',
]);
/** @var Comment $comment */
$comment = factory(Comment::class)
$comment = Comment::factory()
->create([
'body' => 'comment body',
'post_id' => $post->id,
Expand Down Expand Up @@ -143,13 +143,13 @@ public function testAlwaysSingleMultipleFieldInString(): void
public function testAlwaysSingleMultipleFieldInArray(): void
{
/** @var Post $post */
$post = factory(Post::class)
$post = Post::factory()
->create([
'body' => 'post body',
'title' => 'post title',
]);
/** @var Comment $comment */
$comment = factory(Comment::class)
$comment = Comment::factory()
->create([
'body' => 'comment body',
'post_id' => $post->id,
Expand Down Expand Up @@ -200,13 +200,13 @@ public function testAlwaysSingleMultipleFieldInArray(): void
public function testAlwaysSameFieldTwice(): void
{
/** @var Post $post */
$post = factory(Post::class)
$post = Post::factory()
->create([
'body' => 'post body',
'title' => 'post title',
]);
/** @var Comment $comment */
$comment = factory(Comment::class)
$comment = Comment::factory()
->create([
'body' => 'comment body',
'post_id' => $post->id,
Expand Down
2 changes: 1 addition & 1 deletion tests/Database/SelectFields/ArrayTests/ArrayTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function testArrayFieldRetrieved(): void
];

/** @var Post $post */
$post = factory(Post::class)->create([
$post = Post::factory()->create([
'properties' => $properties,
]);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ protected function getEnvironmentSetUp($app): void
public function testComputedProperty(): void
{
/** @var User $user */
$user = factory(User::class)->create([
$user = User::factory()->create([
]);

/** @var Post $post */
$post = factory(Post::class)->create([
$post = Post::factory()->create([
'user_id' => $user->id,
]);

Expand Down
4 changes: 2 additions & 2 deletions tests/Database/SelectFields/DepthTests/DepthTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ protected function getEnvironmentSetUp($app): void
public function testDefaultDepthExceeded(): void
{
/** @var User $user */
$user = factory(User::class)->create();
factory(Post::class)->create([
$user = User::factory()->create();
Post::factory()->create([
'user_id' => $user->id,
]);

Expand Down
34 changes: 17 additions & 17 deletions tests/Database/SelectFields/InterfaceTests/InterfaceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ protected function getEnvironmentSetUp($app): void

public function testGeneratedSqlQuery(): void
{
factory(Post::class)->create([
Post::factory()->create([
'title' => 'Title of the post',
]);

Expand Down Expand Up @@ -79,11 +79,11 @@ public function testGeneratedSqlQuery(): void
public function testGeneratedRelationSqlQuery(): void
{
/** @var Post $post */
$post = factory(Post::class)
$post = Post::factory()
->create([
'title' => 'Title of the post',
]);
factory(Comment::class)
Comment::factory()
->create([
'title' => 'Title of the comment',
'post_id' => $post->id,
Expand Down Expand Up @@ -133,18 +133,18 @@ public function testGeneratedRelationSqlQuery(): void
public function testGeneratedInterfaceFieldSqlQuery(): void
{
/** @var Post $post */
$post = factory(Post::class)
$post = Post::factory()
->create([
'title' => 'Title of the post',
]);
factory(Comment::class)
Comment::factory()
->create([
'title' => 'Title of the comment',
'post_id' => $post->id,
]);

/** @var User $user */
$user = factory(User::class)->create();
$user = User::factory()->create();
Like::create([
'likable_id' => $post->id,
'likable_type' => Post::class,
Expand Down Expand Up @@ -200,18 +200,18 @@ public function testGeneratedInterfaceFieldSqlQuery(): void
public function testGeneratedInterfaceFieldInlineFragmentsAndAlias(): void
{
/** @var Post $post */
$post = factory(Post::class)
$post = Post::factory()
->create([
'title' => 'Title of the post',
]);
factory(Comment::class)
Comment::factory()
->create([
'title' => 'Title of the comment',
'post_id' => $post->id,
]);

/** @var User $user */
$user = factory(User::class)->create();
$user = User::factory()->create();
Like::create([
'likable_id' => $post->id,
'likable_type' => Post::class,
Expand Down Expand Up @@ -273,20 +273,20 @@ public function testGeneratedInterfaceFieldInlineFragmentsAndAlias(): void
public function testGeneratedInterfaceFieldWithRelationSqlQuery(): void
{
/** @var Post $post */
$post = factory(Post::class)
$post = Post::factory()
->create([
'title' => 'Title of the post',
]);
factory(Comment::class)
Comment::factory()
->create([
'title' => 'Title of the comment',
'post_id' => $post->id,
]);

/** @var User $user */
$user = factory(User::class)->create();
$user = User::factory()->create();
/** @var User $user2 */
$user2 = factory(User::class)->create();
$user2 = User::factory()->create();
$like1 = Like::create([
'likable_id' => $post->id,
'likable_type' => Post::class,
Expand Down Expand Up @@ -378,21 +378,21 @@ public function testGeneratedInterfaceFieldWithRelationSqlQuery(): void
public function testGeneratedInterfaceFieldWithRelationAndCustomQueryOnInterfaceSqlQuery(): void
{
/** @var Post $post */
$post = factory(Post::class)
$post = Post::factory()
->create([
'title' => 'Title of the post',
]);
/** @var Comment $comment */
$comment = factory(Comment::class)
$comment = Comment::factory()
->create([
'title' => 'Title of the comment',
'post_id' => $post->id,
]);

/** @var User $user */
$user = factory(User::class)->create();
$user = User::factory()->create();
/** @var User $user2 */
$user2 = factory(User::class)->create();
$user2 = User::factory()->create();
$like1 = Like::create([
'likable_id' => $comment->id,
'likable_type' => Comment::class,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,20 @@ protected function getEnvironmentSetUp($app): void
public function testMorphRelationship(): void
{
/** @var User $user */
$user = factory(User::class)->create([
$user = User::factory()->create([
'name' => 'User Name',
]);

/** @var User $otherUser */
$otherUser = factory(User::class)->create();
$otherUser = User::factory()->create();

/** @var Post $post */
$post = factory(Post::class)->create([
$post = Post::factory()->create([
'user_id' => $user->id,
]);

/** @var Like $like */
$like = factory(Like::class)->make([
$like = Like::factory()->make([
'user_id' => $otherUser->id,
]);

Expand Down
Loading

0 comments on commit 030ad0b

Please sign in to comment.