Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ COMPOSER ?= /usr/bin/composer
DOCKER_COMPOSE ?= docker compose
DOCKER_EXEC_CONTAINER ?= docker exec -t $(CONTAINER_NAME)

.PHONY: bash build cs-fixer down install phpstan phpunit rector up update
.PHONY: bash build cs-fixer down install jsons phpstan phpunit rector up update

bash:
$(DOCKER_EXEC_CONTAINER) bash
Expand All @@ -21,6 +21,9 @@ down:
install:
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) $(COMPOSER) install

jsons:
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) tests/generate_serialized_jsons.php

phpstan:
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) vendor/bin/phpstan analyze src --level=2

Expand Down
4 changes: 2 additions & 2 deletions src/File/Struct.php
Original file line number Diff line number Diff line change
Expand Up @@ -482,7 +482,7 @@ protected function addStructMethodsSetAndGetAnnotationBlockFromStructAttribute(s
switch ($setOrGet) {
case 'set':
if ($attribute->getRemovableFromRequest()) {
$annotationBlock->addChild('This property is removable from request (nillable=true+minOccurs=0), therefore if the value assigned to this property is null, it is removed from this object');
$annotationBlock->addChild('This property is removable from request (minOccurs=0), therefore if the value assigned to this property is null, it is removed from this object');
}
if ($attribute->isAChoice()) {
$annotationBlock->addChild('This property belongs to a choice that allows only one property to exist. It is therefore removable from the request, consequently if the value assigned to this property is null, the property is removed from this object');
Expand Down Expand Up @@ -514,7 +514,7 @@ protected function addStructMethodsSetAndGetAnnotationBlockFromStructAttribute(s

case 'get':
if ($attribute->getRemovableFromRequest()) {
$annotationBlock->addChild('An additional test has been added (isset) before returning the property value as this property may have been unset before, due to the fact that this property is removable from the request (nillable=true+minOccurs=0)');
$annotationBlock->addChild('An additional test has been added (isset) before returning the property value as this property may have been unset before, due to the fact that this property is removable from the request (minOccurs=0)');
}
$this
->addStructMethodsGetAnnotationBlockFromXmlAttribute($annotationBlock, $attribute)
Expand Down
5 changes: 5 additions & 0 deletions tests/Generator/GeneratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,10 @@ public function testJsonSerialize(): void
$generator = self::getBingGeneratorInstance(true);
$generator->setOptionStandalone(false);
$generator->parse();

// uncomment the next line to easily regenerate file :)
// file_put_contents(sprintf('%sjson_serialized.json', self::getTestDirectory()), trim(json_encode($generator, JSON_PRETTY_PRINT)));

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just wondering but what is the difference to using the generate_serialized_jsons file specified in the Makefile?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These files are used for the tests and it avoids loading the WSDL + the schema each time needs to test a scenario against an element from the WSDL. The JSONs are the results of the parsed WSDL + Schemas and are loaded "instantly", it's just for performance during the tests

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I read again your question I answered too fast! What you say is that the test could rely on one of the updated json files? I did not think of that before 😉 (if that's actually your question)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah. No, my fault for not articulating the question well.

I was actually just wondering regarding the commented out line. It says above that it can be used to regenerate the serialized.json file(s).

However, in the makefile there is a new json entry that is used to call generate_serialized_jsons.php which I guess regenerates all json files?

Just wondering, if one of those would not be enough actually?

However, I guess the commented out line could be helpful if one only runs individual tests?


$jsonContent = file_get_contents(sprintf('%sjson_serialized.json', self::getTestDirectory()));
$jsonContent = str_replace([
'"__ORIGIN__"',
Expand All @@ -606,6 +610,7 @@ public function testJsonSerialize(): void
json_encode(self::wsdlBingPath(), JSON_THROW_ON_ERROR),
json_encode($generator->getOptionDestination(), JSON_THROW_ON_ERROR),
], $jsonContent);

$this->assertSame(trim($jsonContent), trim(json_encode($generator, JSON_PRETTY_PRINT)));
}

Expand Down
4 changes: 2 additions & 2 deletions tests/Parser/Wsdl/TagElementTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public function testParseBing(): void
], $structs->getStructByName('SearchRequest')->getAttribute('Version')->getMeta());
$this->assertSame('string', $structs->getStructByName('SearchRequest')->getAttribute('Version')->getType());
$this->assertFalse($structs->getStructByName('SearchRequest')->getAttribute('Version')->getContainsElements());
$this->assertFalse($structs->getStructByName('SearchRequest')->getAttribute('Version')->getRemovableFromRequest());
$this->assertTrue($structs->getStructByName('SearchRequest')->getAttribute('Version')->getRemovableFromRequest());
++$count;
}
if ($structs->getStructByName('ArrayOfNewsRelatedSearch') instanceof Struct) {
Expand All @@ -58,7 +58,7 @@ public function testParseBing(): void
], $structs->getStructByName('ArrayOfNewsRelatedSearch')->getAttribute('NewsRelatedSearch')->getMeta());
$this->assertSame('NewsRelatedSearch', $structs->getStructByName('ArrayOfNewsRelatedSearch')->getAttribute('NewsRelatedSearch')->getType());
$this->assertTrue($structs->getStructByName('ArrayOfNewsRelatedSearch')->getAttribute('NewsRelatedSearch')->getContainsElements());
$this->assertFalse($structs->getStructByName('ArrayOfNewsRelatedSearch')->getAttribute('NewsRelatedSearch')->getRemovableFromRequest());
$this->assertTrue($structs->getStructByName('ArrayOfNewsRelatedSearch')->getAttribute('NewsRelatedSearch')->getRemovableFromRequest());
++$count;
}
}
Expand Down
91 changes: 77 additions & 14 deletions tests/resources/generated/ValidAdGroupsSelectionCriteria.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,14 @@ public function __construct(?array $campaignIds = null, ?array $ids = null, ?arr
}
/**
* Get CampaignIds value
* An additional test has been added (isset) before returning the property value as
* this property may have been unset before, due to the fact that this property is
* removable from the request (minOccurs=0)
* @return int[]
*/
public function getCampaignIds(): ?array
{
return $this->CampaignIds;
return $this->CampaignIds ?? null;
}
/**
* This method is responsible for validating the value(s) passed to the setCampaignIds method
Expand Down Expand Up @@ -137,6 +140,8 @@ public static function validateCampaignIdsForArrayConstraintFromSetCampaignIds(?
}
/**
* Set CampaignIds value
* This property is removable from request (minOccurs=0), therefore if the value
* assigned to this property is null, it is removed from this object
* @throws InvalidArgumentException
* @param int[] $campaignIds
* @return \StructType\ApiAdGroupsSelectionCriteria
Expand All @@ -147,7 +152,11 @@ public function setCampaignIds(?array $campaignIds = null): self
if ('' !== ($campaignIdsArrayErrorMessage = self::validateCampaignIdsForArrayConstraintFromSetCampaignIds($campaignIds))) {
throw new InvalidArgumentException($campaignIdsArrayErrorMessage, __LINE__);
}
$this->CampaignIds = $campaignIds;
if (is_null($campaignIds) || (is_array($campaignIds) && empty($campaignIds))) {
unset($this->CampaignIds);
} else {
$this->CampaignIds = $campaignIds;
}

return $this;
}
Expand All @@ -169,11 +178,14 @@ public function addToCampaignIds(int $item): self
}
/**
* Get Ids value
* An additional test has been added (isset) before returning the property value as
* this property may have been unset before, due to the fact that this property is
* removable from the request (minOccurs=0)
* @return int[]
*/
public function getIds(): ?array
{
return $this->Ids;
return $this->Ids ?? null;
}
/**
* This method is responsible for validating the value(s) passed to the setIds method
Expand Down Expand Up @@ -204,6 +216,8 @@ public static function validateIdsForArrayConstraintFromSetIds(?array $values =
}
/**
* Set Ids value
* This property is removable from request (minOccurs=0), therefore if the value
* assigned to this property is null, it is removed from this object
* @throws InvalidArgumentException
* @param int[] $ids
* @return \StructType\ApiAdGroupsSelectionCriteria
Expand All @@ -214,7 +228,11 @@ public function setIds(?array $ids = null): self
if ('' !== ($idsArrayErrorMessage = self::validateIdsForArrayConstraintFromSetIds($ids))) {
throw new InvalidArgumentException($idsArrayErrorMessage, __LINE__);
}
$this->Ids = $ids;
if (is_null($ids) || (is_array($ids) && empty($ids))) {
unset($this->Ids);
} else {
$this->Ids = $ids;
}

return $this;
}
Expand All @@ -236,11 +254,14 @@ public function addToIds(int $item): self
}
/**
* Get Types value
* An additional test has been added (isset) before returning the property value as
* this property may have been unset before, due to the fact that this property is
* removable from the request (minOccurs=0)
* @return string[]
*/
public function getTypes(): ?array
{
return $this->Types;
return $this->Types ?? null;
}
/**
* This method is responsible for validating the value(s) passed to the setTypes method
Expand Down Expand Up @@ -271,6 +292,8 @@ public static function validateTypesForArrayConstraintFromSetTypes(?array $value
}
/**
* Set Types value
* This property is removable from request (minOccurs=0), therefore if the value
* assigned to this property is null, it is removed from this object
* @uses \EnumType\ApiAdGroupTypesEnum::valueIsValid()
* @uses \EnumType\ApiAdGroupTypesEnum::getValidValues()
* @throws InvalidArgumentException
Expand All @@ -283,7 +306,11 @@ public function setTypes(?array $types = null): self
if ('' !== ($typesArrayErrorMessage = self::validateTypesForArrayConstraintFromSetTypes($types))) {
throw new InvalidArgumentException($typesArrayErrorMessage, __LINE__);
}
$this->Types = $types;
if (is_null($types) || (is_array($types) && empty($types))) {
unset($this->Types);
} else {
$this->Types = $types;
}

return $this;
}
Expand All @@ -307,11 +334,14 @@ public function addToTypes(string $item): self
}
/**
* Get Statuses value
* An additional test has been added (isset) before returning the property value as
* this property may have been unset before, due to the fact that this property is
* removable from the request (minOccurs=0)
* @return string[]
*/
public function getStatuses(): ?array
{
return $this->Statuses;
return $this->Statuses ?? null;
}
/**
* This method is responsible for validating the value(s) passed to the setStatuses method
Expand Down Expand Up @@ -342,6 +372,8 @@ public static function validateStatusesForArrayConstraintFromSetStatuses(?array
}
/**
* Set Statuses value
* This property is removable from request (minOccurs=0), therefore if the value
* assigned to this property is null, it is removed from this object
* @uses \EnumType\ApiStatusSelectionEnum::valueIsValid()
* @uses \EnumType\ApiStatusSelectionEnum::getValidValues()
* @throws InvalidArgumentException
Expand All @@ -354,7 +386,11 @@ public function setStatuses(?array $statuses = null): self
if ('' !== ($statusesArrayErrorMessage = self::validateStatusesForArrayConstraintFromSetStatuses($statuses))) {
throw new InvalidArgumentException($statusesArrayErrorMessage, __LINE__);
}
$this->Statuses = $statuses;
if (is_null($statuses) || (is_array($statuses) && empty($statuses))) {
unset($this->Statuses);
} else {
$this->Statuses = $statuses;
}

return $this;
}
Expand All @@ -378,11 +414,14 @@ public function addToStatuses(string $item): self
}
/**
* Get TagIds value
* An additional test has been added (isset) before returning the property value as
* this property may have been unset before, due to the fact that this property is
* removable from the request (minOccurs=0)
* @return int[]
*/
public function getTagIds(): ?array
{
return $this->TagIds;
return $this->TagIds ?? null;
}
/**
* This method is responsible for validating the value(s) passed to the setTagIds method
Expand Down Expand Up @@ -413,6 +452,8 @@ public static function validateTagIdsForArrayConstraintFromSetTagIds(?array $val
}
/**
* Set TagIds value
* This property is removable from request (minOccurs=0), therefore if the value
* assigned to this property is null, it is removed from this object
* @throws InvalidArgumentException
* @param int[] $tagIds
* @return \StructType\ApiAdGroupsSelectionCriteria
Expand All @@ -423,7 +464,11 @@ public function setTagIds(?array $tagIds = null): self
if ('' !== ($tagIdsArrayErrorMessage = self::validateTagIdsForArrayConstraintFromSetTagIds($tagIds))) {
throw new InvalidArgumentException($tagIdsArrayErrorMessage, __LINE__);
}
$this->TagIds = $tagIds;
if (is_null($tagIds) || (is_array($tagIds) && empty($tagIds))) {
unset($this->TagIds);
} else {
$this->TagIds = $tagIds;
}

return $this;
}
Expand All @@ -445,11 +490,14 @@ public function addToTagIds(int $item): self
}
/**
* Get Tags value
* An additional test has been added (isset) before returning the property value as
* this property may have been unset before, due to the fact that this property is
* removable from the request (minOccurs=0)
* @return string[]
*/
public function getTags(): ?array
{
return $this->Tags;
return $this->Tags ?? null;
}
/**
* This method is responsible for validating the value(s) passed to the setTags method
Expand Down Expand Up @@ -480,6 +528,8 @@ public static function validateTagsForArrayConstraintFromSetTags(?array $values
}
/**
* Set Tags value
* This property is removable from request (minOccurs=0), therefore if the value
* assigned to this property is null, it is removed from this object
* @throws InvalidArgumentException
* @param string[] $tags
* @return \StructType\ApiAdGroupsSelectionCriteria
Expand All @@ -490,7 +540,11 @@ public function setTags(?array $tags = null): self
if ('' !== ($tagsArrayErrorMessage = self::validateTagsForArrayConstraintFromSetTags($tags))) {
throw new InvalidArgumentException($tagsArrayErrorMessage, __LINE__);
}
$this->Tags = $tags;
if (is_null($tags) || (is_array($tags) && empty($tags))) {
unset($this->Tags);
} else {
$this->Tags = $tags;
}

return $this;
}
Expand All @@ -512,11 +566,14 @@ public function addToTags(string $item): self
}
/**
* Get AppIconStatuses value
* An additional test has been added (isset) before returning the property value as
* this property may have been unset before, due to the fact that this property is
* removable from the request (minOccurs=0)
* @return string[]
*/
public function getAppIconStatuses(): ?array
{
return $this->AppIconStatuses;
return $this->AppIconStatuses ?? null;
}
/**
* This method is responsible for validating the value(s) passed to the setAppIconStatuses method
Expand Down Expand Up @@ -547,6 +604,8 @@ public static function validateAppIconStatusesForArrayConstraintFromSetAppIconSt
}
/**
* Set AppIconStatuses value
* This property is removable from request (minOccurs=0), therefore if the value
* assigned to this property is null, it is removed from this object
* @uses \EnumType\ApiStatusSelectionEnum::valueIsValid()
* @uses \EnumType\ApiStatusSelectionEnum::getValidValues()
* @throws InvalidArgumentException
Expand All @@ -559,7 +618,11 @@ public function setAppIconStatuses(?array $appIconStatuses = null): self
if ('' !== ($appIconStatusesArrayErrorMessage = self::validateAppIconStatusesForArrayConstraintFromSetAppIconStatuses($appIconStatuses))) {
throw new InvalidArgumentException($appIconStatusesArrayErrorMessage, __LINE__);
}
$this->AppIconStatuses = $appIconStatuses;
if (is_null($appIconStatuses) || (is_array($appIconStatuses) && empty($appIconStatuses))) {
unset($this->AppIconStatuses);
} else {
$this->AppIconStatuses = $appIconStatuses;
}

return $this;
}
Expand Down
Loading
Loading