function SerializerTest::testSerializerReceivesOptions

Same name in other branches
  1. 9 core/modules/rest/tests/src/Unit/Plugin/views/style/SerializerTest.php \Drupal\Tests\rest\Unit\Plugin\views\style\SerializerTest::testSerializerReceivesOptions()
  2. 8.9.x core/modules/rest/tests/src/Unit/Plugin/views/style/SerializerTest.php \Drupal\Tests\rest\Unit\Plugin\views\style\SerializerTest::testSerializerReceivesOptions()
  3. 11.x core/modules/rest/tests/src/Unit/Plugin/views/style/SerializerTest.php \Drupal\Tests\rest\Unit\Plugin\views\style\SerializerTest::testSerializerReceivesOptions()

Tests that the symfony serializer receives style plugin from the render() method.

@covers ::render

File

core/modules/rest/tests/src/Unit/Plugin/views/style/SerializerTest.php, line 62

Class

SerializerTest
@coversDefaultClass \Drupal\rest\Plugin\views\style\Serializer @group rest

Namespace

Drupal\Tests\rest\Unit\Plugin\views\style

Code

public function testSerializerReceivesOptions() : void {
    $mock_serializer = $this->prophesize(SerializerInterface::class);
    // This is the main expectation of the test. We want to make sure the
    // serializer options are passed to the SerializerInterface object.
    $mock_serializer->serialize([], 'json', Argument::that(function ($argument) {
        return isset($argument['views_style_plugin']) && $argument['views_style_plugin'] instanceof Serializer;
    }))
        ->willReturn('')
        ->shouldBeCalled();
    $view_serializer_style = new Serializer([], 'dummy_serializer', [], $mock_serializer->reveal(), [
        'json',
        'xml',
    ], [
        'json' => 'serialization',
        'xml' => 'serialization',
    ]);
    $view_serializer_style->options = [
        'formats' => [
            'xml',
            'json',
        ],
    ];
    $view_serializer_style->view = $this->view;
    $view_serializer_style->displayHandler = $this->displayHandler;
    $view_serializer_style->render();
}

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