Skip to content

Commit 2870f35

Browse files
committed
- Update tests to Laravel 5.4
- Bugfix
1 parent 09574fa commit 2870f35

File tree

5 files changed

+24
-30
lines changed

5 files changed

+24
-30
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
"autoload-dev": {
1313
"classmap": [
1414
"tests",
15-
"vendor/laravel/laravel/tests/TestCase.php"
15+
"vendor/laravel/laravel/tests"
1616
]
1717
},
1818
"require": {

src/ModerationScope.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,6 @@ public function extend(Builder $builder)
9898
foreach ($this->extensions as $extension) {
9999
$this->{"add{$extension}"}($builder);
100100
}
101-
102-
$builder->onDelete(function (Builder $builder) {
103-
$column = $builder->getModel()->getModeratedAtColumn();
104-
105-
return $builder->update([
106-
$column => $builder->getModel()->freshTimestampString(),
107-
]);
108-
});
109101
}
110102

111103
/**

tests/BaseTestCase.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22

33
use Hootlex\Moderation\Tests\Post;
4+
use Tests\TestCase;
5+
46

57
abstract class BaseTestCase extends TestCase
68
{
@@ -14,7 +16,7 @@ function createPost($overrides = [], $amount = 1)
1416
{
1517
$posts = new \Illuminate\Database\Eloquent\Collection;
1618
for ($i = 0; $i < $amount; $i++) {
17-
$post = Post::create(array_merge(['moderated_at' => 0], $overrides));
19+
$post = Post::create(array_merge(['moderated_at' => \Carbon\Carbon::now()], $overrides));
1820
$posts->push($post);
1921
}
2022

tests/ModerationScopeTest.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public function it_approves_stories()
157157
(new Post)->newQueryWithoutScope(new ModerationScope)->whereIn('id', $postsIds)->approve();
158158

159159
foreach ($postsIds as $postId) {
160-
$this->seeInDatabase('posts', ['id' => $postId, $this->status_column => Status::APPROVED]);
160+
$this->assertDatabaseHas('posts', ['id' => $postId, $this->status_column => Status::APPROVED]);
161161
}
162162
}
163163

@@ -170,7 +170,7 @@ public function it_rejects_stories()
170170
(new Post)->newQueryWithoutScope(new ModerationScope)->whereIn('id', $postsIds)->reject();
171171

172172
foreach ($postsIds as $postId) {
173-
$this->seeInDatabase('posts', ['id' => $postId, $this->status_column => Status::REJECTED]);
173+
$this->assertDatabaseHas('posts', ['id' => $postId, $this->status_column => Status::REJECTED]);
174174
}
175175
}
176176

@@ -183,7 +183,7 @@ public function it_postpones_stories()
183183
(new Post)->newQueryWithoutScope(new ModerationScope)->whereIn('id', $postsIds)->postpone();
184184

185185
foreach ($postsIds as $postId) {
186-
$this->seeInDatabase('posts', ['id' => $postId, $this->status_column => Status::POSTPONED]);
186+
$this->assertDatabaseHas('posts', ['id' => $postId, $this->status_column => Status::POSTPONED]);
187187
}
188188
}
189189

@@ -194,7 +194,7 @@ public function it_approves_a_story_by_id()
194194

195195
(new Post)->newQueryWithoutScope(new ModerationScope)->approve($post->id);
196196

197-
$this->seeInDatabase('posts',
197+
$this->assertDatabaseHas('posts',
198198
[
199199
'id' => $post->id,
200200
$this->status_column => Status::APPROVED,
@@ -209,7 +209,7 @@ public function it_rejects_a_story_by_id()
209209

210210
(new Post)->newQueryWithoutScope(new ModerationScope)->reject($post->id);
211211

212-
$this->seeInDatabase('posts',
212+
$this->assertDatabaseHas('posts',
213213
[
214214
'id' => $post->id,
215215
$this->status_column => Status::REJECTED,
@@ -224,7 +224,7 @@ public function it_postpones_a_story_by_id()
224224

225225
(new Post)->newQueryWithoutScope(new ModerationScope)->postpone($post->id);
226226

227-
$this->seeInDatabase('posts',
227+
$this->assertDatabaseHas('posts',
228228
[
229229
'id' => $post->id,
230230
$this->status_column => Status::POSTPONED,
@@ -245,7 +245,7 @@ public function it_updates_moderated_by_column_on_status_update()
245245
(new Post)->newQueryWithoutScope(new ModerationScope)->where('id', '=', $posts[2]->id)->reject();
246246

247247
foreach ($posts as $post) {
248-
$this->seeInDatabase('posts',
248+
$this->assertDatabaseHas('posts',
249249
[
250250
'id' => $post->id,
251251
$this->moderated_by_column => \Auth::user()->id
@@ -266,7 +266,7 @@ public function it_updates_moderated_by_column_on_status_update_by_id()
266266
(new Post)->newQueryWithoutScope(new ModerationScope)->reject($posts[2]->id);
267267

268268
foreach ($posts as $post) {
269-
$this->seeInDatabase('posts',
269+
$this->assertDatabaseHas('posts',
270270
[
271271
'id' => $post->id,
272272
$this->moderated_by_column => \Auth::user()->id

tests/ModerationTraitTest.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ public function it_approves_a_story_by_id()
7373

7474
Post::approve($post->id);
7575

76-
$this->seeInDatabase('posts',
76+
$this->assertDatabaseHas('posts',
7777
['id' => $post->id, $this->status_column => Status::APPROVED, $this->moderated_at_column => \Carbon\Carbon::now()]);
7878
}
7979

@@ -84,7 +84,7 @@ public function it_rejects_a_story_by_id()
8484

8585
Post::reject($post->id);
8686

87-
$this->seeInDatabase('posts',
87+
$this->assertDatabaseHas('posts',
8888
['id' => $post->id, $this->status_column => Status::REJECTED, $this->moderated_at_column => \Carbon\Carbon::now()]);
8989
}
9090

@@ -95,7 +95,7 @@ public function it_postpones_a_story_by_id()
9595

9696
Post::postpone($post->id);
9797

98-
$this->seeInDatabase('posts',
98+
$this->assertDatabaseHas('posts',
9999
['id' => $post->id, $this->status_column => Status::POSTPONED, $this->moderated_at_column => \Carbon\Carbon::now()]);
100100
}
101101

@@ -106,7 +106,7 @@ public function it_pendings_a_story_by_id()
106106

107107
Post::pend($post->id);
108108

109-
$this->seeInDatabase('posts',
109+
$this->assertDatabaseHas('posts',
110110
['id' => $post->id, $this->status_column => Status::PENDING, $this->moderated_at_column => \Carbon\Carbon::now()]);
111111
}
112112

@@ -178,7 +178,7 @@ public function it_deletes_rejected_resources(){
178178
$postDel = Post::withRejected()->where('id', $post->id)->first();
179179
$postDel->delete();
180180

181-
$this->dontSeeInDatabase('posts',['id' => $post->id]);
181+
$this->assertDatabaseMissing('posts',['id' => $post->id]);
182182
}
183183

184184
/** @test */
@@ -192,9 +192,9 @@ public function it_deletes_resources_of_any_status(){
192192
$post->delete();
193193
}
194194

