You are here

public function ArrayPluginDefinitionDecoratorTest::testGetClass in Plugin 8.2

@covers ::setClass @covers ::getClass @covers ::offsetExists @covers ::offsetSet @covers ::offsetGet @covers ::offsetUnset

File

tests/src/Unit/PluginDefinition/ArrayPluginDefinitionDecoratorTest.php, line 189

Class

ArrayPluginDefinitionDecoratorTest
@coversDefaultClass \Drupal\plugin\PluginDefinition\ArrayPluginDefinitionDecorator

Namespace

Drupal\Tests\plugin\Unit\PluginDefinition

Code

public function testGetClass() {

  // Test the injected value.
  $this
    ->assertSame($this->arrayDefinition['class'], $this->sut
    ->getClass());
  $this
    ->assertSame($this->arrayDefinition['class'], $this->sut
    ->getArrayDefinition()['class']);
  $this
    ->assertSame($this->arrayDefinition['class'], $this->sut['class']);

  // Test changing the value through the setter.
  $value = '\\stdClass';
  $this
    ->assertSame($this->sut, $this->sut
    ->setClass($value));
  $this
    ->assertSame($value, $this->sut
    ->getClass());
  $this
    ->assertSame($value, $this->sut
    ->getArrayDefinition()['class']);
  $this
    ->assertSame($value, $this->sut['class']);

  // Test changing the value through array access.
  $value = '\\stdClass';
  $this->sut['class'] = $value;
  $this
    ->assertSame($value, $this->sut
    ->getClass());
  $this
    ->assertSame($value, $this->sut
    ->getArrayDefinition()['class']);
  $this
    ->assertSame($value, $this->sut['class']);

  // Test unsetting the value.
  unset($this->sut['class']);
  $this
    ->assertFalse(isset($this->sut['class']));
  $this
    ->assertNull($this->sut
    ->getClass());
  $this
    ->assertFalse(isset($this->sut
    ->getArrayDefinition()['class']));
}