-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathStrictEntityRelationsTest.php
More file actions
63 lines (50 loc) · 1.93 KB
/
StrictEntityRelationsTest.php
File metadata and controls
63 lines (50 loc) · 1.93 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<?php
declare(strict_types=1);
namespace Tests;
use CodeIgniter\Test\CIUnitTestCase;
use CodeIgniter\Test\DatabaseTestTrait;
use Tests\Support\Database\Seeds\SeedTests;
use Tests\Support\Entities\Post;
use Tests\Support\Entities\Profile;
use Tests\Support\Entities\StrictUser;
use Tests\Support\Models\StrictUserModel;
/**
* @internal
*/
final class StrictEntityRelationsTest extends CIUnitTestCase
{
use DatabaseTestTrait;
protected $refresh = true;
protected $namespace;
protected $seed = SeedTests::class;
public function testEagerLoadsHasOneRelationOnStrictEntity(): void
{
$user = model(StrictUserModel::class)->with('profile')->find(1);
$this->assertInstanceOf(StrictUser::class, $user);
$this->assertInstanceOf(Profile::class, $user->profile);
$this->assertSame('United States', $user->profile->country);
}
public function testEagerLoadsHasManyRelationOnStrictEntity(): void
{
$user = model(StrictUserModel::class)->with('posts')->find(1);
$this->assertInstanceOf(StrictUser::class, $user);
$this->assertIsArray($user->posts);
$this->assertInstanceOf(Post::class, $user->posts[0]);
$this->assertSame('Title 1', $user->posts[0]->title);
}
public function testLazyLoadsHasOneRelationOnStrictEntity(): void
{
$user = model(StrictUserModel::class)->find(1);
$this->assertInstanceOf(StrictUser::class, $user);
$this->assertInstanceOf(Profile::class, $user->profile);
$this->assertSame('United States', $user->profile->country);
}
public function testLazyLoadsHasManyRelationOnStrictEntity(): void
{
$user = model(StrictUserModel::class)->find(1);
$this->assertInstanceOf(StrictUser::class, $user);
$this->assertIsArray($user->posts);
$this->assertInstanceOf(Post::class, $user->posts[0]);
$this->assertSame('Title 1', $user->posts[0]->title);
}
}