Skip to content
Merged
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
19 changes: 17 additions & 2 deletions tests/Database/DatabaseEloquentFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -995,9 +995,21 @@ public function test_factory_can_insert()
->insert();
$this->assertCount(5, $posts = FactoryTestPost::query()->where('title', 'hello')->get());
$this->assertEquals(strtoupper($posts[0]->user->name), $posts[0]->upper_case_name);
$this->assertEquals(2, ($users = FactoryTestUser::query()->get())->count());
$this->assertCount(1, $users->where('name', 'shaedrich'));
$this->assertEquals(
2,
($users = FactoryTestUser::query()->get())->count()
);
$this->assertCount(1, $users->where('name', 'totwell'));
$this->assertCount(1, $users->where('name', 'shaedrich'));
}

public function test_factory_can_insert_with_hidden()
{
(new FactoryTestUserFactory())->forEachSequence(['name' => Name::Taylor, 'options' => 'abc'])->insert();
$user = DB::table('users')->sole();
$this->assertEquals('abc', $user->options);
$userModel = FactoryTestUser::query()->sole();
$this->assertEquals('abc', $userModel->options);
}

/**
Expand Down Expand Up @@ -1039,6 +1051,9 @@ class FactoryTestUser extends Eloquent
use HasFactory;

protected $table = 'users';
protected $hidden = ['options'];
protected $withCount = ['posts'];
protected $with = ['posts'];

public function posts()
{
Expand Down
Loading