class MultiresponseJsonNormalizerTest in Subrequests 8.2
Same name and namespace in other branches
- 3.x tests/src/Unit/Normalizer/MultiresponseJsonNormalizerTest.php \Drupal\Tests\subrequests\Normalizer\MultiresponseJsonNormalizerTest
@coversDefaultClass \Drupal\subrequests\Normalizer\MultiresponseJsonNormalizer @group subrequests
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\subrequests\Normalizer\MultiresponseJsonNormalizerTest
Expanded class hierarchy of MultiresponseJsonNormalizerTest
File
- tests/
src/ Unit/ Normalizer/ MultiresponseJsonNormalizerTest.php, line 14
Namespace
Drupal\Tests\subrequests\NormalizerView source
class MultiresponseJsonNormalizerTest extends UnitTestCase {
/**
* @var \Drupal\subrequests\Normalizer\MultiresponseJsonNormalizer
*/
protected $sut;
protected function setUp() {
parent::setUp();
$this->sut = new MultiresponseJsonNormalizer();
}
/**
* @dataProvider dataProviderSupportsNormalization
* @covers ::supportsNormalization
*/
public function testSupportsNormalization($data, $format, $is_supported) {
$actual = $this->sut
->supportsNormalization($data, $format);
$this
->assertSame($is_supported, $actual);
}
public function dataProviderSupportsNormalization() {
return [
[
[
Response::create(''),
],
'json',
TRUE,
],
[
[],
'json',
TRUE,
],
[
[
Response::create(''),
],
'fail',
FALSE,
],
[
NULL,
'json',
FALSE,
],
[
[
Response::create(''),
NULL,
],
'json',
FALSE,
],
];
}
/**
* @covers ::normalize
*/
public function testNormalize() {
$sub_content_type = $this
->getRandomGenerator()
->string();
$data = [
Response::create('Foo!', 200, [
'Content-ID' => '<f>',
]),
Response::create('Bar', 200, [
'Content-ID' => '<b>',
]),
];
$actual = $this->sut
->normalize($data, NULL, [
'sub-content-type' => $sub_content_type,
]);
$this
->assertSame('application/json; type=' . $sub_content_type, $actual['headers']['Content-Type']);
$parsed = Json::decode($actual['content']);
$this
->assertSame('Foo!', $parsed['f']['body']);
$this
->assertSame('Bar', $parsed['b']['body']);
}
}
Members
Name![]() |
Modifiers | Type | Description | Overrides |
---|---|---|---|---|
MultiresponseJsonNormalizerTest:: |
protected | property | ||
MultiresponseJsonNormalizerTest:: |
public | function | ||
MultiresponseJsonNormalizerTest:: |
protected | function |
Overrides UnitTestCase:: |
|
MultiresponseJsonNormalizerTest:: |
public | function | @covers ::normalize | |
MultiresponseJsonNormalizerTest:: |
public | function | @dataProvider dataProviderSupportsNormalization @covers ::supportsNormalization | |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |