Skip to content

Commit 176c442

Browse files
committed
update PhpGenerator and tests
1 parent db8a42c commit 176c442

12 files changed

Lines changed: 56 additions & 19 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ phpstan:
2525
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) vendor/bin/phpstan analyze src --level=2
2626

2727
phpunit:
28-
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) vendor/bin/phpunit
28+
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) vendor/bin/phpunit --stop-on-failure --stop-on-error $(ARGS)
2929

3030
rector:
3131
$(DOCKER_EXEC_CONTAINER) $(PHP_VERSION) vendor/bin/rector process

src/File/Service.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,7 @@ protected function getSoapHeaderMethod(string $methodName, string $soapHeaderNam
175175
$firstParameter = new PhpFunctionParameter(lcfirst($soapHeaderName), PhpFunctionParameterBase::NO_VALUE, $this->getTypeFromName($soapHeaderType)),
176176
new PhpFunctionParameterBase(self::PARAM_SET_HEADER_NAMESPACE, $soapHeaderNamespace, self::TYPE_STRING),
177177
new PhpFunctionParameterBase(self::PARAM_SET_HEADER_MUSTUNDERSTAND, false, self::TYPE_BOOL),
178-
new PhpFunctionParameterBase(self::PARAM_SET_HEADER_ACTOR, null, '?'.self::TYPE_STRING),
178+
new PhpFunctionParameterBase(self::PARAM_SET_HEADER_ACTOR, null, self::TYPE_STRING),
179179
], self::TYPE_SELF);
180180

181181
$model = $this->getModelByName($soapHeaderType);

src/File/Struct.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@ protected function getStructMethodParameter(StructAttributeModel $attribute): Ph
182182
break;
183183

184184
default:
185-
$type = (($attribute->isRequired() && !$attribute->isNullable()) ? '' : '?').$this->getStructAttributeTypeAsPhpType($attribute);
185+
$type = $this->getStructAttributeTypeAsPhpType($attribute);
186186

187187
break;
188188
}
@@ -192,7 +192,7 @@ protected function getStructMethodParameter(StructAttributeModel $attribute): Ph
192192

193193
return new PhpFunctionParameter(
194194
lcfirst($attribute->getUniqueString($attribute->getCleanName(), 'method')),
195-
$attribute->isRequired() && !$attribute->isAChoice() ? AssignedValueElementInterface::NO_VALUE : (str_contains($type ?? '', '?') ? $defaultValue ?? null : $defaultValue),
195+
$attribute->isRequired() && !$attribute->isAChoice() ? AssignedValueElementInterface::NO_VALUE : (($attribute->isRequired() && !$attribute->isNullable()) ? $defaultValue ?? null : $defaultValue),
196196
$type,
197197
$attribute
198198
);

src/File/Validation/AbstractRule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ final protected function addArrayValidationMethod(string $parameterName, $value)
9494
ucfirst($this->getAttribute()->getCleanName())
9595
);
9696
$method = new PhpMethod($this->getValidationMethodName($parameterName), [
97-
new PhpFunctionParameter('values', null, '?array'),
97+
new PhpFunctionParameter('values', null, 'array'),
9898
], AbstractModelFile::TYPE_STRING, PhpMethod::ACCESS_PUBLIC, false, true);
9999

100100
$method

src/Parser/Wsdl/AbstractTagInputOutputParser.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use WsdlToPhp\PackageGenerator\Model\Method;
88
use WsdlToPhp\PackageGenerator\Model\Wsdl;
99
use WsdlToPhp\WsdlHandler\Tag\AbstractTagOperationElement;
10-
use WsdlToPhp\WsdlHandler\Tag\TagOperation;
1110
use WsdlToPhp\WsdlHandler\Tag\TagPart;
1211

1312
abstract class AbstractTagInputOutputParser extends AbstractTagParser
@@ -21,7 +20,7 @@ public function parseInputOutput(AbstractTagOperationElement $tag): void
2120
}
2221

2322
$operation = $tag->getParentOperation();
24-
if (!$operation instanceof TagOperation) {
23+
if (!$operation) {
2524
return;
2625
}
2726

@@ -40,7 +39,6 @@ public function parseInputOutput(AbstractTagOperationElement $tag): void
4039
return;
4140
}
4241

