function ListNormalizerTest::setUp

Same name and namespace in other branches
  1. 9 core/modules/serialization/tests/src/Unit/Normalizer/ListNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ListNormalizerTest::setUp()
  2. 8.9.x core/modules/serialization/tests/src/Unit/Normalizer/ListNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ListNormalizerTest::setUp()
  3. 10 core/modules/serialization/tests/src/Unit/Normalizer/ListNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\ListNormalizerTest::setUp()

Overrides UnitTestCase::setUp

File

core/modules/serialization/tests/src/Unit/Normalizer/ListNormalizerTest.php, line 51

Class

ListNormalizerTest
@coversDefaultClass <a href="/api/drupal/core%21modules%21serialization%21src%21Normalizer%21ListNormalizer.php/class/ListNormalizer/11.x" title="Converts list objects to arrays." class="local">\Drupal\serialization\Normalizer\ListNormalizer</a> @group serialization

Namespace

Drupal\Tests\serialization\Unit\Normalizer

Code

protected function setUp() : void {
    parent::setUp();
    // Mock the TypedDataManager to return a TypedDataInterface mock.
    $this->typedData = $this->createMock('Drupal\\Core\\TypedData\\TypedDataInterface');
    $typed_data_manager = $this->createMock(TypedDataManagerInterface::class);
    $typed_data_manager->expects($this->any())
        ->method('getPropertyInstance')
        ->willReturn($this->typedData);
    // Set up a mock container as ItemList() will call for the 'typed_data_manager'
    // service.
    $container = $this->getMockBuilder('Symfony\\Component\\DependencyInjection\\ContainerBuilder')
        ->onlyMethods([
        'get',
    ])
        ->getMock();
    $container->expects($this->any())
        ->method('get')
        ->with($this->equalTo('typed_data_manager'))
        ->willReturn($typed_data_manager);
    \Drupal::setContainer($container);
    $this->normalizer = new ListNormalizer();
    $this->list = new ItemList(new DataDefinition());
    $this->list
        ->setValue($this->expectedListValues);
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.