Skip to content
Snippets Groups Projects
Commit 89e40acf authored by Joseph Olstad's avatar Joseph Olstad
Browse files

Issue #3455186 by joseph.olstad - Refactor of 88f1e040 for tests for D11...

Issue #3455186 by joseph.olstad - Refactor of 88f1e040 for tests for D11 phpunit 10+ compatibility refactoring test.
parent 4be2a29f
No related branches found
No related tags found
No related merge requests found
Pipeline #333668 failed
......@@ -5,14 +5,13 @@ declare(strict_types=1);
namespace Drupal\Tests\cshs\Unit;
use Drupal\Core\DependencyInjection\ContainerBuilder;
use Drupal\Core\DependencyInjection\ContainerNotInitializedException;
use Drupal\Core\ClassResolver\ClassResolverInterface;
use Drupal\Core\Field\EntityReferenceFieldItemListInterface;
use Drupal\Core\GeneratedLink;
use Drupal\Core\Language\LanguageInterface;
use Drupal\cshs\Plugin\Field\FieldFormatter\CshsGroupByRootFormatter;
use Drupal\taxonomy\Entity\Term;
use Drupal\Tests\UnitTestCase;
use Drupal\Core\DependencyInjection\ContainerBuilder;
/**
* Tests the `cshs_group_by_root` field formatter.
......@@ -22,20 +21,27 @@ use Drupal\Tests\UnitTestCase;
*/
class CshsGroupByRootFormatterUnitTest extends UnitTestCase {
public function setUp(): void {
/**
*
*/
protected function setUp(): void {
parent::setUp();
// Mock the ClassResolver service.
$class_resolver_mock = $this->createMock(ClassResolverInterface::class);
$class_resolver_mock->method('getInstanceFromDefinition')
->willReturnCallback(function ($class) {
return new $class();
});
// Create a mock container and set it.
$container = new ContainerBuilder();
$container->set('class_resolver', $class_resolver_mock);
\Drupal::setContainer($container);
// Check if the Drupal container is already set.
if (!\Drupal::hasContainer()) {
$container = new ContainerBuilder();
\Drupal::setContainer($container);
}
// Inject the class resolver service if it exists.
if (\Drupal::hasService('class_resolver')) {
$class_resolver = \Drupal::service('class_resolver');
$this->classResolver = $class_resolver;
}
else {
// Mock the class resolver for the test environment.
$this->classResolver = $this->createMock(\stdClass::class);
}
}
/**
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment