Passed
Pull Request — master (#8)
by Maksim
02:53
created

SingleKeyBinaryModelHexTest::getEnvironmentSetUp()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
eloc 1
c 1
b 1
f 0
dl 0
loc 3
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 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 validateSingleModelLookup()
29
    {
30
        /**
31
         * @var TestBinaryRoleHex
32
         */
33
        $model = TestBinaryRoleHex::find(md5(1));
34
        $this->assertNotNull($model);
35
        $this->assertInstanceOf(TestBinaryRoleHex::class, $model);
36
37
        return $model;
38
    }
39
40
    /** @test
41
     *  @depends  validateSingleModelLookup
42
     */
43
    public function validateSingleModelLookupModel(TestBinaryRoleHex $model)
44
    {
45
        $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...
46
    }
47
48
    /** @test
49
     *  @depends  validateSingleModelLookup
50
     */
51
    public function validateSingleModelUpdate(TestBinaryRoleHex $model)
52
    {
53
        $model->update([
54
            'name' => 'FooBar',
55
        ]);
56
        $model->refresh();
57
        $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...
58
    }
59
60
    /** @test
61
     *  @depends  validateSingleModelLookup
62
     */
63
    public function validateEagerRelations(TestBinaryRoleHex $model)
64
    {
65
        $model->loadMissing(['users', 'hex_users']);
66
        $this->assertNotNull($model->toArray()['users']);
67
        $this->assertNotNull($model->toArray()['hex_users']);
68
        $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...
69
        $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...
70
        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...
71
    }
72
73
    /** @test
74
     */
75
    public function validateLazyEagerRelations()
76
    {
77
        $model = TestBinaryRoleHex::find(md5(1));
78
        $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...
79
        $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...
80
    }
81
}
82