You are here

class XmlEncoderTest in Zircon Profile 8

Same name in this branch
  1. 8 vendor/symfony/serializer/Tests/Encoder/XmlEncoderTest.php \Symfony\Component\Serializer\Tests\Encoder\XmlEncoderTest
  2. 8 core/modules/serialization/tests/src/Unit/Encoder/XmlEncoderTest.php \Drupal\Tests\serialization\Unit\Encoder\XmlEncoderTest
Same name and namespace in other branches
  1. 8.0 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 \Drupal\Tests\PHPUnit_Framework_TestCase

Expanded class hierarchy of XmlEncoderTest

File

core/modules/serialization/tests/src/Unit/Encoder/XmlEncoderTest.php, line 17
Contains \Drupal\Tests\serialization\Unit\Encoder\XmlEncoderTest.

Namespace

Drupal\Tests\serialization\Unit\Encoder
View 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 = array(
    'test' => 'test',
  );
  protected function setUp() {
    $this->baseEncoder = $this
      ->getMock('Symfony\\Component\\Serializer\\Encoder\\XmlEncoder');
    $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', array())
      ->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', array())
      ->will($this
      ->returnValue($this->testArray));
    $this
      ->assertEquals($this->testArray, $this->encoder
      ->decode('test', 'test'));
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UnitTestCase::$randomGenerator protected property The random generator.
UnitTestCase::$root protected property The app root.
UnitTestCase::assertArrayEquals protected function Asserts if two arrays are equal by sorting them first.
UnitTestCase::getBlockMockWithMachineName protected function Mocks a block with a block plugin.
UnitTestCase::getClassResolverStub protected function Returns a stub class resolver.
UnitTestCase::getConfigFactoryStub public function Returns a stub config factory that behaves according to the passed in 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::getRandomGenerator protected function Gets the random generator for the utility methods.
UnitTestCase::getStringTranslationStub public function Returns a stub translation manager that just returns the passed string.
UnitTestCase::randomMachineName public function Generates a unique random string containing letters and numbers.
XmlEncoderTest::$baseEncoder protected property
XmlEncoderTest::$encoder protected property The XmlEncoder instance.
XmlEncoderTest::$testArray protected property An array of test data.
XmlEncoderTest::setUp protected function Overrides UnitTestCase::setUp
XmlEncoderTest::testDecode public function Tests the decode() method.
XmlEncoderTest::testEncode public function Tests the encode() method.
XmlEncoderTest::testSupportsDecoding public function Tests the supportsDecoding() method.
XmlEncoderTest::testSupportsEncoding public function Tests the supportsEncoding() method.