From bd68420fc10e446fd25921d8ad0eab93c88a83ae Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 14 Nov 2020 10:03:34 +0000 Subject: [PATCH] 5d: Create a mock node > TypeError: Return value of Drupal\my_module\Entity\Post::getTitle() > must be of the type string, null returned --- .../custom/my_module/tests/src/Unit/Entity/PostTest.php | 3 +++ 1 file changed, 3 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 841dd29..4ab5273 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 @@ -3,12 +3,15 @@ namespace Drupal\Tests\my_module\Unit\Entity; use Drupal\my_module\Entity\Post; +use Drupal\node\NodeInterface; use Drupal\Tests\UnitTestCase; class PostTest extends UnitTestCase { /** @test */ public function it_returns_the_title() { + $node = $this->createMock(NodeInterface::class); + $post = new Post($node); $this->assertSame('Test post', $post->getTitle());