use Drupal\Core\Config\Entity\ConfigEntityInterface;
use Drupal\Core\DependencyInjection\ContainerBuilder;
+use Drupal\Core\Entity\EntityFieldManagerInterface;
use Drupal\Core\Entity\EntityInterface;
use Drupal\Core\Entity\EntityMalformedException;
+use Drupal\Core\Entity\EntityManager;
use Drupal\Core\Entity\EntityStorageException;
+use Drupal\Core\Entity\EntityTypeManagerInterface;
use Drupal\Core\Language\Language;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\Entity\KeyValueStore\KeyValueEntityStorage;
protected $entityStorage;
/**
- * The mocked entity manager.
+ * The entity manager.
*
* @var \Drupal\Core\Entity\EntityManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
protected $entityManager;
+ /**
+ * The mocked entity type manager.
+ *
+ * @var \Drupal\Core\Entity\EntityTypeManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $entityTypeManager;
+
+ /**
+ * The mocked entity field manager.
+ *
+ * @var \Drupal\Core\Entity\EntityFieldManagerInterface|\PHPUnit_Framework_MockObject_MockObject
+ */
+ protected $entityFieldManager;
+
/**
* The mocked cache tags invalidator.
*
->method('getListCacheTags')
->willReturn(['test_entity_type_list']);
- $this->entityManager = $this->getMock('Drupal\Core\Entity\EntityManagerInterface');
- $this->entityManager->expects($this->any())
+ $this->entityManager = new EntityManager();
+
+ $this->entityTypeManager = $this->getMock(EntityTypeManagerInterface::class);
+ $this->entityTypeManager->expects($this->any())
->method('getDefinition')
->with('test_entity_type')
->will($this->returnValue($this->entityType));
+ $this->entityFieldManager = $this->getMock(EntityFieldManagerInterface::class);
+
$this->cacheTagsInvalidator = $this->getMock('Drupal\Core\Cache\CacheTagsInvalidatorInterface');
$this->keyValueStore = $this->getMock('Drupal\Core\KeyValueStore\KeyValueStoreInterface');
$container = new ContainerBuilder();
$container->set('entity.manager', $this->entityManager);
+ $container->set('entity_field.manager', $this->entityFieldManager);
+ $container->set('entity_type.manager', $this->entityTypeManager);
$container->set('language_manager', $this->languageManager);
$container->set('cache_tags.invalidator', $this->cacheTagsInvalidator);
+ // Inject the container into entity.manager so it can defer to
+ // entity_type.manager and other services.
+ $this->entityManager->setContainer($container);
\Drupal::setContainer($container);
}
$this->assertSame('foo', $entity->getOriginalId());
$expected = ['id' => 'foo'];
- $entity->expects($this->once())
+ $entity->expects($this->atLeastOnce())
->method('toArray')
->will($this->returnValue($expected));