Completed
Push — master ( 549676...aa79ee )
by Maksim
16s queued 13s
created

UpdatesTest::incrementingBinaryTest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 4
c 0
b 0
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\TestBinaryUser;
6
use MaksimM\CompositePrimaryKeys\Tests\Stubs\TestUser;
7
8
class UpdatesTest extends CompositeKeyBaseUnit
9
{
10
    /** @test */
11
    public function validateEmptyCounter()
12
    {
13
        /**
14
         * @var TestUser
15
         */
16
        $model = TestUser::find([
17
            'user_id'         => 1,
18
            'organization_id' => 100,
19
        ]);
20
        $this->assertNotNull($model);
21
        $this->assertInstanceOf(TestUser::class, $model);
22
        $this->assertEquals(0, $model->counter);
23
24
        return $model;
25
    }
26
27
    /** @test
28
     *  @depends validateEmptyCounter
29
     */
30
    public function incrementingTest(TestUser $model)
31
    {
32
        $model->increment('counter');
33
        $model->refresh();
34
        $this->assertEquals(1, $model->counter);
35
36
        return $model;
37
    }
38
39
    /** @test
40
     *  @depends validateEmptyCounter
41
     */
42
    public function incrementingBinaryTest(TestBinaryUser $model)
43
    {
44
        $model->increment('counter');
45
        $model->refresh();
46
        $this->assertEquals(1, $model->counter);
47
48
        return $model;
49
    }
50
51
    /** @test
52
     *  @depends validateEmptyCounter
53
     */
54
    public function decrementingTest(TestUser $model)
55
    {
56
        $model->decrement('counter');
57
        $model->refresh();
58
        $this->assertEquals(-1, $model->counter);
59
    }
60
61
    /** @test
62
     *  @depends validateEmptyCounter
63
     */
64
    public function updateTest(TestUser $model)
65
    {
66
        $model->update([
67
            'counter' => 9999,
68
        ]);
69
        $model->refresh();
70
        $this->assertEquals(9999, $model->counter);
71
    }
72
73
    /** @test
74
     *  @depends validateEmptyCounter
75
     */
76
    public function saveTest(TestUser $model)
77
    {
78
        $this->assertTrue($model->exists);
79
        $model->counter = 6666;
80
        $model->save();
81
        $model->refresh();
82
        $this->assertEquals(6666, $model->counter);
83
    }
84
}
85