You are here

public function YamlTest::testDecode in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/tests/Drupal/Tests/Component/Serialization/YamlTest.php \Drupal\Tests\Component\Serialization\YamlTest::testDecode()

@covers ::decode

File

core/tests/Drupal/Tests/Component/Serialization/YamlTest.php, line 22
Contains \Drupal\Tests\Component\Serialization\YamlTest.

Class

YamlTest
@coversDefaultClass \Drupal\Component\Serialization\Yaml @group Serialization

Namespace

Drupal\Tests\Component\Serialization

Code

public function testDecode() {

  // Test that files without line break endings are properly interpreted.
  $yaml = 'foo: bar';
  $expected = array(
    'foo' => 'bar',
  );
  $this
    ->assertSame($expected, Yaml::decode($yaml));
  $yaml .= "\n";
  $this
    ->assertSame($expected, Yaml::decode($yaml));
  $yaml .= "\n";
  $this
    ->assertSame($expected, Yaml::decode($yaml));
  $yaml = "{}\n";
  $expected = array();
  $this
    ->assertSame($expected, Yaml::decode($yaml));
  $yaml = '';
  $this
    ->assertNULL(Yaml::decode($yaml));
  $yaml .= "\n";
  $this
    ->assertNULL(Yaml::decode($yaml));
  $yaml .= "\n";
  $this
    ->assertNULL(Yaml::decode($yaml));
}