From ab13da7315091783b3e94dc37479567732cf5946 Mon Sep 17 00:00:00 2001 From: Philippe Lonchampt Date: Mon, 30 Nov 2015 22:24:26 +0100 Subject: [PATCH] Test List specific_create_item_method_is_called --- tests/ListValuatorTest.php | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/tests/ListValuatorTest.php b/tests/ListValuatorTest.php index 01754c5..5df3f04 100644 --- a/tests/ListValuatorTest.php +++ b/tests/ListValuatorTest.php @@ -124,25 +124,31 @@ public function list_items_order_is_managed() } /** @test */ - function specific_create_item_method_is_called() + public function specific_create_item_method_is_called() { $post = factory(TestListPostModel::class)->create(); - $sharpRepo = Mockery::mock(SharpCmsRepository::class)->makePartial(); - $sharpRepo->shouldReceive("createCommentsListItem")->once(); + $sharpRepo = Mockery::mock(TestListRepository::class); + $sharpRepo->shouldReceive("createCommentsListItem") + ->once() + ->andReturn( + factory(TestListCommentModel::class)->create([ + "post_id" => $post->id + ]) + ); + $listConfig = SharpListFormFieldConfig::create("comments") ->setAddable(true) ->addItemFormField( SharpTextareaFormFieldConfig::create("body") ); - $autoUpdater = new SharpEloquentAutoUpdaterService(); (new ListValuator($post, "comments", [ "N_1" => [ "id" => "N_1", "body" => "some test body" ] - ], $listConfig, $sharpRepo, $autoUpdater)) + ], $listConfig, $sharpRepo, new SharpEloquentAutoUpdaterService)) ->valuate(); } @@ -195,4 +201,10 @@ public function post() { return $this->belongsTo(TestListPostModel::class, "post_id"); } +} + +abstract class TestListRepository implements SharpCmsRepository { + + function createCommentsListItem($item){} + } \ No newline at end of file