Skip to content

Commit

Permalink
Add test List specific_update_item_method_is_called
Browse files Browse the repository at this point in the history
  • Loading branch information
dvlpp committed Nov 30, 2015
1 parent ab13da7 commit 7f83e36
Showing 1 changed file with 36 additions and 3 deletions.
39 changes: 36 additions & 3 deletions tests/ListValuatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public function specific_create_item_method_is_called()
{
$post = factory(TestListPostModel::class)->create();

$sharpRepo = Mockery::mock(TestListRepository::class);
$sharpRepo = Mockery::mock(TestListRepositoryCreate::class);
$sharpRepo->shouldReceive("createCommentsListItem")
->once()
->andReturn(
Expand All @@ -152,6 +152,33 @@ public function specific_create_item_method_is_called()
->valuate();
}

/** @test */
public function specific_update_item_method_is_called()
{
$post = factory(TestListPostModel::class)->create([]);
$comment = factory(TestListCommentModel::class)->create([
"post_id" => $post->id
]);

$sharpRepo = Mockery::mock(TestListRepositoryUpdate::class);
$sharpRepo->shouldReceive("updateCommentsListItem")
->once()
->andReturn($comment);

$listConfig = SharpListFormFieldConfig::create("comments")
->addItemFormField(
SharpTextareaFormFieldConfig::create("body")
);

(new ListValuator($post, "comments", [
$comment->id => [
"id" => $comment->id,
"body" => "some test body"
]
], $listConfig, $sharpRepo, new SharpEloquentAutoUpdaterService))
->valuate();
}

private function migrateDatabase()
{
\Schema::create('posts', function (Blueprint $table) {
Expand Down Expand Up @@ -203,8 +230,14 @@ public function post()
}
}

abstract class TestListRepository implements SharpCmsRepository {
abstract class TestListRepositoryCreate implements SharpCmsRepository {

function createCommentsListItem(){}

}

abstract class TestListRepositoryUpdate implements SharpCmsRepository {

function createCommentsListItem($item){}
function updateCommentsListItem(){}

}

0 comments on commit 7f83e36

Please sign in to comment.