Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
barw4 committed Oct 21, 2024
1 parent bee695f commit cc840b3
Show file tree
Hide file tree
Showing 12 changed files with 154 additions and 154 deletions.
10 changes: 0 additions & 10 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -5785,16 +5785,6 @@ parameters:
count: 1
path: tests/lib/Output/FieldTypeSerializerTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\FieldTypeHashGeneratorBaseTest\\:\\:assertSerializationSame\\(\\) has no return type specified\\.$#"
count: 1
path: tests/lib/Output/Generator/FieldTypeHashGeneratorBaseTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\FieldTypeHashGeneratorBaseTest\\:\\:assertSerializationSame\\(\\) has parameter \\$functionName with no type specified\\.$#"
count: 1
path: tests/lib/Output/Generator/FieldTypeHashGeneratorBaseTest.php

-
message: "#^Method Ibexa\\\\Tests\\\\Rest\\\\Output\\\\Generator\\\\FieldTypeHashGeneratorBaseTest\\:\\:getFieldTypeHashGenerator\\(\\) has no return type specified\\.$#"
count: 1
Expand Down
2 changes: 1 addition & 1 deletion src/contracts/Output/VisitorAdapterNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ public function supportsNormalization(mixed $data, ?string $format = null, array

return $this->normalizer->supportsNormalization(
$data,
null,
$format,
$context + [self::CALLED_CONTEXT => true],
);
}
Expand Down
4 changes: 1 addition & 3 deletions src/lib/Output/Generator/Data/ArrayList.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@ public function __construct(
) {
$this->name = $name;
$this->parent = $parent;

parent::__construct();
}

