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

Fix tests when $this->call(UsersTableSeeder::class) runs #206

Merged
merged 4 commits into from
Apr 11, 2024

Conversation

D0nVitalio
Copy link

When DatabaseSeeder runs $this->call(UsersTableSeeder::class) with custom users, count assertions fails.

@D0nVitalio D0nVitalio marked this pull request as draft March 12, 2024 21:08
@D0nVitalio D0nVitalio marked this pull request as ready for review March 12, 2024 21:10
@@ -27,7 +32,7 @@ protected function setUp(): void
$this->assertEquals($this->rolesCount, config('roles.models.role')::count());
$this->assertEquals($this->permissionsCount, config('roles.models.permission')::count());

DB::listen(function (QueryExecuted $query) {
DB::listen(function(QueryExecuted $query) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected 1 space after FUNCTION keyword; 0 found

@@ -38,27 +43,28 @@ public function canPreloadRolesOnCollection(): void
$roleIds = config('roles.models.role')::pluck('id');

User::factory($this->usersCount)->create()
->each(function (User $user) use ($roleIds) {
->each(function(User $user) use ($roleIds) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected 1 space after FUNCTION keyword; 0 found


$this->queries = 0;

// without eager load
$users = User::get();
$this->assertQueries(1);

$users->each(function (User $user) {
$users->each(function(User $user) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected 1 space after FUNCTION keyword; 0 found

$this->assertQueries($this->usersCount);

// with eager load
$users = User::with('roles')->get();
$this->assertQueries(2);

$users->each(function (User $user) {
$users->each(function(User $user) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected 1 space after FUNCTION keyword; 0 found

@@ -136,33 +142,33 @@ public function canPreloadPermissionsOnCollection(): void
$roleIds = config('roles.models.role')::pluck('id');

User::factory($this->usersCount)->create()
->each(function (User $user) use ($roleIds) {
->each(function(User $user) use ($roleIds) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected 1 space after FUNCTION keyword; 0 found


$this->queries = 0;

// without eager load
$users = User::get();
$this->assertQueries(1);

$users->each(function (User $user) {
$users->each(function(User $user) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected 1 space after FUNCTION keyword; 0 found


// with eager load
// TODO: 'rolePermissions' relation
$users = User::with('roles', 'userPermissions')->get();
$this->assertQueries(3);

$users->each(function (User $user) {
$users->each(function(User $user) {

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Expected 1 space after FUNCTION keyword; 0 found

@jeremykenedy jeremykenedy merged commit 56eb5cb into jeremykenedy:master Apr 11, 2024
2 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants