From e5cedf795cb5a3e11af262d64b352ed405daca17 Mon Sep 17 00:00:00 2001 From: Andrew Longosz Date: Tue, 27 Jun 2023 15:59:24 +0200 Subject: [PATCH] [Tests] Added more coverage for scalar values --- .../booleans.json | 1 + .../booleans.xml | 4 ++ .../floats.json | 1 + .../floats.xml | 4 ++ .../integers.json | 1 + .../integers.xml | 4 ++ .../null.json | 1 + .../null.xml | 4 ++ .../strings.json} | 0 .../strings.xml} | 0 tests/lib/Output/GeneratorTest.php | 64 +++++++++++++++++-- 11 files changed, 78 insertions(+), 6 deletions(-) create mode 100644 tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/booleans.json create mode 100644 tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/booleans.xml create mode 100644 tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/floats.json create mode 100644 tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/floats.xml create mode 100644 tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/integers.json create mode 100644 tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/integers.xml create mode 100644 tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/null.json create mode 100644 tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/null.xml rename tests/lib/Output/Generator/_fixtures/{testStartValueElementWithAttributes.json => testStartValueElementWithAttributes/strings.json} (100%) rename tests/lib/Output/Generator/_fixtures/{testStartValueElementWithAttributes.xml => testStartValueElementWithAttributes/strings.xml} (100%) diff --git a/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/booleans.json b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/booleans.json new file mode 100644 index 00000000..66fe8f98 --- /dev/null +++ b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/booleans.json @@ -0,0 +1 @@ +{"Element":{"_media-type":"application\/vnd.ibexa.api.Element+json","element":{"_attribute1":true,"_attribute2":false,"#text":false}}} diff --git a/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/booleans.xml b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/booleans.xml new file mode 100644 index 00000000..2783d3e2 --- /dev/null +++ b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/booleans.xml @@ -0,0 +1,4 @@ + + + + diff --git a/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/floats.json b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/floats.json new file mode 100644 index 00000000..cf31bf6b --- /dev/null +++ b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/floats.json @@ -0,0 +1 @@ +{"Element":{"_media-type":"application\/vnd.ibexa.api.Element+json","element":{"_attribute1":2.3,"_attribute2":3.2,"#text":1.2}}} diff --git a/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/floats.xml b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/floats.xml new file mode 100644 index 00000000..35efd3e6 --- /dev/null +++ b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/floats.xml @@ -0,0 +1,4 @@ + + + 1.2 + diff --git a/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/integers.json b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/integers.json new file mode 100644 index 00000000..49858e28 --- /dev/null +++ b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/integers.json @@ -0,0 +1 @@ +{"Element":{"_media-type":"application\/vnd.ibexa.api.Element+json","element":{"_attribute1":2,"_attribute2":3,"#text":1}}} diff --git a/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/integers.xml b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/integers.xml new file mode 100644 index 00000000..bb220d65 --- /dev/null +++ b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/integers.xml @@ -0,0 +1,4 @@ + + + 1 + diff --git a/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/null.json b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/null.json new file mode 100644 index 00000000..255fb07f --- /dev/null +++ b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/null.json @@ -0,0 +1 @@ +{"Element":{"_media-type":"application\/vnd.ibexa.api.Element+json","element":{"_attribute1":null,"_attribute2":"foo","#text":null}}} diff --git a/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/null.xml b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/null.xml new file mode 100644 index 00000000..78b4d0a7 --- /dev/null +++ b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/null.xml @@ -0,0 +1,4 @@ + + + + diff --git a/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes.json b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/strings.json similarity index 100% rename from tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes.json rename to tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/strings.json diff --git a/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes.xml b/tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/strings.xml similarity index 100% rename from tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes.xml rename to tests/lib/Output/Generator/_fixtures/testStartValueElementWithAttributes/strings.xml diff --git a/tests/lib/Output/GeneratorTest.php b/tests/lib/Output/GeneratorTest.php index 19c057c0..0b0747ab 100644 --- a/tests/lib/Output/GeneratorTest.php +++ b/tests/lib/Output/GeneratorTest.php @@ -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 $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}> + */ + 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 + ], + ]; } }