SingleKeyBinaryModelTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 92
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 0
Metric Value
wmc 9
eloc 29
c 2
b 1
f 0
dl 0
loc 92
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A getEnvironmentSetUp() 0 3 1
A validateSingleModelUpdate() 0 7 1
A validateSingleModelLookup() 0 10 1
A automaticBinaryKeysOnCreation() 0 10 1
A validateLazyEagerRelations() 0 5 1
A validateEagerRelations() 0 7 1
A validateSingleModelLookupModel() 0 3 1
A decrementingTest() 0 5 1
A incrementingTest() 0 5 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 automaticBinaryKeysOnCreation()
16
    {
17
        /**
18
         * @var TestBinaryRole
19
         */
20
        $model = TestBinaryRole::create(['name' => 'Zoo']);
21
        $this->assertNotNull($model->role_id);
22
        $this->assertInstanceOf(TestBinaryRole::class, $model);
23
24
        return $model;
25
    }
26
27
    /** @test */
28
    public function validateSingleModelLookup()
29
    {
30
        /**
31
         * @var TestBinaryRole
32
         */
33
        $model = TestBinaryRole::find(md5(1, true));
34
        $this->assertNotNull($model);
35
        $this->assertInstanceOf(TestBinaryRole::class, $model);
36
37
        return $model;
38
    }
39
40
    /** @test
41
     *  @depends  validateSingleModelLookup
42
     */
43
    public function validateSingleModelLookupModel(TestBinaryRole $model)
44
    {
45
        $this->assertEquals('Foo', $model->name);
46
    }
47
48
    /** @test
49
     *  @depends  validateSingleModelLookup
50
     */
51
    public function validateSingleModelUpdate(TestBinaryRole $model)
52
    {
53
        $model->update([
54
            'name' => 'FooBar',
55
        ]);
56
        $model->refresh();
57
        $this->assertEquals('FooBar', $model->name);
58
    }
59
60
    /** @test
61
     *  @depends  validateSingleModelLookup
62
     */
63
    public function validateEagerRelations(TestBinaryRole $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);
69
        $this->assertNotNull($model->hex_users);
70
    }
71
72
    /** @test
73
     */
74
    public function validateLazyEagerRelations()
75
    {
76
        $model = TestBinaryRole::find(md5(1, true));
77
        $this->assertNotNull($model->users);
78
        $this->assertNotNull($model->hex_users);
79
    }
80
81
    /** @test
82
     *  @depends  validateSingleModelLookup
83
     */
84
    public function incrementingTest(TestBinaryRole $model)
85
    {
86
        $model->increment('counter');
87
        $model->refresh();
88
        $this->assertEquals(1, $model->counter);
89
    }
90
91
    /** @test
92
     *  @depends validateSingleModelLookup
93
     */
94
    public function decrementingTest(TestBinaryRole $model)
95
    {
96
        $model->decrement('counter');
97
        $model->refresh();
98
        $this->assertEquals(-1, $model->counter);
99
    }
100
}
101