Skip to content

Commit

Permalink
Merge pull request #21 from veewee/parse-method-special-chars
Browse files Browse the repository at this point in the history
Parse special chars like - in method and type names
  • Loading branch information
veewee authored Jan 26, 2024
2 parents c1a195f + 995b7c5 commit 893ab16
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 4 deletions.
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')
);
}
}

0 comments on commit 893ab16

Please sign in to comment.