43-
$multipleParts = count($parts);
4442
if (1 < count($parts)) {
4543
$types = [];
4644
foreach ($parts as $part) {
@@ -85,6 +83,6 @@ protected function isKnownTypeUnknown(Method $method): bool
8583
}
8684
}
8785

88-
return (bool) !$isKnown;
86+
return !$isKnown;
8987
}
9088
}

tests/Container/Model/StructAttributeContainerTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ public function testGetStructAttributeByName(): void
3131
{
3232
$structAttributeContainer = self::instance();
3333

34-
self::assertInstanceOf(\WsdlTophp\PackageGenerator\Model\StructAttribute::class, $structAttributeContainer->getStructAttributeByName('foo'));
35-
self::assertInstanceOf(\WsdlTophp\PackageGenerator\Model\StructAttribute::class, $structAttributeContainer->getStructAttributeByName('bar'));
36-
self::assertInstanceOf(\WsdlTophp\PackageGenerator\Model\StructAttribute::class, $structAttributeContainer->getStructAttributeByName('fooBar'));
34+
self::assertInstanceOf(StructAttribute::class, $structAttributeContainer->getStructAttributeByName('foo'));
35+
self::assertInstanceOf(StructAttribute::class, $structAttributeContainer->getStructAttributeByName('bar'));
36+
self::assertInstanceOf(StructAttribute::class, $structAttributeContainer->getStructAttributeByName('fooBar'));
3737
self::assertNull($structAttributeContainer->getStructAttributeByName('foobar'));
3838
}
3939
}

tests/File/AbstractFile.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ protected function assertSameFileContent(string $valid, File $file, string $file
5252
$this->fail(sprintf('Generated file "%s" could not be found', $file->getFileName()));
5353
}
5454

55-
// uncomment next line to easily regenerate all valid files :)
55+
// uncomment the next line to easily regenerate all valid files :)
5656
// file_put_contents(sprintf('%s%s.%s', self::getTestDirectory(), $valid, $fileExtension), str_replace($file->getGenerator()->getWsdl()->getName(), '__WSDL_URL__', file_get_contents($file->getFileName())));
5757

5858
$validContent = file_get_contents(sprintf('%s%s.%s', self::getTestDirectory(), $valid, $fileExtension));

