From 61664cb2639cc819d71a678ba22fca36a3563b85 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Sat, 14 Nov 2020 10:01:36 +0000 Subject: [PATCH] 5c: Add the node as a constructor argument > Undefined variable: node --- web/modules/custom/my_module/src/Entity/Post.php | 8 ++++++++ .../custom/my_module/tests/src/Unit/Entity/PostTest.php | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/web/modules/custom/my_module/src/Entity/Post.php b/web/modules/custom/my_module/src/Entity/Post.php index 315c676..b3cc15b 100644 --- a/web/modules/custom/my_module/src/Entity/Post.php +++ b/web/modules/custom/my_module/src/Entity/Post.php @@ -2,8 +2,16 @@ namespace Drupal\my_module\Entity; +use Drupal\node\NodeInterface; + class Post { + private $node; + + public function __construct(NodeInterface $node) { + $this->node = $node; + } + public function getTitle(): string { return ''; } 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 254408a..841dd29 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 @@ -9,7 +9,7 @@ class PostTest extends UnitTestCase { /** @test */ public function it_returns_the_title() { - $post = new Post(); + $post = new Post($node); $this->assertSame('Test post', $post->getTitle()); }