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

validateSingleModelUpdate()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 4
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\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 validateSingleModelLookup()
16
    {
17
        /**
18
         * @var TestBinaryRoleHex
19
         */
20
        $model = TestBinaryRoleHex::find(md5(1));
21
        $this->assertNotNull($model);
22
        $this->assertInstanceOf(TestBinaryRoleHex::class, $model);
23
24
        return $model;
25
    }
26
27
    /** @test
28
     *  @depends  validateSingleModelLookup
29
     */
30
    public function validateSingleModelLookupModel(TestBinaryRoleHex $model)
31
    {
32
        $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...
33
    }
34
35
    /** @test
36
     *  @depends  validateSingleModelLookup
37
     */
38
    public function validateSingleModelUpdate(TestBinaryRoleHex $model)
39
    {
40
        $model->update([
41
            'name' => 'FooBar',
42
        ]);
43
        $model->refresh();
44
        $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...
45
    }
46
47
    /** @test
48
     *  @depends  validateSingleModelLookup
49
     */
50
    public function validateEagerRelations(TestBinaryRoleHex $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);
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...
56
        $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...
57
        var_dump($model->toArray());
0 ignored issues
show
Security Debugging Code introduced by
var_dump($model->toArray()) looks like debug code. Are you sure you do not want to remove it?
Loading history...
58
    }
59
60
    /** @test
61
     */
62
    public function validateLazyEagerRelations()
63
    {
64
        $model = TestBinaryRoleHex::find(md5(1));
65
        $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...
66
        $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...
67
    }
68
}
69