Skip to content

Commit

Permalink
[Tests] Added more coverage for scalar values
Browse files Browse the repository at this point in the history
  • Loading branch information
alongosz committed Jun 27, 2023
1 parent 1090a5c commit e5cedf7
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Element":{"_media-type":"application\/vnd.ibexa.api.Element+json","element":{"_attribute1":true,"_attribute2":false,"#text":false}}}
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="1" attribute2="" />
</Element>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Element":{"_media-type":"application\/vnd.ibexa.api.Element+json","element":{"_attribute1":2.3,"_attribute2":3.2,"#text":1.2}}}
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="2.3" attribute2="3.2">1.2</element>
</Element>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Element":{"_media-type":"application\/vnd.ibexa.api.Element+json","element":{"_attribute1":2,"_attribute2":3,"#text":1}}}
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="2" attribute2="3">1</element>
</Element>
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"Element":{"_media-type":"application\/vnd.ibexa.api.Element+json","element":{"_attribute1":null,"_attribute2":"foo","#text":null}}}
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="" attribute2="foo" />
</Element>
64 changes: 58 additions & 6 deletions tests/lib/Output/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -188,23 +188,75 @@ public function testNonEmptyDocument()

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

public function testStartValueElementWithAttributes(): void
/**
* @dataProvider getDataForTestStartValueElementWithAttributes
*
* @phpstan-param scalar|null $elementValue
* @phpstan-param array<string, scalar|null> $attributes
*/
public function testStartValueElementWithAttributes($elementValue, array $attributes): void
{
$generator = $this->getGenerator();
$generator->startDocument('test');
$generator->startObjectElement('Element');
$generator->startValueElement(
'element',
$elementValue,
$attributes
);
$generator->endValueElement('element');
$generator->endObjectElement('Element');

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

/**
* @return iterable<string, array{scalar|null, array<string, scalar|null>}>
*/
public function getDataForTestStartValueElementWithAttributes(): iterable
{
// data set name corresponds to the file names located in
// ./tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes

yield 'strings' => [
'value',
[
'attribute1' => 'attribute_value1',
'attribute2' => 'attribute_value2',
]
);
$generator->endValueElement('element');
$generator->endObjectElement('Element');
],
];

yield 'booleans' => [
false,
[
'attribute1' => true,
'attribute2' => false,
],
];

static::assertSnapshot(__FUNCTION__, $generator->endDocument('test'));
yield 'integers' => [
1,
[
'attribute1' => 2,
'attribute2' => 3,
],
];

yield 'floats' => [
1.2,
[
'attribute1' => 2.3,
'attribute2' => 3.2,
],
];

yield 'null' => [
null,
[
'attribute1' => null,
'attribute2' => 'foo', // let's see if 1st null affects rendering
],
];
}
}

Expand Down

0 comments on commit e5cedf7

Please sign in to comment.