Skip to content

Commit

Permalink
Merge pull request #22 from veewee/find-method-by-soap-action
Browse files Browse the repository at this point in the history
Find method by SOAP action
  • Loading branch information
veewee authored Jan 3, 2025
2 parents c30e751 + c9b8700 commit c19daa9
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
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');
}
}

0 comments on commit c19daa9

Please sign in to comment.