30 lines
1.2 KiB
PHP
30 lines
1.2 KiB
PHP
|
<?php
|
||
|
namespace Drupal\Tests\opencase\Unit;
|
||
|
use PHPUnit\Framework\MockObject\MockObject;
|
||
|
use Drupal\Core\DependencyInjection\ContainerBuilder;
|
||
|
|
||
|
trait EntityTrait {
|
||
|
public function getEntityTypeManager() {
|
||
|
return $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityTypeManager')->disableOriginalConstructor()->getMock();
|
||
|
}
|
||
|
|
||
|
public function getStorage(MockObject $entityTypeManager, string $entityTypeId): MockObject {
|
||
|
$storage = $this->getMockBuilder('\\Drupal\\Core\\Entity\\EntityStorageInterface')->disableOriginalConstructor()->getMock();
|
||
|
$entityTypeManager->method('getStorage')->with($entityTypeId)->willReturn($storage);
|
||
|
return $storage;
|
||
|
}
|
||
|
|
||
|
public function getQuery(MockObject $storage): MockObject {
|
||
|
$query = $this->getMockBuilder('\\Drupal\\Core\\Entity\\Query\\QueryInterface')->getMock();
|
||
|
$storage->method('getQuery')->willReturn($query);
|
||
|
return $query;
|
||
|
}
|
||
|
|
||
|
public function setupContainer(array $services): void {
|
||
|
$container = new ContainerBuilder();
|
||
|
foreach ($services as $key => $mock) {
|
||
|
$container->set($key, $mock);
|
||
|
}
|
||
|
\Drupal::setContainer($container);
|
||
|
}
|
||
|
}
|