195-
$this->dontSeeInDatabase('posts',['id' => $posts[0]->id]);
196-
$this->dontSeeInDatabase('posts',['id' => $posts[1]->id]);
197-
$this->dontSeeInDatabase('posts',['id' => $posts[2]->id]);
195+
$this->assertDatabaseMissing('posts',['id' => $posts[0]->id]);
196+
$this->assertDatabaseMissing('posts',['id' => $posts[1]->id]);
197+
$this->assertDatabaseMissing('posts',['id' => $posts[2]->id]);
198198
}
199199

200200
/** @test */
@@ -206,7 +206,7 @@ public function it_marks_as_approved_an_instance()
206206

207207
$this->assertEquals(Status::APPROVED, $post->status);
208208

209-
$this->seeInDatabase('posts',
209+
$this->assertDatabaseHas('posts',
210210
['id' => $post->id, $this->status_column => Status::APPROVED, $this->moderated_at_column => \Carbon\Carbon::now()]);
211211
}
212212

@@ -219,7 +219,7 @@ public function it_marks_as_rejected_an_instance()
219219

220220
$this->assertEquals(Status::REJECTED, $post->status);
221221

222-
$this->seeInDatabase('posts',
222+
$this->assertDatabaseHas('posts',
223223
['id' => $post->id, $this->status_column => Status::REJECTED, $this->moderated_at_column => \Carbon\Carbon::now()]);
224224
}
225225

@@ -232,7 +232,7 @@ public function it_marks_as_postponed_an_instance()
232232

233233
$this->assertEquals(Status::POSTPONED, $post->status);
234234

235-
$this->seeInDatabase('posts',
235+
$this->assertDatabaseHas('posts',
236236
['id' => $post->id, $this->status_column => Status::POSTPONED, $this->moderated_at_column => \Carbon\Carbon::now()]);
237237
}
238238

@@ -245,7 +245,7 @@ public function it_marks_as_pending_an_instance()
245245

246246
$this->assertEquals(Status::PENDING, $post->status);
247247

248-
$this->seeInDatabase('posts',
248+
$this->assertDatabaseHas('posts',
249249
['id' => $post->id, $this->status_column => Status::PENDING, $this->moderated_at_column => \Carbon\Carbon::now()]);
250250
}
251251

0 commit comments

Comments
 (0)