-
-
Notifications
You must be signed in to change notification settings - Fork 64
/
Copy pathBelongsToManyTest.php
41 lines (31 loc) · 1.29 KB
/
BelongsToManyTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php
namespace Staudenmeir\EloquentEagerLimit\Tests;
use Staudenmeir\EloquentEagerLimit\Tests\Models\User;
class BelongsToManyTest extends TestCase
{
public function testLazyLoading()
{
$roles = User::first()->roles()->offset(1)->get();
$this->assertEquals([2, 1], $roles->pluck('id')->all());
}
public function testEagerLoading()
{
$users = User::with('roles')->get();
$this->assertEquals([3, 2], $users[0]->roles->pluck('id')->all());
$this->assertEquals([6, 5], $users[1]->roles->pluck('id')->all());
$this->assertArrayNotHasKey('@laravel_partition := `pivot_user_id`', $users[0]->roles[0]);
}
public function testEagerLoadingWithOffset()
{
$users = User::with('rolesWithOffset')->get();
$this->assertEquals([2, 1], $users[0]->rolesWithOffset->pluck('id')->all());
$this->assertEquals([5, 4], $users[1]->rolesWithOffset->pluck('id')->all());
}
public function testLazyEagerLoading()
{
$users = User::all()->load('roles');
$this->assertEquals([3, 2], $users[0]->roles->pluck('id')->all());
$this->assertEquals([6, 5], $users[1]->roles->pluck('id')->all());
$this->assertArrayNotHasKey('@laravel_partition := `pivot_user_id`', $users[0]->roles[0]);
}
}