Skip to content

Commit c19daa9

Browse files
authored
Merge pull request #22 from veewee/find-method-by-soap-action
Find method by SOAP action
2 parents c30e751 + c9b8700 commit c19daa9

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

src/Metadata/Collection/MethodCollection.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,4 +64,19 @@ public function fetchByName(string $name): Method
6464

6565
throw MetadataException::methodNotFound($name);
6666
}
67+
68+
/**
69+
* @throws MetadataException
70+
*/
71+
public function fetchBySoapAction(string $soapAction): Method
72+
{
73+
foreach ($this->methods as $method) {
74+
$meta = $method->getMeta();
75+
if ($meta->action()->isSome() && $soapAction === $meta->action()->unwrap()) {
76+
return $method;
77+
}
78+
}
79+
80+
throw MetadataException::methodNotFound($soapAction);
81+
}
6782
}

tests/Unit/Metadata/Collection/MethodCollectionTest.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use Soap\Engine\Metadata\Collection\MethodCollection;
1010
use Soap\Engine\Metadata\Collection\ParameterCollection;
1111
use Soap\Engine\Metadata\Model\Method;
12+
use Soap\Engine\Metadata\Model\MethodMeta;
1213
use Soap\Engine\Metadata\Model\XsdType;
1314

1415
final class MethodCollectionTest extends TestCase
@@ -18,11 +19,12 @@ final class MethodCollectionTest extends TestCase
1819
protected function setUp(): void
1920
{
2021
$this->collection = new MethodCollection(
21-
new Method('hello', new ParameterCollection(), XsdType::create('Response'))
22+
(new Method('hello', new ParameterCollection(), XsdType::create('Response')))->withMeta(
23+
static fn (MethodMeta $meta) => $meta->withAction('uri:hello')
24+
)
2225
);
2326
}
2427

25-
2628
public function test_it_can_iterate_over_methods(): void
2729
{
2830
static::assertCount(1, $this->collection);
@@ -42,4 +44,16 @@ public function test_it_can_fail_fetching_by_name(): void
4244
$this->expectException(MetadataException::class);
4345
$this->collection->fetchByName('nope');
4446
}
47+
48+
public function test_it_can_fetch_by_soap_action(): void
49+
{
50+
$method = $this->collection->fetchBySoapAction('uri:hello');
51+
static::assertSame('hello', $method->getName());
52+
}
53+
54+
public function test_it_can_fail_fetching_by_soap_action(): void
55+
{
56+
$this->expectException(MetadataException::class);
57+
$this->collection->fetchBySoapAction('uri:nope');
58+
}
4559
}

0 commit comments

Comments
 (0)