tests/File/Validation/AbstractRule.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,25 @@ abstract class AbstractRule extends AbstractTestCase
1919
{
2020
private static array $generators = [];
2121

22+
/**
23+
* @throws \ReflectionException
24+
*/
2225
public static function getActonItemInstance(bool $reset = false)
2326
{
2427
return self::getClassInstance('actonGeneratorInstance', 'Item', $reset);
2528
}
2629

30+
/**
31+
* @throws \ReflectionException
32+
*/
2733
public static function getWhlAddressTypeInstance(bool $reset = false)
2834
{
2935
return self::getClassInstance('whlInstance', 'AddressType', $reset);
3036
}
3137

38+
/**
39+
* @throws \ReflectionException
40+
*/
3241
public static function getWhlBookingChannelInstance(bool $reset = false)
3342
{
3443
return self::getClassInstance('whlInstance', 'BookingChannel', $reset);
@@ -159,6 +168,12 @@ protected static function createClassInstance(Struct $struct)
159168
@unlink($structFile->getFileName());
160169
}
161170

171+
/**
172+
* @param mixed $instanceMethod
173+
* @param mixed $structName
174+
* @param mixed $reset
175+
* @throws \ReflectionException
176+
*/
162177
private static function getClassInstance($instanceMethod, $structName, $reset = false)
163178
{
164179
$key = implode('_', [

tests/File/Validation/ArrayRuleTest.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,15 @@ final class ArrayRuleTest extends AbstractRule
1515
{
1616
/**
1717
* The AddressLine
18-
* Meta informations extracted from the WSDL
18+
* Meta information extracted from the WSDL
1919
* - documentation: When the address is unformatted (FormattedInd="false") these lines will contain free form address details. When the address is formatted and street number and street name must be sent independently, the street number will be sent
2020
* using StreetNmbr, and the street name will be sent in the first AddressLine occurrence. | Used for Character Strings, length 1 to 255.
2121
* - maxOccurs: 5
2222
* - minOccurs: 0
2323
* - base: xs:string
2424
* - maxLength: 255
2525
* - minLength: 1.
26+
* @throws \ReflectionException
2627
*/
2728
public function testSetAddressLineWithNullOnOneItemMustThrowAnException(): void
2829
{
@@ -42,7 +43,7 @@ public function testSetAddressLineWithNullOnOneItemMustThrowAnException(): void
4243

4344
/**
4445
* The AddressLine
45-
* Meta informations extracted from the WSDL
46+
* Meta information extracted from the WSDL
4647
* - documentation: When the address is unformatted (FormattedInd="false") these lines will contain free form address details. When the address is formatted and street number and street name must be sent independently, the street number will be sent
4748
* using StreetNmbr, and the street name will be sent in the first AddressLine occurrence. | Used for Character Strings, length 1 to 255.
4849
* - maxOccurs: 5
@@ -51,6 +52,7 @@ public function testSetAddressLineWithNullOnOneItemMustThrowAnException(): void
5152
* - maxLength: 255
5253
* - minLength: 1.
5354
*
55+
* @throws \ReflectionException
5456
* @var string[]
5557
*/
5658
public function testSetAddressLineWithStringsMustPass(): void

tests/File/Validation/XmlRuleTest.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
*/
1111
final class XmlRuleTest extends AbstractRule
1212
{
13+
/**
14+
* @throws \ReflectionException
15+
*/
1316
public function testSetAnyWithEmptyStringMustThrowAnException(): void
1417
{
1518
$this->expectException(\InvalidArgumentException::class);
@@ -19,6 +22,9 @@ public function testSetAnyWithEmptyStringMustThrowAnException(): void
1922
$instance->setAny('');
2023
}
2124

25+
/**
26+
* @throws \ReflectionException
27+
*/
2228
public function testSetAnyWithInvalidXmlStringMustThrowAnException(): void
2329
{
2430
$this->expectException(\InvalidArgumentException::class);
@@ -28,6 +34,9 @@ public function testSetAnyWithInvalidXmlStringMustThrowAnException(): void
2834
@$instance->setAny('<attribute>1</attribute');
2935
}
3036

37+
/**
38+
* @throws \ReflectionException
39+
*/
3140
public function testSetAnyWithValidXmlStringMustPass(): void
3241
{
3342
$instance = self::getActonItemInstance();
@@ -37,6 +46,9 @@ public function testSetAnyWithValidXmlStringMustPass(): void
3746
$this->assertSame($string, $instance->getAny());
3847
}
3948

49+
/**
50+
* @throws \ReflectionException
51+
*/
4052
public function testSetAnyWithIntMustThrowAnException(): void
4153
{
4254
$this->expectException(\InvalidArgumentException::class);
@@ -46,6 +58,10 @@ public function testSetAnyWithIntMustThrowAnException(): void
4658
$instance->setAny(2);
4759
}
4860

61+
/**
62+
* @throws \DOMException
63+
* @throws \ReflectionException
64+
*/
4965
public function testSetAnyWithDomDocumentMustPass(): void
5066
{
5167
$instance = self::getActonItemInstance();
@@ -57,6 +73,9 @@ public function testSetAnyWithDomDocumentMustPass(): void
5773
$this->assertSame('<element>147</element>', $instance->getAny());
5874
}
5975

76+
/**
77+
* @throws \ReflectionException
78+
*/
6079
public function testSetAnyWithInvalidObjectMustThrowAnException(): void
6180
{
6281
$this->expectException(\InvalidArgumentException::class);
@@ -66,6 +85,9 @@ public function testSetAnyWithInvalidObjectMustThrowAnException(): void
6685
$instance->setAny(new \stdClass());
6786
}
6887

88+
/**
89+
* @throws \ReflectionException
90+
*/
6991
public function testSetAnyWithArrayMustThrowAnException(): void
7092
{
7193
$this->expectException(\InvalidArgumentException::class);

0 commit comments

Comments
 (0)