Skip to content

Commit e6f0ed8

Browse files
authored
Add ext-dom to composer.json and more test (#53)
1 parent 0855dcc commit e6f0ed8

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

composer.json

+1
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
"prefer-stable": true,
2121
"require": {
2222
"php": "^7.4|^8.0",
23+
"ext-dom": "*",
2324
"psr/http-message": "^1.0",
2425
"psr/http-server-middleware": "^1.0",
2526
"yiisoft/http": "^1.0",

tests/Formatter/XmlDataResponseFormatterTest.php

+29
Original file line numberDiff line numberDiff line change
@@ -541,6 +541,35 @@ public function testItemTagWhenNameIsEmptyOrInvalid(): void
541541
);
542542
}
543543

544+
public function testObjectWithPublicProperties(): void
545+
{
546+
$object = new class() {
547+
public int $x = 7;
548+
public float $y = 42;
549+
public string $name = 'yii';
550+
protected int $a = 1;
551+
private int $b = 2;
552+
};
553+
$dataResponse = $this->createResponse($object);
554+
$result = (new XmlDataResponseFormatter())->format($dataResponse);
555+
$result->getBody()->rewind();
556+
557+
$this->assertSame(
558+
$this->xml(
559+
<<<EOF
560+
<response>
561+
<item>
562+
<x>7</x>
563+
<y>42</y>
564+
<name>yii</name>
565+
</item>
566+
</response>
567+
EOF
568+
),
569+
$result->getBody()->getContents()
570+
);
571+
}
572+
544573
private function createResponse($data): DataResponse
545574
{
546575
return (new DataResponseFactory(new Psr17Factory()))->createResponse($data);

0 commit comments

Comments
 (0)