MergeablePluginDefinitionTraitTest.php in Plugin 8.2
File
tests/src/Unit/PluginDefinition/MergeablePluginDefinitionTraitTest.php
View source
<?php
namespace Drupal\Tests\plugin\Unit\PluginDefinition;
use Drupal\plugin\PluginDefinition\MergeablePluginDefinitionTrait;
use Drupal\plugin\PluginDefinition\PluginDefinitionInterface;
use Drupal\Tests\UnitTestCase;
use InvalidArgumentException;
class MergeablePluginDefinitionTraitTest extends UnitTestCase {
protected $sut;
protected function setUp() : void {
parent::setUp();
$this->sut = $this
->getMockForTrait(MergeablePluginDefinitionTrait::class);
}
public function testMergeDefaultDefinition() {
$other_definition = $this
->createMock(PluginDefinitionInterface::class);
$this->sut
->expects($this
->atLeastOnce())
->method('isDefinitionCompatible')
->willReturnCallback(function ($value) use ($other_definition) {
return $value == $other_definition;
});
$this
->assertSame($this->sut, $this->sut
->mergeDefaultDefinition($other_definition));
}
public function testMergeDefaultDefinitionWithInvalidOtherDefinition() {
$this
->expectException(InvalidArgumentException::class);
$other_definition = $this
->createMock(PluginDefinitionInterface::class);
$this->sut
->expects($this
->atLeastOnce())
->method('isDefinitionCompatible')
->willReturn(FALSE);
$this->sut
->mergeDefaultDefinition($other_definition);
}
public function testMergeOverrideDefinition() {
$other_definition = $this
->createMock(PluginDefinitionInterface::class);
$this->sut
->expects($this
->atLeastOnce())
->method('isDefinitionCompatible')
->willReturnCallback(function ($value) use ($other_definition) {
return $value == $other_definition;
});
$this
->assertSame($this->sut, $this->sut
->mergeOverrideDefinition($other_definition));
}
public function testMergeOverrideDefinitionWithInvalidOtherDefinition() {
$this
->expectException(InvalidArgumentException::class);
$other_definition = $this
->createMock(PluginDefinitionInterface::class);
$this->sut
->expects($this
->atLeastOnce())
->method('isDefinitionCompatible')
->willReturn(FALSE);
$this->sut
->mergeOverrideDefinition($other_definition);
}
}