3 namespace Drupal\Tests\Core\Entity;
5 use Drupal\Core\DependencyInjection\ContainerBuilder;
6 use Drupal\Core\Entity\EntityFieldManagerInterface;
7 use Drupal\Core\Entity\EntityManager;
8 use Drupal\Core\Entity\EntityTypeBundleInfoInterface;
9 use Drupal\Core\Entity\EntityTypeManagerInterface;
10 use Drupal\Core\Entity\EntityTypeRepositoryInterface;
11 use Drupal\Tests\UnitTestCase;
14 * @coversDefaultClass \Drupal\Core\Entity\EntityManager
17 class EntityManagerTest extends UnitTestCase {
22 * @var \Drupal\Core\Entity\EntityManager
24 protected $entityManager;
27 * The entity type manager.
29 * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\Prophecy\Prophecy\ProphecyInterface
31 protected $entityTypeManager;
34 * The entity type repository.
36 * @var \Drupal\Core\Entity\EntityTypeRepositoryInterface|\Prophecy\Prophecy\ProphecyInterface
38 protected $entityTypeRepository;
41 * The entity type bundle info.
43 * @var \Drupal\Core\Entity\EntityTypeBundleInfoInterface|\Prophecy\Prophecy\ProphecyInterface
45 protected $entityTypeBundleInfo;
48 * The entity field manager.
50 * @var \Drupal\Core\Entity\EntityFieldManagerInterface|\Prophecy\Prophecy\ProphecyInterface
52 protected $entityFieldManager;
57 protected function setUp() {
60 $this->entityTypeManager = $this->prophesize(EntityTypeManagerInterface::class);
61 $this->entityTypeRepository = $this->prophesize(EntityTypeRepositoryInterface::class);
62 $this->entityTypeBundleInfo = $this->prophesize(EntityTypeBundleInfoInterface::class);
63 $this->entityFieldManager = $this->prophesize(EntityFieldManagerInterface::class);
65 $container = new ContainerBuilder();
66 $container->set('entity_type.manager', $this->entityTypeManager->reveal());
67 $container->set('entity_type.repository', $this->entityTypeRepository->reveal());
68 $container->set('entity_type.bundle.info', $this->entityTypeBundleInfo->reveal());
69 $container->set('entity_field.manager', $this->entityFieldManager->reveal());
71 $this->entityManager = new EntityManager();
72 $this->entityManager->setContainer($container);
76 * Tests the clearCachedDefinitions() method.
78 * @covers ::clearCachedDefinitions
80 public function testClearCachedDefinitions() {
81 $this->entityTypeManager->clearCachedDefinitions()->shouldBeCalled();
82 $this->entityTypeRepository->clearCachedDefinitions()->shouldBeCalled();
83 $this->entityTypeBundleInfo->clearCachedBundles()->shouldBeCalled();
84 $this->entityFieldManager->clearCachedFieldDefinitions()->shouldBeCalled();
86 $this->entityManager->clearCachedDefinitions();