5c: Add the node as a constructor argument

> Undefined variable: node
This commit is contained in:
Oliver Davies 2020-11-14 10:01:36 +00:00
parent 1fe7119b5d
commit 61664cb263
2 changed files with 9 additions and 1 deletions

View file

@ -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 '';
}

View file

@ -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());
}