1 | <?php |
||
2 | |||
3 | namespace MaksimM\CompositePrimaryKeys\Tests; |
||
4 | |||
5 | use MaksimM\CompositePrimaryKeys\Tests\Stubs\TestBinaryUser; |
||
6 | use MaksimM\CompositePrimaryKeys\Tests\Stubs\TestBinaryUserHex; |
||
7 | use MaksimM\CompositePrimaryKeys\Tests\Stubs\TestUser; |
||
8 | |||
9 | class UpdatesTest extends CompositeKeyBaseUnit |
||
10 | { |
||
11 | /** @test */ |
||
12 | public function validateEmptyCounter() |
||
13 | { |
||
14 | /** |
||
15 | * @var TestUser |
||
16 | */ |
||
17 | $model = TestUser::find([ |
||
18 | 'user_id' => 1, |
||
19 | 'organization_id' => 100, |
||
20 | ]); |
||
21 | $this->assertNotNull($model); |
||
22 | $this->assertInstanceOf(TestUser::class, $model); |
||
23 | $this->assertEquals(0, $model->counter); |
||
24 | |||
25 | return $model; |
||
26 | } |
||
27 | |||
28 | /** @test */ |
||
29 | public function validateEmptyCounterBinaryModel() |
||
30 | { |
||
31 | /** |
||
32 | * @var TestBinaryUser |
||
33 | */ |
||
34 | $model = TestBinaryUser::find([ |
||
35 | 'user_id' => md5(20000, true), |
||
36 | 'organization_id' => 100, |
||
37 | ]); |
||
38 | $this->assertNotNull($model); |
||
39 | $this->assertInstanceOf(TestBinaryUser::class, $model); |
||
40 | $this->assertEquals(0, $model->counter); |
||
41 | |||
42 | return $model; |
||
43 | } |
||
44 | |||
45 | /** @test */ |
||
46 | public function validateEmptyCounterBinaryModelHex() |
||
47 | { |
||
48 | /** |
||
49 | * @var TestBinaryUserHex |
||
50 | */ |
||
51 | $model = TestBinaryUserHex::find([ |
||
52 | 'user_id' => md5(20000), |
||
53 | 'organization_id' => 100, |
||
54 | ]); |
||
55 | $this->assertNotNull($model); |
||
56 | $this->assertInstanceOf(TestBinaryUserHex::class, $model); |
||
57 | $this->assertEquals(0, $model->counter); |
||
58 | |||
59 | return $model; |
||
60 | } |
||
61 | |||
62 | /** @test |
||
63 | * @depends validateEmptyCounter |
||
64 | */ |
||
65 | public function incrementingTest(TestUser $model) |
||
66 | { |
||
67 | $model->increment('counter'); |
||
68 | $model->refresh(); |
||
69 | $this->assertEquals(1, $model->counter); |
||
70 | |||
71 | return $model; |
||
72 | } |
||
73 | |||
74 | /** @test |
||
75 | * @depends validateEmptyCounter |
||
76 | */ |
||
77 | public function decrementingTest(TestUser $model) |
||
78 | { |
||
79 | $model->decrement('counter'); |
||
80 | $model->refresh(); |
||
81 | $this->assertEquals(-1, $model->counter); |
||
82 | } |
||
83 | |||
84 | /** @test |
||
85 | * @depends validateEmptyCounterBinaryModel |
||
86 | */ |
||
87 | public function incrementingBinaryTest(TestBinaryUser $model) |
||
88 | { |
||
89 | $model->increment('counter'); |
||
90 | $model->refresh(); |
||
91 | $this->assertEquals(1, $model->counter); |
||
92 | |||
93 | return $model; |
||
94 | } |
||
95 | |||
96 | /** @test |
||
97 | * @depends validateEmptyCounterBinaryModel |
||
98 | */ |
||
99 | public function decrementingBinaryTest(TestBinaryUser $model) |
||
100 | { |
||
101 | $model->decrement('counter'); |
||
102 | $model->refresh(); |
||
103 | $this->assertEquals(-1, $model->counter); |
||
104 | |||
105 | return $model; |
||
106 | } |
||
107 | |||
108 | /** @test |
||
109 | * @depends validateEmptyCounterBinaryModelHex |
||
110 | */ |
||
111 | public function incrementingBinaryHexTest(TestBinaryUserHex $model) |
||
112 | { |
||
113 | $model->increment('counter'); |
||
114 | $model->refresh(); |
||
115 | $this->assertEquals(1, $model->counter); |
||
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
116 | |||
117 | return $model; |
||
118 | } |
||
119 | |||
120 | /** @test |
||
121 | * @depends validateEmptyCounterBinaryModelHex |
||
122 | */ |
||
123 | public function decrementingBinaryHexTest(TestBinaryUserHex $model) |
||
124 | { |
||
125 | $model->decrement('counter'); |
||
126 | $model->refresh(); |
||
127 | $this->assertEquals(-1, $model->counter); |
||
0 ignored issues
–
show
The property
counter does not exist on MaksimM\CompositePrimary...Stubs\TestBinaryUserHex . Since you implemented __get , consider adding a @property annotation.
![]() |
|||
128 | |||
129 | return $model; |
||
130 | } |
||
131 | |||
132 | /** @test |
||
133 | * @depends validateEmptyCounter |
||
134 | */ |
||
135 | public function updateTest(TestUser $model) |
||
136 | { |
||
137 | $model->update([ |
||
138 | 'counter' => 9999, |
||
139 | ]); |
||
140 | $model->refresh(); |
||
141 | $this->assertEquals(9999, $model->counter); |
||
142 | } |
||
143 | |||
144 | /** @test |
||
145 | * @depends validateEmptyCounter |
||
146 | */ |
||
147 | public function saveTest(TestUser $model) |
||
148 | { |
||
149 | $this->assertTrue($model->exists); |
||
150 | $model->counter = 6666; |
||
151 | $model->save(); |
||
152 | $model->refresh(); |
||
153 | $this->assertEquals(6666, $model->counter); |
||
154 | } |
||
155 | } |
||
156 |