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
5 changes: 5 additions & 0 deletions src/Exception/UnloadableWsdlException.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@ public static function fromException(Exception $e): self
{
return new self($e->getMessage(), (int)$e->getCode(), $e);
}

public static function noContentAt(string $location): self
{
return new self('WSDL at location "'.$location.'" returned no content.');
}
}
13 changes: 7 additions & 6 deletions src/Loader/FlatteningLoader.php
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
<?php

declare(strict_types=1);

namespace Soap\Wsdl\Loader;

use Psl\Type\Exception\AssertException;
use Soap\Wsdl\Exception\UnloadableWsdlException;
use Soap\Wsdl\Loader\Context\FlatteningContext;
use Soap\Wsdl\Xml\Flattener;
use VeeWee\Xml\Dom\Document;
use VeeWee\Xml\Exception\RuntimeException;
use function Psl\Type\non_empty_string;

final class FlatteningLoader implements WsdlLoader
{
Expand All @@ -21,14 +20,16 @@ public function __construct(
/**
* @throws RuntimeException
* @throws UnloadableWsdlException
* @throws AssertException
*/
public function __invoke(string $location): string
{
$location = self::normalizeLocation($location);
$currentDoc = Document::fromXmlString(
non_empty_string()->assert(($this->loader)($location))
);
$content = ($this->loader)($location);
if ($content === '') {
throw UnloadableWsdlException::noContentAt($location);
}

$currentDoc = Document::fromXmlString($content);
$context = FlatteningContext::forWsdl($location, $currentDoc, $this->loader);

return (new Flattener())($location, $currentDoc, $context);
Expand Down
13 changes: 13 additions & 0 deletions tests/Unit/Loader/FlatteningLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,19 @@ protected function setUp(): void
$this->loader = new FlatteningLoader(new StreamWrapperLoader());
}

public function test_it_throws_when_content_is_empty(): void
{
$emptyLoader = new class implements WsdlLoader {
public function __invoke(string $location): string
{
return '';
}
};
$this->expectException(UnloadableWsdlException::class);

(new FlatteningLoader($emptyLoader))('http://example.com/service.wsdl');
}

#[DataProvider('provideTestCases')]
public function test_it_can_load_flattened_imports(string $wsdl, Document $expected): void
{
Expand Down