Skip to content
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
15 changes: 15 additions & 0 deletions src/Metadata/Collection/MethodCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,19 @@ public function fetchByName(string $name): Method

throw MetadataException::methodNotFound($name);
}

/**
* @throws MetadataException
*/
public function fetchBySoapAction(string $soapAction): Method
{
foreach ($this->methods as $method) {
$meta = $method->getMeta();
if ($meta->action()->isSome() && $soapAction === $meta->action()->unwrap()) {
return $method;
}
}

throw MetadataException::methodNotFound($soapAction);
}
}
18 changes: 16 additions & 2 deletions tests/Unit/Metadata/Collection/MethodCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Soap\Engine\Metadata\Collection\MethodCollection;
use Soap\Engine\Metadata\Collection\ParameterCollection;
use Soap\Engine\Metadata\Model\Method;
use Soap\Engine\Metadata\Model\MethodMeta;
use Soap\Engine\Metadata\Model\XsdType;

final class MethodCollectionTest extends TestCase
Expand All @@ -18,11 +19,12 @@ final class MethodCollectionTest extends TestCase
protected function setUp(): void
{
$this->collection = new MethodCollection(
new Method('hello', new ParameterCollection(), XsdType::create('Response'))
(new Method('hello', new ParameterCollection(), XsdType::create('Response')))->withMeta(
static fn (MethodMeta $meta) => $meta->withAction('uri:hello')
)
);
}


public function test_it_can_iterate_over_methods(): void
{
static::assertCount(1, $this->collection);
Expand All @@ -42,4 +44,16 @@ public function test_it_can_fail_fetching_by_name(): void
$this->expectException(MetadataException::class);
$this->collection->fetchByName('nope');
}

public function test_it_can_fetch_by_soap_action(): void
{
$method = $this->collection->fetchBySoapAction('uri:hello');
static::assertSame('hello', $method->getName());
}

public function test_it_can_fail_fetching_by_soap_action(): void
{
$this->expectException(MetadataException::class);
$this->collection->fetchBySoapAction('uri:nope');
}
}
Loading