4l: Expect a custom Post class to be returned

This commit is contained in:
Oliver Davies 2020-11-14 09:46:05 +00:00
parent 290c8fbcba
commit 9aec327945
2 changed files with 8 additions and 3 deletions

View file

@ -0,0 +1,5 @@
<?php
namespace Drupal\my_module\Entity;
class Post {}

View file

@ -4,6 +4,7 @@ namespace Drupal\Tests\my_module\Kernel;
use Drupal\Core\Datetime\DrupalDateTime; use Drupal\Core\Datetime\DrupalDateTime;
use Drupal\KernelTests\Core\Entity\EntityKernelTestBase; use Drupal\KernelTests\Core\Entity\EntityKernelTestBase;
use Drupal\my_module\Entity\Post;
use Drupal\my_module\Repository\ArticleRepository; use Drupal\my_module\Repository\ArticleRepository;
use Drupal\node\NodeInterface; use Drupal\node\NodeInterface;
use Drupal\Tests\node\Traits\NodeCreationTrait; use Drupal\Tests\node\Traits\NodeCreationTrait;
@ -23,9 +24,8 @@ class ArticleRepositoryTest extends EntityKernelTestBase {
$this->assertCount(1, $articles); $this->assertCount(1, $articles);
$this->assertIsObject($articles[1]); $this->assertIsObject($articles[1]);
$this->assertInstanceOf(NodeInterface::class, $articles[1]); $this->assertInstanceOf(Post::class, $articles[1]);
$this->assertSame('article', $articles[1]->bundle()); $this->assertSame('Test post', $articles[1]->getTitle());
$this->assertSame('Test post', $articles[1]->label());
} }
/** @test */ /** @test */