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
17 changes: 10 additions & 7 deletions src/Metadata/Collection/TypeCollection.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
use IteratorAggregate;
use Soap\Engine\Exception\MetadataException;
use Soap\Engine\Metadata\Model\Type;
use function array_key_exists;
use function Psl\Dict\reindex;

/**
Expand Down Expand Up @@ -108,17 +107,21 @@ public function fetchFirstByName(string $name): Type
throw MetadataException::typeNotFound($name);
}

/**
* Convention: fetch* throws when the type is missing, find* returns null.
*/
public function findByNameAndXmlNamespace(string $name, string $namespace): ?Type
{
return $this->qualifiedLookup[self::createLookupKey($name, $namespace)] ?? null;
}

/**
* @throws MetadataException
*/
public function fetchByNameAndXmlNamespace(string $name, string $namespace): Type
{
$lookupKey = self::createLookupKey($name, $namespace);
if (!array_key_exists($lookupKey, $this->qualifiedLookup)) {
throw MetadataException::typeNotFound($name);
}

return $this->qualifiedLookup[$lookupKey];
return $this->findByNameAndXmlNamespace($name, $namespace)
?? throw MetadataException::typeNotFound($name);
}

private static function createLookupKey(string $name, string $namespace): string
Expand Down
16 changes: 16 additions & 0 deletions tests/Unit/Metadata/Collection/TypeCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,22 @@ public function test_it_can_fail_fetching_by_name_and_namespace_invalid_namespac
$this->collection->fetchByNameAndXmlNamespace('Response', 'http://invalid');
}

public function test_it_can_find_by_name_and_namespace(): void
{
$type = $this->collection->findByNameAndXmlNamespace('Response', 'http://namesapce');
static::assertSame('Response', $type?->getName());
}

public function test_it_finds_nothing_by_name_and_namespace_for_invalid_name(): void
{
static::assertNull($this->collection->findByNameAndXmlNamespace('nope', 'http://namesapce'));
}

public function test_it_finds_nothing_by_name_and_namespace_for_other_namespace(): void
{
static::assertNull($this->collection->findByNameAndXmlNamespace('Response', 'http://invalid'));
}

public function test_it_can_reduce(): void
{
$result = $this->collection->reduce(static fn (int $i, Type $item) => $i + 1, 0);
Expand Down
Loading