Skip to content

Commit

Permalink
Fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
veewee committed Sep 22, 2023
1 parent 13eb7d6 commit 0d8172a
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 21 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
"php": "~8.1.0 || ~8.2.0",
"azjezz/psl": "^2.1",
"laminas/laminas-code": "^4.8.0",
"php-soap/engine": "^2.3",
"php-soap/engine": "^2.4",
"php-soap/ext-soap-engine": "^1.4",
"php-soap/psr18-transport": "^1.3",
"php-soap/wsdl-reader": "~0.3",
"php-soap/wsdl-reader": "~0.5",
"psr/event-dispatcher": "^1.0",
"psr/log": "^1.0 || ^2.0 || ^3.0",
"symfony/console": "~5.4 || ~6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ private function generateMethodBody(
ClientMethod $method,
$context
): string {
$assertInstanceOf = static fn (string $class): string =>
'\\Psl\\Type\\instance_of(\\'.ltrim($class, '\\').'::class)->assert($response);';

$code = [
sprintf(
'$response = ($this->caller)(\'%s\', %s);',
Expand All @@ -88,8 +91,8 @@ private function generateMethodBody(
: '$'.$param->getName()
),
'',
'\\assert($response instanceof \\'.ltrim($this->decideOnReturnType($context, true), '\\').');',
'\\assert($response instanceof \\'.ResultInterface::class.');',
$assertInstanceOf($this->decideOnReturnType($context, true)),
$assertInstanceOf(ResultInterface::class),
'',
'return $response;',
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function assemble(ContextInterface $context)
$meta = $type->getMeta();
$extending = $meta->extends()->unwrapOr(null);

if (!$extending || $extending['isSimple']) {
if (!$extending || ($extending['isSimple'] ?? false)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,14 @@ public function __invoke(TypeMeta $meta): string
*/
static function (array $union): string {
$type = $union['type'];
$type = Normalizer::isKnownType($type) ? $type : 'mixed'; // Todo : resolve bottom type of the selected simple type??

// The union type could be a nested simple type.
// If the normalizer does not know the type,
// this implementation falls back to 'mixed' in that case.
//
// A possible improvement here could be to parse and store the inferred bottom type
//as meta-info inside the union meta instead.
$type = Normalizer::isKnownType($type) ? $type : 'mixed';

return $union['isList'] ? 'list<'.$type.'>' : $type;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,12 @@ class MyClient
*/
public function functionName(\Vendor\MyTypeNamespace\ParamType \$param) : \Vendor\MyTypeNamespace\ReturnType
{
return (\$this->caller)('functionName', \$param);
\$response = (\$this->caller)('functionName', \$param);
\Psl\Type\instance_of(\Vendor\MyTypeNamespace\ReturnType::class)->assert(\$response);
\Psl\Type\instance_of(\Phpro\SoapClient\Type\ResultInterface::class)->assert(\$response);
return \$response;
}
}
Expand Down Expand Up @@ -178,7 +183,12 @@ class MyClient
*/
public function functionName(\Phpro\SoapClient\Type\MultiArgumentRequest \$multiArgumentRequest) : \Vendor\MyTypeNamespace\ReturnType
{
return (\$this->caller)('functionName', \$multiArgumentRequest);
\$response = (\$this->caller)('functionName', \$multiArgumentRequest);
\Psl\Type\instance_of(\Vendor\MyTypeNamespace\ReturnType::class)->assert(\$response);
\Psl\Type\instance_of(\Phpro\SoapClient\Type\ResultInterface::class)->assert(\$response);
return \$response;
}
}
Expand Down Expand Up @@ -212,7 +222,12 @@ class MyClient
*/
public function functionName() : \Vendor\MyTypeNamespace\ReturnType
{
return (\$this->caller)('functionName', new MultiArgumentRequest([]));
\$response = (\$this->caller)('functionName', new MultiArgumentRequest([]));
\Psl\Type\instance_of(\Vendor\MyTypeNamespace\ReturnType::class)->assert(\$response);
\Psl\Type\instance_of(\Phpro\SoapClient\Type\ResultInterface::class)->assert(\$response);
return \$response;
}
}
Expand Down Expand Up @@ -260,7 +275,12 @@ class MyClient
*/
public function function_name(\Vendor\MyTypeNamespace\ParamType \$param) : \Vendor\MyTypeNamespace\ReturnType
{
return (\$this->caller)('Function_name', \$param);
\$response = (\$this->caller)('Function_name', \$param);
\Psl\Type\instance_of(\Vendor\MyTypeNamespace\ReturnType::class)->assert(\$response);
\Psl\Type\instance_of(\Phpro\SoapClient\Type\ResultInterface::class)->assert(\$response);
return \$response;
}
}
Expand Down Expand Up @@ -328,7 +348,12 @@ class MyClient
*/
public function function_name(\Phpro\SoapClient\Type\MultiArgumentRequest \$multiArgumentRequest) : \Vendor\MyTypeNamespace\ReturnType
{
return (\$this->caller)('Function_name', \$multiArgumentRequest);
\$response = (\$this->caller)('Function_name', \$multiArgumentRequest);
\Psl\Type\instance_of(\Vendor\MyTypeNamespace\ReturnType::class)->assert(\$response);
\Psl\Type\instance_of(\Phpro\SoapClient\Type\ResultInterface::class)->assert(\$response);
return \$response;
}
}
Expand Down Expand Up @@ -376,7 +401,12 @@ class MyClient
*/
public function functionName() : \Phpro\SoapClient\Type\MixedResult
{
return (\$this->caller)('functionName', new MultiArgumentRequest([]));
\$response = (\$this->caller)('functionName', new MultiArgumentRequest([]));
\Psl\Type\instance_of(\Phpro\SoapClient\Type\MixedResult::class)->assert(\$response);
\Psl\Type\instance_of(\Phpro\SoapClient\Type\ResultInterface::class)->assert(\$response);
return \$response;
}
}
Expand Down Expand Up @@ -433,7 +463,12 @@ class MyClient
*/
public function functionName(\Phpro\SoapClient\Type\MultiArgumentRequest \$multiArgumentRequest) : \Phpro\SoapClient\Type\MixedResult
{
return (\$this->caller)('functionName', \$multiArgumentRequest);
\$response = (\$this->caller)('functionName', \$multiArgumentRequest);
\Psl\Type\instance_of(\Phpro\SoapClient\Type\MixedResult::class)->assert(\$response);
\Psl\Type\instance_of(\Phpro\SoapClient\Type\ResultInterface::class)->assert(\$response);
return \$response;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function provideExpectations()
['type' => 'My_Type', 'isList' => false, 'namespace' => 'xx'],
['type' => 'Your_Type', 'isList' => true, 'namespace' => 'xx'],
]),
"MyType | list<YourType>",
"mixed | list<mixed>",
];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,11 @@ public function provideTests()
(new TypeMeta()),
false,
];
yield 'list' => [
(new TypeMeta())->withIsList(true),
true,
];
yield 'nullable' => [
(new TypeMeta())->withIsNullable(true),
yield 'simple' => [
(new TypeMeta())->withIsSimple(true),
true,
];
yield 'simple' => [
yield 'attribute' => [
(new TypeMeta())->withIsSimple(true),
true,
];
Expand Down

0 comments on commit 0d8172a

Please sign in to comment.