Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Parse special chars like - in method and type names #21

Merged
merged 1 commit into from
Jan 26, 2024
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
4 changes: 2 additions & 2 deletions src/Metadata/MethodsParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,14 @@ function (string $parameter): Parameter {

private function parseName(string $methodString): string
{
preg_match('/^\w+ (?P<name>\w+)/', $methodString, $matches);
preg_match('/^[\w-]+ (?P<name>[\w-]+)/', $methodString, $matches);

return $matches['name'];
}

private function parseReturnType(string $methodString): XsdType
{
preg_match('/^(?P<returnType>\w+)/', $methodString, $matches);
preg_match('/^(?P<returnType>[\w-]+)/', $methodString, $matches);

return $this->xsdTypes->fetchByNameWithFallback($matches['returnType']);
}
Expand Down
25 changes: 23 additions & 2 deletions tests/Unit/Metadata/MethodsParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,14 +33,15 @@ public function test_it_can_parse_ext_soap_function_strings()
'TestResponse Test0Param()',
'TestResponse Test1Param(Test1 $parameter1)',
'TestResponse Test2Param(Test1 $parameter1, Test2 $parameter2)',
'list(Response1 $response1, Response2 $response2) TestReturnList()',
'list(Response1 $response1, Response-2 $response2, Response_3 $response3) TestReturnList()',
'list(Response1 $response1, Response2 $response2) TestReturnListWithParams(Test1 $parameter1, Test2 $parameter2)',
'simpleType TestSimpleType(simpleType $parameter1)',
'Test-Response Test-Method(Test-1 $parameter-1)',
'Test_Response Test_Method(Test_1 $parameter_1)',
]
]);

$result = $this->parser->parse($client);

static::assertCount(count($methods), $result);
static::assertEquals(
new Method(
Expand Down Expand Up @@ -100,5 +101,25 @@ public function test_it_can_parse_ext_soap_function_strings()
),
$result->fetchByName('TestSimpleType')
);
static::assertEquals(
new Method(
'Test-Method',
new ParameterCollection(
new Parameter('parameter-1', XsdType::create('Test-1'))
),
XsdType::create('Test-Response')
),
$result->fetchByName('Test-Method')
);
static::assertEquals(
new Method(
'Test_Method',
new ParameterCollection(
new Parameter('parameter_1', XsdType::create('Test_1'))
),
XsdType::create('Test_Response')
),
$result->fetchByName('Test_Method')
);
}
}