Skip to content

Commit

Permalink
- Update tests to Laravel 5.4
Browse files Browse the repository at this point in the history
- Bugfix
  • Loading branch information
hootlex committed Feb 10, 2017
1 parent 09574fa commit 2870f35
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 30 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"autoload-dev": {
"classmap": [
"tests",
"vendor/laravel/laravel/tests/TestCase.php"
"vendor/laravel/laravel/tests"
]
},
"require": {
Expand Down
8 changes: 0 additions & 8 deletions src/ModerationScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,14 +98,6 @@ public function extend(Builder $builder)
foreach ($this->extensions as $extension) {
$this->{"add{$extension}"}($builder);
}

$builder->onDelete(function (Builder $builder) {
$column = $builder->getModel()->getModeratedAtColumn();

return $builder->update([
$column => $builder->getModel()->freshTimestampString(),
]);
});
}

/**
Expand Down
4 changes: 3 additions & 1 deletion tests/BaseTestCase.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<?php

use Hootlex\Moderation\Tests\Post;
use Tests\TestCase;


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

Expand Down
16 changes: 8 additions & 8 deletions tests/ModerationScopeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ public function it_approves_stories()
(new Post)->newQueryWithoutScope(new ModerationScope)->whereIn('id', $postsIds)->approve();

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

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

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

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

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

Expand All @@ -194,7 +194,7 @@ public function it_approves_a_story_by_id()

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

$this->seeInDatabase('posts',
$this->assertDatabaseHas('posts',
[
'id' => $post->id,
$this->status_column => Status::APPROVED,
Expand All @@ -209,7 +209,7 @@ public function it_rejects_a_story_by_id()

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

$this->seeInDatabase('posts',
$this->assertDatabaseHas('posts',
[
'id' => $post->id,
$this->status_column => Status::REJECTED,
Expand All @@ -224,7 +224,7 @@ public function it_postpones_a_story_by_id()

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

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

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

foreach ($posts as $post) {
$this->seeInDatabase('posts',
$this->assertDatabaseHas('posts',
[
'id' => $post->id,
$this->moderated_by_column => \Auth::user()->id
Expand Down
24 changes: 12 additions & 12 deletions tests/ModerationTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function it_approves_a_story_by_id()

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

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

Expand All @@ -84,7 +84,7 @@ public function it_rejects_a_story_by_id()

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

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

Expand All @@ -95,7 +95,7 @@ public function it_postpones_a_story_by_id()

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

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

Expand All @@ -106,7 +106,7 @@ public function it_pendings_a_story_by_id()

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

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

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

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

/** @test */
Expand All @@ -192,9 +192,9 @@ public function it_deletes_resources_of_any_status(){
$post->delete();
}

$this->dontSeeInDatabase('posts',['id' => $posts[0]->id]);
$this->dontSeeInDatabase('posts',['id' => $posts[1]->id]);
$this->dontSeeInDatabase('posts',['id' => $posts[2]->id]);
$this->assertDatabaseMissing('posts',['id' => $posts[0]->id]);
$this->assertDatabaseMissing('posts',['id' => $posts[1]->id]);
$this->assertDatabaseMissing('posts',['id' => $posts[2]->id]);
}

/** @test */
Expand All @@ -206,7 +206,7 @@ public function it_marks_as_approved_an_instance()

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

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

Expand All @@ -219,7 +219,7 @@ public function it_marks_as_rejected_an_instance()

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

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

Expand All @@ -232,7 +232,7 @@ public function it_marks_as_postponed_an_instance()

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

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

Expand All @@ -245,7 +245,7 @@ public function it_marks_as_pending_an_instance()

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

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

Expand Down

0 comments on commit 2870f35

Please sign in to comment.