class SerializerTest

Same name in this branch
  1. 11.x core/modules/jsonapi/tests/src/Kernel/Serializer/SerializerTest.php \Drupal\Tests\jsonapi\Kernel\Serializer\SerializerTest
Same name in other branches
  1. 9 core/modules/jsonapi/tests/src/Kernel/Serializer/SerializerTest.php \Drupal\Tests\jsonapi\Kernel\Serializer\SerializerTest
  2. 9 core/modules/rest/tests/src/Unit/Plugin/views/style/SerializerTest.php \Drupal\Tests\rest\Unit\Plugin\views\style\SerializerTest
  3. 8.9.x core/modules/jsonapi/tests/src/Kernel/Serializer/SerializerTest.php \Drupal\Tests\jsonapi\Kernel\Serializer\SerializerTest
  4. 8.9.x core/modules/rest/tests/src/Unit/Plugin/views/style/SerializerTest.php \Drupal\Tests\rest\Unit\Plugin\views\style\SerializerTest
  5. 10 core/modules/jsonapi/tests/src/Kernel/Serializer/SerializerTest.php \Drupal\Tests\jsonapi\Kernel\Serializer\SerializerTest
  6. 10 core/modules/rest/tests/src/Unit/Plugin/views/style/SerializerTest.php \Drupal\Tests\rest\Unit\Plugin\views\style\SerializerTest

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

Hierarchy

Expanded class hierarchy of SerializerTest

File

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

Namespace

Drupal\Tests\rest\Unit\Plugin\views\style
View source
class SerializerTest extends UnitTestCase {
    
    /**
     * The View instance.
     *
     * @var \Drupal\views\ViewExecutable|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $view;
    
    /**
     * The RestExport display handler.
     *
     * @var \Drupal\rest\Plugin\views\display\RestExport|\PHPUnit\Framework\MockObject\MockObject
     */
    protected $displayHandler;
    
    /**
     * {@inheritdoc}
     */
    protected function setUp() : void {
        parent::setUp();
        $this->view = $this->getMockBuilder(ViewExecutable::class)
            ->disableOriginalConstructor()
            ->getMock();
        // Make the view result empty so we don't have to mock the row plugin render
        // call.
        $this->view->result = [];
        $this->displayHandler = $this->getMockBuilder(RestExport::class)
            ->disableOriginalConstructor()
            ->getMock();
        $this->displayHandler
            ->expects($this->any())
            ->method('getContentType')
            ->willReturn('json');
    }
    
    /**
     * Tests that the symfony serializer receives style plugin from the render() method.
     *
     * @covers ::render
     */
    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();
    }

}

Members

Title Sort descending Modifiers Object type Summary Overriden Title
ExpectDeprecationTrait::expectDeprecation public function Adds an expected deprecation.
ExpectDeprecationTrait::getCallableName private static function Returns a callable as a string suitable for inclusion in a message.
ExpectDeprecationTrait::setUpErrorHandler public function Sets up the test error handler.
ExpectDeprecationTrait::tearDownErrorHandler public function Tears down the test error handler.
RandomGeneratorTrait::getRandomGenerator protected function Gets the random generator for the utility methods.
RandomGeneratorTrait::randomMachineName protected function Generates a unique random string containing letters and numbers.
RandomGeneratorTrait::randomObject public function Generates a random PHP object.
RandomGeneratorTrait::randomString public function Generates a pseudo-random string of ASCII characters of codes 32 to 126.
SerializerTest::$displayHandler protected property The RestExport display handler.
SerializerTest::$view protected property The View instance.
SerializerTest::setUp protected function Overrides UnitTestCase::setUp
SerializerTest::testSerializerReceivesOptions public function Tests that the symfony serializer receives style plugin from the render() method.
UnitTestCase::$root protected property The app root.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed array.
UnitTestCase::getConfigStorageStub public function Returns a stub config storage that returns the supplied configuration.
UnitTestCase::getContainerWithCacheTagsInvalidator protected function Sets up a container with a cache tags invalidator.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::setUpBeforeClass public static function

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