class XmlEncoderTest in Drupal 9
Same name and namespace in other branches
- 8 core/modules/serialization/tests/src/Unit/Encoder/XmlEncoderTest.php \Drupal\Tests\serialization\Unit\Encoder\XmlEncoderTest
- 10 core/modules/serialization/tests/src/Unit/Encoder/XmlEncoderTest.php \Drupal\Tests\serialization\Unit\Encoder\XmlEncoderTest
@coversDefaultClass \Drupal\serialization\Encoder\XmlEncoder @group serialization
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses \Symfony\Bridge\PhpUnit\ExpectDeprecationTrait, PhpUnitCompatibilityTrait, PhpUnitWarnings
- class \Drupal\Tests\serialization\Unit\Encoder\XmlEncoderTest
Expanded class hierarchy of XmlEncoderTest
File
- core/
modules/ serialization/ tests/ src/ Unit/ Encoder/ XmlEncoderTest.php, line 15
Namespace
Drupal\Tests\serialization\Unit\EncoderView source
class XmlEncoderTest extends UnitTestCase {
/**
* The XmlEncoder instance.
*
* @var \Drupal\serialization\Encoder\XmlEncoder
*/
protected $encoder;
/**
* @var \Symfony\Component\Serializer\Encoder\XmlEncoder|\PHPUnit\Framework\MockObject\MockObject
*/
protected $baseEncoder;
/**
* An array of test data.
*
* @var array
*/
protected $testArray = [
'test' => 'test',
];
protected function setUp() : void {
$this->baseEncoder = $this
->createMock(BaseXmlEncoder::class);
$this->encoder = new XmlEncoder();
$this->encoder
->setBaseEncoder($this->baseEncoder);
}
/**
* Tests the supportsEncoding() method.
*/
public function testSupportsEncoding() {
$this
->assertTrue($this->encoder
->supportsEncoding('xml'));
$this
->assertFalse($this->encoder
->supportsEncoding('json'));
}
/**
* Tests the supportsDecoding() method.
*/
public function testSupportsDecoding() {
$this
->assertTrue($this->encoder
->supportsDecoding('xml'));
$this
->assertFalse($this->encoder
->supportsDecoding('json'));
}
/**
* Tests the encode() method.
*/
public function testEncode() {
$this->baseEncoder
->expects($this
->once())
->method('encode')
->with($this->testArray, 'test', [])
->will($this
->returnValue('test'));
$this
->assertEquals('test', $this->encoder
->encode($this->testArray, 'test'));
}
/**
* Tests the decode() method.
*/
public function testDecode() {
$this->baseEncoder
->expects($this
->once())
->method('decode')
->with('test', 'test', [])
->will($this
->returnValue($this->testArray));
$this
->assertEquals($this->testArray, $this->encoder
->decode('test', 'test'));
}
/**
* @covers ::getBaseEncoder
*/
public function testDefaultEncoderHasSerializer() {
// The serializer should be set on the Drupal encoder, which should then
// set it on our default encoder.
$encoder = new XmlEncoder();
$serializer = new Serializer([
new GetSetMethodNormalizer(),
]);
$encoder
->setSerializer($serializer);
$base_encoder = $encoder
->getBaseEncoder();
$this
->assertInstanceOf(BaseXmlEncoder::class, $base_encoder);
// Test the encoder.
$base_encoder
->encode([
'a' => new TestObject(),
], 'xml');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
PhpUnitWarnings:: |
private static | property | Deprecation warnings from PHPUnit to raise with @trigger_error(). | |
PhpUnitWarnings:: |
public | function | Converts PHPUnit deprecation warnings to E_USER_DEPRECATED. | |
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 | 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. | |
UnitTestCase:: |
public static | function | ||
XmlEncoderTest:: |
protected | property | ||
XmlEncoderTest:: |
protected | property | The XmlEncoder instance. | |
XmlEncoderTest:: |
protected | property | An array of test data. | |
XmlEncoderTest:: |
protected | function |
Overrides UnitTestCase:: |
|
XmlEncoderTest:: |
public | function | Tests the decode() method. | |
XmlEncoderTest:: |
public | function | @covers ::getBaseEncoder | |
XmlEncoderTest:: |
public | function | Tests the encode() method. | |
XmlEncoderTest:: |
public | function | Tests the supportsDecoding() method. | |
XmlEncoderTest:: |
public | function | Tests the supportsEncoding() method. |