Passed
Pull Request — master (#5)
by Maksim
04:51 queued 01:17
created

SingleKeyBinaryModelTest::validateEagerRelations()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 5
c 1
b 1
f 0
dl 0
loc 7
rs 10
cc 1
nc 1
nop 1
1
<?php
2
3
namespace MaksimM\CompositePrimaryKeys\Tests;
4
5
use MaksimM\CompositePrimaryKeys\Tests\Stubs\TestBinaryRole;
6
7
class SingleKeyBinaryModelTest extends CompositeKeyBaseUnit
8
{
9
    protected function getEnvironmentSetUp($app)
10
    {
11
        $app['config']->set('database.default', 'testing');
12
    }
13
14
    /** @test */
15
    public function validateSingleModelLookup()
16
    {
17
        /**
18
         * @var TestBinaryRole
19
         */
20
        $model = TestBinaryRole::find(md5(1, true));
21
        $this->assertNotNull($model);
22
        $this->assertInstanceOf(TestBinaryRole::class, $model);
23
24
        return $model;
25
    }
26
27
    /** @test
28
     *  @depends  validateSingleModelLookup
29
     */
30
    public function validateSingleModelLookupModel(TestBinaryRole $model)
31
    {
32
        $this->assertEquals('Foo', $model->name);
33
    }
34
35
    /** @test
36
     *  @depends  validateSingleModelLookup
37
     */
38
    public function validateSingleModelUpdate(TestBinaryRole $model)
39
    {
40
        $model->update([
41
            'name' => 'FooBar',
42
        ]);
43
        $model->refresh();
44
        $this->assertEquals('FooBar', $model->name);
45
    }
46
47
    /** @test
48
     *  @depends  validateSingleModelLookup
49
     */
50
    public function validateEagerRelations(TestBinaryRole $model)
51
    {
52
        $model->loadMissing(['users', 'hex_users']);
53
        $this->assertNotNull($model->toArray()['users']);
54
        $this->assertNotNull($model->toArray()['hex_users']);
55
        $this->assertNotNull($model->users);
56
        $this->assertNotNull($model->hex_users);
57
    }
58
59
    /** @test
60
     */
61
    public function validateLazyEagerRelations()
62
    {
63
        $model = TestBinaryRole::find(md5(1, true));
64
        $this->assertNotNull($model->users);
65
        $this->assertNotNull($model->hex_users);
66
    }
67
}
68