trait TaxonomyTestTrait in Search API 8
Provides common methods for unit tests using taxonomy terms.
@method \PHPUnit\Framework\MockObject\MockObject createMock(string $originalClassName)
Hierarchy
- trait \Drupal\Tests\search_api\Unit\Views\TaxonomyTestTrait
File
- tests/
src/ Unit/ Views/ TaxonomyTestTrait.php, line 16
Namespace
Drupal\Tests\search_api\Unit\ViewsView source
trait TaxonomyTestTrait {
/**
* The test container.
*
* @var \Drupal\Core\DependencyInjection\ContainerBuilder
*/
protected $container;
/**
* The mock term storage.
*
* @var \Drupal\Core\Entity\EntityStorageInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $termStorage;
/**
* The mock entity repository service.
*
* @var \Drupal\Core\Entity\EntityRepositoryInterface|\PHPUnit\Framework\MockObject\MockObject
*/
protected $entityRepository;
/**
* Sets up the container with necessary services.
*/
public function setupContainer() {
$this->container = new ContainerBuilder();
$this->entityRepository = $this
->createMock(EntityRepositoryInterface::class);
$this->termStorage = $this
->createMock(TermStorageInterface::class);
$entity_type_manager = $this
->createMock(EntityTypeManagerInterface::class);
$entity_type_manager
->expects($this
->any())
->method('getStorage')
->willReturnMap([
[
'taxonomy_term',
$this->termStorage,
],
]);
$this->container
->set('entity.repository', $this->entityRepository);
$this->container
->set('entity_type.manager', $entity_type_manager);
$this->container
->set('string_translation', $this
->createMock(TranslationInterface::class));
\Drupal::setContainer($this->container);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
TaxonomyTestTrait:: |
protected | property | The test container. | |
TaxonomyTestTrait:: |
protected | property | The mock entity repository service. | |
TaxonomyTestTrait:: |
protected | property | The mock term storage. | |
TaxonomyTestTrait:: |
public | function | Sets up the container with necessary services. |