Passed
Push — master ( 2097d5...663657 )
by Maksim
04:27 queued 01:00
created

validateManyModelLookup()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
f 0
dl 0
loc 10
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace MaksimM\CompositePrimaryKeys\Tests;
4
5
use MaksimM\CompositePrimaryKeys\Tests\Stubs\TestBinaryRoleHex;
6
7
class SingleKeyBinaryModelHexTest extends CompositeKeyBaseUnit
8
{
9
    protected function getEnvironmentSetUp($app)
10
    {
11
        $app['config']->set('database.default', 'testing');
12
    }
13
14
    /** @test */
15
    public function automaticBinaryKeysOnCreation()
16
    {
17
        /**
18
         * @var TestBinaryRoleHex
19
         */
20
        $model = TestBinaryRoleHex::create(['name' => 'Zoo']);
21
        $this->assertNotNull($model->role_id);
0 ignored issues
show
Bug Best Practice introduced by
The property role_id does not exist on MaksimM\CompositePrimary...Stubs\TestBinaryRoleHex. Since you implemented __get, consider adding a @property annotation.
Loading history...
22
        $this->assertInstanceOf(TestBinaryRoleHex::class, $model);
23
24
        return $model;
25
    }
26
27
    /** @test */
28
    public function validateManyModelLookup()
29
    {
30
        /**
31
         * @var TestBinaryRoleHex
32
         */
33
        $model = TestBinaryRoleHex::findMany([md5(1)])->first();
34
        $this->assertNotNull($model);
35
        $this->assertInstanceOf(TestBinaryRoleHex::class, $model);
36
37
        return $model;
38
    }
39
40
    /** @test */
41
    public function validateSingleModelLookup()
42
    {
43
        /**
44
         * @var TestBinaryRoleHex
45
         */
46
        $model = TestBinaryRoleHex::find(md5(1));
47
        $this->assertNotNull($model);
48
        $this->assertInstanceOf(TestBinaryRoleHex::class, $model);
49
50
        return $model;
51
    }
52
53
    /** @test
54
     *  @depends  validateSingleModelLookup
55
     */
56
    public function validateSingleModelLookupModel(TestBinaryRoleHex $model)
57
    {
58
        $this->assertEquals('Foo', $model->name);
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on MaksimM\CompositePrimary...Stubs\TestBinaryRoleHex. Since you implemented __get, consider adding a @property annotation.
Loading history...
59
    }
60
61
    /** @test
62
     *  @depends  validateSingleModelLookup
63
     */
64
    public function validateSingleModelUpdate(TestBinaryRoleHex $model)
65
    {
66
        $model->update([
67
            'name' => 'FooBar',
68
        ]);
69
        $model->refresh();
70
        $this->assertEquals('FooBar', $model->name);
0 ignored issues
show
Bug Best Practice introduced by
The property name does not exist on MaksimM\CompositePrimary...Stubs\TestBinaryRoleHex. Since you implemented __get, consider adding a @property annotation.
Loading history...
71
    }
72
73
    /** @test
74
     *  @depends  validateSingleModelLookup
75
     */
76
    public function validateEagerRelations(TestBinaryRoleHex $model)
77
    {
78
        $model->loadMissing(['users', 'hex_users']);
79
        $this->assertNotNull($model->toArray()['users']);
80
        $this->assertNotNull($model->toArray()['hex_users']);
81
        $this->assertNotNull($model->users);
0 ignored issues
show
Bug Best Practice introduced by
The property users does not exist on MaksimM\CompositePrimary...Stubs\TestBinaryRoleHex. Since you implemented __get, consider adding a @property annotation.
Loading history...
82
        $this->assertNotNull($model->hex_users);
0 ignored issues
show
Bug Best Practice introduced by
The property hex_users does not exist on MaksimM\CompositePrimary...Stubs\TestBinaryRoleHex. Since you implemented __get, consider adding a @property annotation.
Loading history...
83
    }
84
85
    /** @test
86
     */
87
    public function validateLazyEagerRelations()
88
    {
89
        $model = TestBinaryRoleHex::find(md5(1));
90
        $this->assertNotNull($model->users);
0 ignored issues
show
Bug Best Practice introduced by
The property users does not exist on MaksimM\CompositePrimary...Stubs\TestBinaryRoleHex. Since you implemented __get, consider adding a @property annotation.
Loading history...
91
        $this->assertNotNull($model->hex_users);
0 ignored issues
show
Bug Best Practice introduced by
The property hex_users does not exist on MaksimM\CompositePrimary...Stubs\TestBinaryRoleHex. Since you implemented __get, consider adding a @property annotation.
Loading history...
92
    }
93
}
94