public function ResourceResponseSubscriberTest::testSerialization in Drupal 8
Same name and namespace in other branches
- 9 core/modules/rest/tests/src/Unit/EventSubscriber/ResourceResponseSubscriberTest.php \Drupal\Tests\rest\Unit\EventSubscriber\ResourceResponseSubscriberTest::testSerialization()
- 10 core/modules/rest/tests/src/Unit/EventSubscriber/ResourceResponseSubscriberTest.php \Drupal\Tests\rest\Unit\EventSubscriber\ResourceResponseSubscriberTest::testSerialization()
@covers ::onResponse @dataProvider providerTestSerialization
File
- core/
modules/ rest/ tests/ src/ Unit/ EventSubscriber/ ResourceResponseSubscriberTest.php, line 36
Class
- ResourceResponseSubscriberTest
- @coversDefaultClass \Drupal\rest\EventSubscriber\ResourceResponseSubscriber @group rest
Namespace
Drupal\Tests\rest\Unit\EventSubscriberCode
public function testSerialization($data, $expected_response = FALSE) {
$request = new Request();
$route_match = new RouteMatch('test', new Route('/rest/test', [
'_rest_resource_config' => 'restplugin',
], [
'_format' => 'json',
]));
$handler_response = new ResourceResponse($data);
$resource_response_subscriber = $this
->getFunctioningResourceResponseSubscriber($route_match);
$event = new FilterResponseEvent($this
->prophesize(HttpKernelInterface::class)
->reveal(), $request, HttpKernelInterface::MASTER_REQUEST, $handler_response);
$resource_response_subscriber
->onResponse($event);
// Content is a serialized version of the data we provided.
$this
->assertEquals($expected_response !== FALSE ? $expected_response : Json::encode($data), $event
->getResponse()
->getContent());
}