Test node bundle

This commit is contained in:
Oliver Davies 2024-01-20 09:23:06 +00:00
parent e09fdbe5d0
commit 196b1f1517
2 changed files with 21 additions and 0 deletions

View file

@ -0,0 +1,16 @@
<?php
namespace Drupal\example;
use Drupal\node\NodeInterface;
final class PostWrapper {
public function __construct(private NodeInterface $post) {
}
public function getType(): string {
return $this->post->bundle();
}
}

View file

@ -2,6 +2,7 @@
namespace Drupal\Tests\example\Unit;
use Drupal\example\PostWrapper;
use Drupal\node\NodeInterface;
use Drupal\Tests\UnitTestCase;
@ -15,8 +16,12 @@ final class PostWrapperTest extends UnitTestCase {
$node = $this->createMock(NodeInterface::class);
$node->method('bundle')->willReturn('post');
$wrapper = new PostWrapper($node);
self::assertInstanceOf(NodeInterface::class, $node);
self::assertSame('post', $node->bundle());
self::assertSame('post', $wrapper->getType());
}
}