Skip to content

Commit

Permalink
[Tests] Added coverage for the change
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed Jun 27, 2023
1 parent 5a847d5 commit 6cb1ff5
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 0 deletions.
8 changes: 8 additions & 0 deletions tests/lib/Output/Generator/JsonTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ public function testGeneratorValueList()
);
}

public function assertSnapshot(string $snapshotName, string $generatedContent): void
{
self::assertJsonStringEqualsJsonFile(
sprintf('%s/_fixtures/%s.json', __DIR__, $snapshotName),
$generatedContent
);
}

public function testGetMediaType()
{
$generator = $this->getGenerator();
Expand Down
8 changes: 8 additions & 0 deletions tests/lib/Output/Generator/XmlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,14 @@ public function testGeneratorValueList()
);
}

public function assertSnapshot(string $snapshotName, string $generatedContent): void
{
self::assertXmlStringEqualsXmlFile(
sprintf('%s/_fixtures/%s.xml', __DIR__, $snapshotName),
$generatedContent
);
}

public function testGetMediaType()
{
$generator = $this->getGenerator();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Element":{"_media-type":"application\/vnd.ibexa.api.Element+json","element":{"_attribute1":"attribute_value1","_attribute2":"attribute_value2","#text":"value"}}}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8" ?>
<Element media-type="application/vnd.ibexa.api.Element+xml">
<element attribute1="attribute_value1" attribute2="attribute_value2">value</element>
</Element>
21 changes: 21 additions & 0 deletions tests/lib/Output/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,27 @@ public function testNonEmptyDocument()

$this->assertFalse($generator->isEmpty());
}

abstract protected function assertSnapshot(string $snapshotName, string $generatedContent): void;

public function testStartValueElementWithAttributes(): void
{
$generator = $this->getGenerator();
$generator->startDocument('test');
$generator->startObjectElement('Element');
$generator->startValueElement(
'element',
'value',
[
'attribute1' => 'attribute_value1',
'attribute2' => 'attribute_value2',
]
);
$generator->endValueElement('element');
$generator->endObjectElement('Element');

static::assertSnapshot(__FUNCTION__, $generator->endDocument('test'));
}
}

class_alias(GeneratorTest::class, 'EzSystems\EzPlatformRest\Tests\Output\GeneratorTest');

0 comments on commit 6cb1ff5

Please sign in to comment.