class PrimitiveDataNormalizerTest in Drupal 8
Same name and namespace in other branches
- 9 core/modules/serialization/tests/src/Unit/Normalizer/PrimitiveDataNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\PrimitiveDataNormalizerTest
- 10 core/modules/serialization/tests/src/Unit/Normalizer/PrimitiveDataNormalizerTest.php \Drupal\Tests\serialization\Unit\Normalizer\PrimitiveDataNormalizerTest
@coversDefaultClass \Drupal\serialization\Normalizer\PrimitiveDataNormalizer @group serialization
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\serialization\Unit\Normalizer\PrimitiveDataNormalizerTest
Expanded class hierarchy of PrimitiveDataNormalizerTest
File
- core/
modules/ serialization/ tests/ src/ Unit/ Normalizer/ PrimitiveDataNormalizerTest.php, line 16
Namespace
Drupal\Tests\serialization\Unit\NormalizerView source
class PrimitiveDataNormalizerTest extends UnitTestCase {
/**
* The TypedDataNormalizer instance.
*
* @var \Drupal\serialization\Normalizer\TypedDataNormalizer
*/
protected $normalizer;
/**
* {@inheritdoc}
*/
protected function setUp() {
$this->normalizer = new PrimitiveDataNormalizer();
}
/**
* @covers ::supportsNormalization
* @dataProvider dataProviderPrimitiveData
*/
public function testSupportsNormalization($primitive_data, $expected) {
$this
->assertTrue($this->normalizer
->supportsNormalization($primitive_data));
}
/**
* @covers ::supportsNormalization
*/
public function testSupportsNormalizationFail() {
// Test that an object not implementing PrimitiveInterface fails.
$this
->assertFalse($this->normalizer
->supportsNormalization(new \stdClass()));
}
/**
* @covers ::normalize
* @dataProvider dataProviderPrimitiveData
*/
public function testNormalize($primitive_data, $expected) {
$this
->assertSame($expected, $this->normalizer
->normalize($primitive_data));
}
/**
* Data provider for testNormalize().
*/
public function dataProviderPrimitiveData() {
$data = [];
$definition = DataDefinition::createFromDataType('string');
$string = new StringData($definition, 'string');
$string
->setValue('test');
$data['string'] = [
$string,
'test',
];
$definition = DataDefinition::createFromDataType('string');
$string = new StringData($definition, 'string');
$string
->setValue(NULL);
$data['string-null'] = [
$string,
NULL,
];
$definition = DataDefinition::createFromDataType('integer');
$integer = new IntegerData($definition, 'integer');
$integer
->setValue(5);
$data['integer'] = [
$integer,
5,
];
$definition = DataDefinition::createFromDataType('integer');
$integer = new IntegerData($definition, 'integer');
$integer
->setValue(NULL);
$data['integer-null'] = [
$integer,
NULL,
];
$definition = DataDefinition::createFromDataType('boolean');
$boolean = new BooleanData($definition, 'boolean');
$boolean
->setValue(TRUE);
$data['boolean'] = [
$boolean,
TRUE,
];
$definition = DataDefinition::createFromDataType('boolean');
$boolean = new BooleanData($definition, 'boolean');
$boolean
->setValue(NULL);
$data['boolean-null'] = [
$boolean,
NULL,
];
return $data;
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
PrimitiveDataNormalizerTest:: |
protected | property | The TypedDataNormalizer instance. | |
PrimitiveDataNormalizerTest:: |
public | function | Data provider for testNormalize(). | |
PrimitiveDataNormalizerTest:: |
protected | function |
Overrides UnitTestCase:: |
|
PrimitiveDataNormalizerTest:: |
public | function | @covers ::normalize @dataProvider dataProviderPrimitiveData | |
PrimitiveDataNormalizerTest:: |
public | function | @covers ::supportsNormalization @dataProvider dataProviderPrimitiveData | |
PrimitiveDataNormalizerTest:: |
public | function | @covers ::supportsNormalization | |
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. |