/**
* @return object
*/
public function getParent(): object
{
return $this->parent;
Expand Down
12 changes: 10 additions & 2 deletions src/lib/Output/Generator/InMemory/Xml.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
namespace Ibexa\Rest\Output\Generator\InMemory;

use Ibexa\Rest\Output\Generator\Data;
use Ibexa\Rest\Output\Generator\Data\ArrayList;
use Ibexa\Rest\Output\Generator\Json;
use Ibexa\Rest\Output\Normalizer\ArrayListNormalizer;
use Ibexa\Rest\Output\Normalizer\ArrayObjectNormalizer;
Expand All @@ -22,6 +21,7 @@ class Xml extends Json
{
public const string OUTER_ELEMENT = 'outer_element';

#[\Override]
public function getMediaType($name): string
{
return $this->generateMediaTypeWithVendor($name, 'xml', $this->vendor);
Expand All @@ -31,24 +31,30 @@ public function getMediaType($name): string
public function startList($name): void
{
$this->checkStartList($name);

$this->isEmpty = false;

$array = new Data\ArrayList($name, $this->json);

$this->json->$name = $array;
$this->json = $array;
}

#[\Override]
public function startAttribute($name, $value): void
{
$this->checkStartAttribute($name);

$this->json->{'@' . $name} = $value;
}

#[\Override]
public function serializeBool($boolValue): string
{
return $boolValue ? 'true' : 'false';
}

#[\Override]
public function startValueElement(string $name, $value, array $attributes = []): void
{
$this->checkStartValueElement($name);
Expand All @@ -64,13 +70,14 @@ public function startValueElement(string $name, $value, array $attributes = []):
$jsonValue->{'#'} = $value;
}

if ($this->json instanceof Json\ArrayObject || $this->json instanceof ArrayList) {
if ($this->json instanceof Json\ArrayObject || $this->json instanceof Data\ArrayList) {
$this->json->append($jsonValue);
} else {
$this->json->$name = $jsonValue;
}
}

#[\Override]
public function endDocument(mixed $data): string
{
parent::endDocument($data);
Expand All @@ -96,6 +103,7 @@ public function endDocument(mixed $data): string
return $serializer->serialize($data, 'xml', $encoderContext);
}

#[\Override]
public function getEncoderContext(array $data): array
{
return [
Expand Down
29 changes: 21 additions & 8 deletions tests/integration/Serializer/SerializerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public function testSerializeTestDataObject(): void
$expectedData = [
'string' => 'some_string',
'int' => 1,
'innerObject' => null,
'location' => null,
];

Expand All @@ -60,11 +59,10 @@ public function testNormalizeTestDataObjectWithApiLocation(): void
$dataObject = new TestDataObject(
'some_string',
1,
null,
$this->locationService->loadLocation(2),
);

$normalizedData = $this->serializer->normalize($dataObject);
$normalizedData = $this->serializer->normalize($dataObject, 'json');

self::assertSame(
'application/vnd.ibexa.api.Location+json',
Expand All @@ -83,19 +81,34 @@ public function testNormalizeTestDataObjectWithApiLocation(): void
);
}

public function testSerializeTestDataObjectWithApiLocation(): void
public function testSerializeTestDataObjectWithApiLocationXml(): void
{
$dataObject = new TestDataObject(
'some_string',
1,
null,
$this->locationService->loadLocation(2),
);

$serializedData = $this->serializer->serialize($dataObject, 'xml');
self::assertResponseMatchesXmlSnapshot(
$serializedData,
self::SNAPSHOT_DIR . '/TestDataObject.xml',
$expectedXml = new \DOMDocument();
$expectedXml->preserveWhiteSpace = false;
$expectedXml->formatOutput = true;
$expectedXml->load(self::SNAPSHOT_DIR . '/TestDataObject.xml');

$actualXml = new \DOMDocument();
$actualXml->preserveWhiteSpace = false;
$actualXml->formatOutput = true;
$actualXml->loadXML($serializedData);

self::assertSame($expectedXml->saveXML(), $actualXml->saveXML());
}

public function testSerializeTestDataObjectWithApiLocationJson(): void
{
$dataObject = new TestDataObject(
'some_string',
1,
$this->locationService->loadLocation(2),
);

$serializedData = $this->serializer->serialize($dataObject, 'json');
Expand Down
1 change: 0 additions & 1 deletion tests/integration/Serializer/TestDataObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
public function __construct(
public string $string,
public int $int,
public ?self $innerObject = null,
public ?Location $apiLocation = null,
) {
}
Expand Down
9 changes: 4 additions & 5 deletions tests/integration/Serializer/TestDataObjectNormalizer.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,18 @@ public function normalize(mixed $object, ?string $format = null, array $context
{
assert($object instanceof TestDataObject);

$scalarData = [
$data = [
'string' => $object->string,
'int' => $object->int,
'innerObject' => $object->innerObject,
'location' => null,
];

if ($object->apiLocation instanceof Location) {
$normalizedLocation = $this->normalizer->normalize($object->apiLocation);
$scalarData['location'] = $normalizedLocation['Location'] ?? null;
$normalizedLocation = $this->normalizer->normalize($object->apiLocation, $format);
$data['location'] = $normalizedLocation['#'] ?? $normalizedLocation['Location'] ?? null;
}

return $scalarData;
return $data;
}

public function supportsNormalization(mixed $data, ?string $format = null): bool
Expand Down
1 change: 0 additions & 1 deletion tests/integration/Serializer/_snapshot/TestDataObject.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
{
"string": "some_string",
"int": 1,
"innerObject": null,
"location": {
"_media-type": "application\/vnd.ibexa.api.Location+json",
"_href": "\/api\/ibexa\/v2\/content\/locations\/1\/2",
Expand Down
115 changes: 27 additions & 88 deletions tests/integration/Serializer/_snapshot/TestDataObject.xml
Original file line number Diff line number Diff line change
@@ -1,88 +1,48 @@
<?xml version="1.0"?>
<response>
<string>some_string</string>
<int>1</int>
<innerObject/>
<location>
<_media-type>application/vnd.ibexa.api.Location+json</_media-type>
<_href>/api/ibexa/v2/content/locations/1/2</_href>
<location media-type="application/vnd.ibexa.api.Location+xml" href="/api/ibexa/v2/content/locations/1/2">
<id>2</id>
<priority>0</priority>
<hidden>0</hidden>
<invisible>0</invisible>
<ParentLocation>
<_media-type>application/vnd.ibexa.api.Location+json</_media-type>
<_href>/api/ibexa/v2/content/locations/1</_href>
</ParentLocation>
<hidden>false</hidden>
<invisible>false</invisible>
<ParentLocation media-type="application/vnd.ibexa.api.Location+xml" href="/api/ibexa/v2/content/locations/1"/>
<pathString>/1/2/</pathString>
<depth>1</depth>
<childCount>1</childCount>
<remoteId>f3e90596361e31d496d4026eb624c983</remoteId>
<Children>
<_media-type>application/vnd.ibexa.api.LocationList+json</_media-type>
<_href>/api/ibexa/v2/content/locations/1/2/children</_href>
</Children>
<Content>
<_media-type>application/vnd.ibexa.api.Content+json</_media-type>
<_href>/api/ibexa/v2/content/objects/57</_href>
</Content>
<Children media-type="application/vnd.ibexa.api.LocationList+xml" href="/api/ibexa/v2/content/locations/1/2/children"/>
<Content media-type="application/vnd.ibexa.api.Content+xml" href="/api/ibexa/v2/content/objects/57"/>
<sortField>PRIORITY</sortField>
<sortOrder>ASC</sortOrder>
<UrlAliases>
<_media-type>application/vnd.ibexa.api.UrlAliasRefList+json</_media-type>
<_href>/api/ibexa/v2/content/locations/1/2/urlaliases</_href>
</UrlAliases>
<ContentInfo>
<_media-type>application/vnd.ibexa.api.ContentInfo+json</_media-type>
<_href>/api/ibexa/v2/content/objects/57</_href>
<Content>
<_media-type>application/vnd.ibexa.api.Content+json</_media-type>
<_href>/api/ibexa/v2/content/objects/57</_href>
<_remoteId>8a9c9c761004866fb458d89910f52bee</_remoteId>
<_id>57</_id>
<ContentType>
<_media-type>application/vnd.ibexa.api.ContentType+json</_media-type>
<_href>/api/ibexa/v2/content/types/21</_href>
</ContentType>
<UrlAliases media-type="application/vnd.ibexa.api.UrlAliasRefList+xml" href="/api/ibexa/v2/content/locations/1/2/urlaliases"/>
<ContentInfo media-type="application/vnd.ibexa.api.ContentInfo+xml" href="/api/ibexa/v2/content/objects/57">
<Content media-type="application/vnd.ibexa.api.Content+xml" href="/api/ibexa/v2/content/objects/57" remoteId="8a9c9c761004866fb458d89910f52bee" id="57">
<ContentType media-type="application/vnd.ibexa.api.ContentType+xml" href="/api/ibexa/v2/content/types/21"/>
<Name>Home</Name>
<TranslatedName>Home</TranslatedName>
<Versions>
<_media-type>application/vnd.ibexa.api.VersionList+json</_media-type>
<_href>/api/ibexa/v2/content/objects/57/versions</_href>
</Versions>
<CurrentVersion>
<_media-type>application/vnd.ibexa.api.Version+json</_media-type>
<_href>/api/ibexa/v2/content/objects/57/currentversion</_href>
<Version>
<_media-type>application/vnd.ibexa.api.Version+json</_media-type>
<_href>/api/ibexa/v2/content/objects/57/versions/1</_href>
<Versions media-type="application/vnd.ibexa.api.VersionList+xml" href="/api/ibexa/v2/content/objects/57/versions"/>
<CurrentVersion media-type="application/vnd.ibexa.api.Version+xml" href="/api/ibexa/v2/content/objects/57/currentversion">
<Version media-type="application/vnd.ibexa.api.Version+xml" href="/api/ibexa/v2/content/objects/57/versions/1">
<VersionInfo>
<id>504</id>
<versionNo>1</versionNo>
<status>PUBLISHED</status>
<modificationDate>2007-11-28T16:51:36+00:00</modificationDate>
<Creator>
<_media-type>application/vnd.ibexa.api.User+json</_media-type>
<_href>/api/ibexa/v2/user/users/14</_href>
</Creator>
<Creator media-type="application/vnd.ibexa.api.User+xml" href="/api/ibexa/v2/user/users/14"/>
<creationDate>2007-11-28T16:50:55+00:00</creationDate>
<initialLanguageCode>eng-GB</initialLanguageCode>
<languageCodes>eng-GB</languageCodes>
<VersionTranslationInfo>
<_media-type>application/vnd.ibexa.api.VersionTranslationInfo+json</_media-type>
<VersionTranslationInfo media-type="application/vnd.ibexa.api.VersionTranslationInfo+xml">
<Language>
<languageCode>eng-GB</languageCode>
</Language>
</VersionTranslationInfo>
<names>
<value>
<_languageCode>eng-GB</_languageCode>
<item key="#text">Home</item>
</value>
<value languageCode="eng-GB">Home</value>
</names>
<Content>
<_media-type>application/vnd.ibexa.api.ContentInfo+json</_media-type>
<_href>/api/ibexa/v2/content/objects/57</_href>
</Content>
<Content media-type="application/vnd.ibexa.api.ContentInfo+xml" href="/api/ibexa/v2/content/objects/57"/>
</VersionInfo>
<Fields>
<field>
Expand All @@ -93,43 +53,22 @@
<fieldValue>Home</fieldValue>
</field>
</Fields>
<Relations>
<_media-type>application/vnd.ibexa.api.RelationList+json</_media-type>
<_href>/api/ibexa/v2/content/objects/57/versions/1/relations</_href>
<Relation/>
</Relations>
<Thumbnail>
<_media-type>application/vnd.ibexa.api.Thumbnail+json</_media-type>
</Thumbnail>
<Relations media-type="application/vnd.ibexa.api.RelationList+xml" href="/api/ibexa/v2/content/objects/57/versions/1/relations"/>
<Thumbnail media-type="application/vnd.ibexa.api.Thumbnail+xml"/>
</Version>
</CurrentVersion>
<Section>
<_media-type>application/vnd.ibexa.api.Section+json</_media-type>
<_href>/api/ibexa/v2/content/sections/1</_href>
</Section>
<MainLocation>
<_media-type>application/vnd.ibexa.api.Location+json</_media-type>
<_href>/api/ibexa/v2/content/locations/1/2</_href>
</MainLocation>
<Locations>
<_media-type>application/vnd.ibexa.api.LocationList+json</_media-type>
<_href>/api/ibexa/v2/content/objects/57/locations</_href>
</Locations>
<Owner>
<_media-type>application/vnd.ibexa.api.User+json</_media-type>
<_href>/api/ibexa/v2/user/users/14</_href>
</Owner>
<Section media-type="application/vnd.ibexa.api.Section+xml" href="/api/ibexa/v2/content/sections/1"/>
<MainLocation media-type="application/vnd.ibexa.api.Location+xml" href="/api/ibexa/v2/content/locations/1/2"/>
<Locations media-type="application/vnd.ibexa.api.LocationList+xml" href="/api/ibexa/v2/content/objects/57/locations"/>
<Owner media-type="application/vnd.ibexa.api.User+xml" href="/api/ibexa/v2/user/users/14"/>
<lastModificationDate>2007-11-28T16:51:36+00:00</lastModificationDate>
<publishedDate>2007-11-19T13:54:46+00:00</publishedDate>
<mainLanguageCode>eng-GB</mainLanguageCode>
<currentVersionNo>1</currentVersionNo>
<alwaysAvailable>1</alwaysAvailable>
<isHidden>0</isHidden>
<alwaysAvailable>true</alwaysAvailable>
<isHidden>false</isHidden>
<status>PUBLISHED</status>
<ObjectStates>
<_media-type>application/vnd.ibexa.api.ContentObjectStates+json</_media-type>
<_href>/api/ibexa/v2/content/objects/57/objectstates</_href>
</ObjectStates>
<ObjectStates media-type="application/vnd.ibexa.api.ContentObjectStates+xml" href="/api/ibexa/v2/content/objects/57/objectstates"/>
</Content>
</ContentInfo>
</location>
Expand Down
Loading

0 comments on commit cc840b3

Please sign in to comment.