AzuraCast/tests/Unit/XmlTest.php

55 lines
1.2 KiB
PHP
Raw Normal View History

2021-06-14 03:30:17 +00:00
<?php
namespace Unit;
2021-06-14 03:30:17 +00:00
use App\Xml\Reader;
use App\Xml\Writer;
use Codeception\Test\Unit;
use UnitTester;
2021-06-14 03:30:17 +00:00
class XmlTest extends Unit
2021-06-14 03:30:17 +00:00
{
protected UnitTester $tester;
2021-06-14 03:30:17 +00:00
public function testXml(): void
{
$arrayValue = [
'mounts' => [
'mount' => [
[
'@type' => 'normal',
'path' => '/radio.mp3',
],
[
'@type' => 'special',
'path' => '/special.mp3',
],
],
],
];
$xmlString = (new Writer())->toString($arrayValue, 'icecast');
$xmlExpected = <<<'XML'
<?xml version="1.0" encoding="UTF-8"?>
<icecast>
<mounts>
<mount type="normal">
<path>/radio.mp3</path>
</mount>
<mount type="special">
<path>/special.mp3</path>
</mount>
</mounts>
</icecast>
XML;
self::assertEquals($xmlString, $xmlExpected);
$backToArray = (new Reader())->fromString($xmlString);
self::assertEquals($arrayValue, $backToArray);
}
}