Issues (64)

tests/SingleKeyBinaryModelHexTest.php (9 issues)

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
    /** @test
95
     *  @depends  validateSingleModelLookup
96
     */
97
    public function incrementingTest(TestBinaryRoleHex $model)
98
    {
99
        $model->increment('counter');
100
        $model->refresh();
101
        $this->assertEquals(1, $model->counter);
0 ignored issues
show
Bug Best Practice introduced by
The property counter does not exist on MaksimM\CompositePrimary...Stubs\TestBinaryRoleHex. Since you implemented __get, consider adding a @property annotation.
Loading history...
102
    }
103
104
    /** @test
105
     *  @depends validateSingleModelLookup
106
     */
107
    public function decrementingTest(TestBinaryRoleHex $model)
108
    {
109
        $model->decrement('counter');
110
        $model->refresh();
111
        $this->assertEquals(-1, $model->counter);
0 ignored issues
show
Bug Best Practice introduced by
The property counter does not exist on MaksimM\CompositePrimary...Stubs\TestBinaryRoleHex. Since you implemented __get, consider adding a @property annotation.
Loading history...
112
    }
113
}
114