From 4be8e022462736a69b78907b16db7e886cfab5ab Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 14 Nov 2020 12:44:42 +0000 Subject: [PATCH] Only articles should be used for Posts An Exception should be thrown if the node passed to the `Post` entity is not an article. > Drupal\Tests\my_module\Unit\Entity\PostTest::it_throws_an_exception_if_the_node_is_not_an_article > Failed asserting that exception of type "InvalidArgumentException" is thrown. --- .../my_module/tests/src/Unit/Entity/PostTest.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/web/modules/custom/my_module/tests/src/Unit/Entity/PostTest.php b/web/modules/custom/my_module/tests/src/Unit/Entity/PostTest.php index 11c990d..1bbb779 100644 --- a/web/modules/custom/my_module/tests/src/Unit/Entity/PostTest.php +++ b/web/modules/custom/my_module/tests/src/Unit/Entity/PostTest.php @@ -21,4 +21,15 @@ class PostTest extends UnitTestCase { $this->assertSame('Test post', $post->getTitle()); } + /** @test */ + public function it_throws_an_exception_if_the_node_is_not_an_article() { + $node = $this->createMock(NodeInterface::class); + + $node->method('bundle')->willReturn('page'); + + $this->expectException(\InvalidArgumentException::class); + + new Post($node); + } + }