Skip to content

Commit

Permalink
fix #1654 BlogPostsService::getNew のユニットテスト実装 (#1752)
Browse files Browse the repository at this point in the history
  • Loading branch information
HungDV2022 committed Jan 16, 2023
1 parent eeddc27 commit 9d7353b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 1 addition & 0 deletions plugins/bc-blog/src/Service/BlogPostsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -465,6 +465,7 @@ public function createAuthorCondition($conditions, $author)
* @return EntityInterface
* @checked
* @noTodo
* @unitTest
*/
public function getNew(int $blogContentId, int $userId)
{
Expand Down
20 changes: 19 additions & 1 deletion plugins/bc-blog/tests/TestCase/Service/BlogPostsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use BcBlog\Test\Factory\BlogPostFactory;
use BcBlog\Test\Factory\BlogTagFactory;
use Cake\Datasource\Exception\RecordNotFoundException;
use Cake\I18n\FrozenTime;

/**
* BlogPostsServiceTest
Expand Down Expand Up @@ -452,7 +453,24 @@ public function testGetRelatedPosts()
*/
public function testGetNew()
{
$this->markTestIncomplete('このテストは、まだ実装されていません。');
//データ生成
BlogPostFactory::make([])->publish(1, 1)->persist();

// サービスメソッドを呼ぶ
$result = $this->BlogPostsService->getNew(2, 1);
//戻り値を確認

//user_idが生成できるか確認
$this->assertEquals("1", $result->user_id);

//postedが生成できるか確認
$this->assertEquals(FrozenTime::now()->i18nFormat('yyyy-MM-dd'), $result->posted->i18nFormat('yyyy-MM-dd'));

//statusが生成できるか確認
$this->assertEquals(false, $result->status);

//blog_content_idが生成できるか確認
$this->assertEquals(2, $result->blog_content_id);
}

/**
Expand Down

0 comments on commit 9d7353b

Please sign in to comment.