Skip to content

Commit dd97725

Browse files
committed
Add tests for Stringable implementation in Serializers
1 parent e5d620f commit dd97725

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

tests/Unit/Serializer/JsonSerializerTest.php

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -180,21 +180,17 @@ public static function getNormalizedToEncodedData(): array
180180
}
181181

182182
/**
183+
* @covers \Redmine\Serializer\JsonSerializer::getEncoded
184+
* @covers \Redmine\Serializer\JsonSerializer::__toString
183185
* @test
184186
*
185187
* @dataProvider getNormalizedToEncodedData
186188
*/
187-
public function createFromArrayDecodesToExpectedString(array $data, $expected)
189+
public function createFromArrayEncodesToExpectedString(array $data, $expected)
188190
{
189191
$serializer = JsonSerializer::createFromArray($data);
190192

191-
// decode the result, so we encode again with JSON_PRETTY_PRINT to compare the formated output
192-
$encoded = json_encode(
193-
json_decode($serializer->getEncoded(), true, 512, \JSON_THROW_ON_ERROR),
194-
\JSON_THROW_ON_ERROR | \JSON_PRETTY_PRINT
195-
);
196-
197-
$this->assertSame($expected, $encoded);
193+
$this->assertJsonStringEqualsJsonString($expected, $serializer->__toString());
198194
}
199195

200196
public static function getInvalidSerializedData(): array

tests/Unit/Serializer/PathSerializerTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ public static function getPathData(): array
4848
}
4949

5050
/**
51+
* @covers \Redmine\Serializer\PathSerializer::getPath
52+
* @covers \Redmine\Serializer\PathSerializer::__toString
5153
* @test
5254
*
5355
* @dataProvider getPathData
@@ -56,6 +58,6 @@ public function getPathShouldReturnExpectedString(string $path, array $params, s
5658
{
5759
$serializer = PathSerializer::create($path, $params);
5860

59-
$this->assertSame($expected, $serializer->getPath());
61+
$this->assertSame($expected, $serializer->__toString());
6062
}
6163
}

tests/Unit/Serializer/XmlSerializerTest.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,19 +186,17 @@ public static function getNormalizedToEncodedData(): array
186186
}
187187

188188
/**
189+
* @covers \Redmine\Serializer\XmlSerializer::getEncoded
190+
* @covers \Redmine\Serializer\XmlSerializer::__toString
189191
* @test
190192
*
191193
* @dataProvider getNormalizedToEncodedData
192194
*/
193-
public function createFromArrayDecodesToExpectedString(array $data, $expected)
195+
public function createFromArrayEncodesToExpectedString(array $data, $expected)
194196
{
195197
$serializer = XmlSerializer::createFromArray($data);
196198

197-
// Load the encoded string into a DOMDocument, so we can compare the formated output
198-
$dom = dom_import_simplexml(new \SimpleXMLElement($serializer->getEncoded()))->ownerDocument;
199-
$dom->formatOutput = true;
200-
201-
$this->assertSame($expected, trim($dom->saveXML()));
199+
$this->assertXmlStringEqualsXmlString($expected, $serializer->__toString());
202200
}
203201

204202
public static function getInvalidSerializedData(): array

0 commit comments

Comments
 (0)