Skip to content

Commit

Permalink
Merge pull request #4018 from HungDV2022/unittest_BlogCommentsService…
Browse files Browse the repository at this point in the history
…_sendCommentToAdmin

BlogCommentsService::sendCommentToAdmin() ユニットテスト
  • Loading branch information
HungDV2022 authored Nov 15, 2024
2 parents ee46dfc + a5f6555 commit 56f0eba
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
3 changes: 2 additions & 1 deletion plugins/bc-blog/src/Service/BlogCommentsService.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ public function getNew()
* @param array $postData
* @return EntityInterface
* @checked
* @unitTest
* @unitTest
*/
public function add(int $blogContentId, int $blogPostId, array $postData)
{
Expand Down Expand Up @@ -213,6 +213,7 @@ public function getBlogContent($blogContentId)
* @throws \Throwable
* @checked
* @noTodo
* @unitTest
*/
public function sendCommentToAdmin(EntityInterface $entity)
{
Expand Down
28 changes: 28 additions & 0 deletions plugins/bc-blog/tests/TestCase/Service/BlogCommentsServiceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

namespace BcBlog\Test\TestCase\Service;

use BaserCore\Test\Factory\SiteConfigFactory;
use BaserCore\Test\Factory\SiteFactory;
use BaserCore\TestSuite\BcTestCase;
use BcBlog\Service\BlogCommentsService;
use BcBlog\Test\Factory\BlogCommentFactory;
Expand Down Expand Up @@ -299,4 +301,30 @@ public function testAdd()
$this->BlogCommentsService->add(1, 1, []);
}

/**
* test sendCommentToAdmin
*/
public function testSendCommentToAdmin()
{
//データー生成
SiteConfigFactory::make(['name' => 'email', 'value' => '[email protected]'])->persist();
SiteFactory::make(['id' => 1])->persist();
$this->loadFixtureScenario(
BlogContentScenario::class,
1, // id
1, // siteId
null, // parentId
'news1', // name
'/news/' // url
);
BlogPostFactory::make(['id' => 1, 'blog_content_id' => 1, 'status' => true])->persist();
$blogComment = BlogCommentFactory::make([['blog_content_id' => 1, 'blog_post_id' => 1, 'no' => 1, 'status' => 1,]])->getEntity();

//正常テスト
$this->BlogCommentsService->sendCommentToAdmin($blogComment);

//異常テスト
$this->expectException(\TypeError::class);
$this->BlogCommentsService->sendCommentToAdmin([]);
}
}

0 comments on commit 56f0eba

Please sign in to comment.