-
-
Notifications
You must be signed in to change notification settings - Fork 175
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add functional tests for debugging harder issues
- Loading branch information
Showing
15 changed files
with
533 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
spec/Phpro/SoapClient/Wsdl/Provider/InMemoryWsdlProviderSpec.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace spec\Phpro\SoapClient\Wsdl\Provider; | ||
|
||
use Phpro\SoapClient\Wsdl\Provider\InMemoryWsdlProvider; | ||
use Phpro\SoapClient\Wsdl\Provider\WsdlProviderInterface; | ||
use PhpSpec\ObjectBehavior; | ||
|
||
class InMemoryWsdlProviderSpec extends ObjectBehavior | ||
{ | ||
function it_is_initializable() | ||
{ | ||
$this->shouldHaveType(InMemoryWsdlProvider::class); | ||
} | ||
|
||
function it_is_a_wsdl_provider() | ||
{ | ||
$this->shouldImplement(WsdlProviderInterface::class); | ||
} | ||
|
||
function it_provides_an_in_memory_data_source() | ||
{ | ||
$this->provide('source')->shouldBe('data://text/plain;base64,'.base64_encode('source')); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
src/Phpro/SoapClient/Soap/Handler/LocalSoapServerHandle.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
|
||
namespace Phpro\SoapClient\Soap\Handler; | ||
|
||
use Phpro\SoapClient\Soap\HttpBinding\LastRequestInfo; | ||
use Phpro\SoapClient\Soap\HttpBinding\SoapRequest; | ||
use Phpro\SoapClient\Soap\HttpBinding\SoapResponse; | ||
use SoapServer; | ||
|
||
class LocalSoapServerHandle implements HandlerInterface, LastRequestInfoCollectorInterface | ||
{ | ||
/** | ||
* @var SoapServer | ||
*/ | ||
private $server; | ||
|
||
/** | ||
* @var LastRequestInfo | ||
*/ | ||
private $lastRequestInfo; | ||
|
||
public function __construct(SoapServer $server) | ||
{ | ||
$this->server = $server; | ||
$this->lastRequestInfo = LastRequestInfo::createEmpty(); | ||
} | ||
|
||
/** | ||
* @param SoapRequest $request | ||
* | ||
* @return SoapResponse | ||
*/ | ||
public function request(SoapRequest $request): SoapResponse | ||
{ | ||
ob_start(); | ||
$this->server->handle($request->getRequest()); | ||
$responseBody = ob_get_contents(); | ||
ob_end_clean(); | ||
|
||
$this->lastRequestInfo = new LastRequestInfo( | ||
'', | ||
$request->getRequest(), | ||
'', | ||
$responseBody | ||
); | ||
|
||
return new SoapResponse($responseBody); | ||
} | ||
|
||
/** | ||
* @return LastRequestInfo | ||
*/ | ||
public function collectLastRequestInfo(): LastRequestInfo | ||
{ | ||
return $this->lastRequestInfo; | ||
} | ||
} |
13 changes: 13 additions & 0 deletions
13
src/Phpro/SoapClient/Wsdl/Provider/InMemoryWsdlProvider.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare( strict_types=1 ); | ||
|
||
namespace Phpro\SoapClient\Wsdl\Provider; | ||
|
||
class InMemoryWsdlProvider implements WsdlProviderInterface | ||
{ | ||
public function provide(string $source): string | ||
{ | ||
return 'data://text/plain;base64,'.base64_encode($source); | ||
} | ||
} |
67 changes: 67 additions & 0 deletions
67
test/PhproTest/SoapClient/Functional/AbstractSoapTestCase.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
<?php | ||
|
||
declare( strict_types=1 ); | ||
|
||
namespace PhproTest\SoapClient\Functional; | ||
|
||
use Phpro\SoapClient\Soap\Handler\LocalSoapServerHandle; | ||
use Phpro\SoapClient\Soap\SoapClient as PhproSoapClient; | ||
use Phpro\SoapClient\Wsdl\Provider\InMemoryWsdlProvider; | ||
use PHPUnit\Framework\TestCase; | ||
use SoapServer; | ||
|
||
abstract class AbstractSoapTestCase extends TestCase | ||
{ | ||
/** | ||
* @var SoapServer | ||
*/ | ||
protected $server; | ||
|
||
/** | ||
* @var PhproSoapClient | ||
*/ | ||
protected $client; | ||
|
||
/** | ||
* @return SoapServer | ||
*/ | ||
abstract protected function configureServer(SoapServer $server); | ||
|
||
/** | ||
* @return string|null | ||
*/ | ||
abstract protected function getWsdl(); | ||
abstract protected function getSoapOptions(): array; | ||
|
||
protected function setUp() { | ||
$wsdl = $this->getWsdl(); | ||
$options = $this->getSoapOptions(); | ||
|
||
$this->server = new SoapServer($wsdl, $options); | ||
$this->configureServer($this->server); | ||
|
||
$this->client = new PhproSoapClient($wsdl, $options); | ||
$this->client->setHandler(new LocalSoapServerHandle($this->server)); | ||
} | ||
|
||
protected function generateInMemoryWsdl(string $wsdl): string | ||
{ | ||
return (new InMemoryWsdlProvider())->provide($wsdl); | ||
} | ||
|
||
protected function provideBasicNonWsdlOptions(): array { | ||
return [ | ||
'soap_version' => SOAP_1_2, | ||
'uri' => 'http://localhost/dummysoap', | ||
'location' => 'http://localhost/dummysoap', | ||
'cache_wsdl' => WSDL_CACHE_NONE | ||
]; | ||
} | ||
|
||
protected function provideBasicWsdlOptions(): array { | ||
return [ | ||
'soap_version' => SOAP_1_2, | ||
'cache_wsdl' => WSDL_CACHE_NONE | ||
]; | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
test/PhproTest/SoapClient/Functional/Encoding/Base64BinaryTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
<?php | ||
|
||
declare( strict_types=1 ); | ||
|
||
namespace PhproTest\SoapClient\Functional\Encoding; | ||
|
||
use PhproTest\SoapClient\Functional\AbstractSoapTestCase; | ||
use SoapServer; | ||
use SoapVar; | ||
|
||
class Base64BinaryTest extends AbstractSoapTestCase | ||
{ | ||
protected function configureServer(SoapServer $server) | ||
{ | ||
$server->setObject(new class() { | ||
public function validate($input) | ||
{ | ||
return [ | ||
'input' => $input, | ||
'output' => 'output', | ||
]; | ||
} | ||
}); | ||
} | ||
|
||
protected function getWsdl() | ||
{ | ||
return FIXTURE_DIR . '/wsdl/functional/base64Binary.wsdl'; | ||
} | ||
|
||
protected function getSoapOptions(): array { | ||
return $this->provideBasicNonWsdlOptions(); | ||
} | ||
|
||
/** | ||
* @test | ||
* @runInSeparateProcess | ||
*/ | ||
function it_automatically_converts_base64_binary_fields() | ||
{ | ||
$input = 'input'; | ||
$output = 'output'; | ||
$response = (array)$this->client->validate($input); | ||
|
||
$this->assertEquals($output, $response['output']); | ||
$this->assertEquals($input, $response['input']); | ||
$this->assertContains(base64_encode($input), $this->client->__getLastRequest()); | ||
$this->assertContains(base64_encode($output), $this->client->__getLastResponse()); | ||
} | ||
|
||
/** | ||
* @test | ||
* @runInSeparateProcess | ||
*/ | ||
function it_automatically_converts_base64_binary_internal_types() | ||
{ | ||
$input = 'input'; | ||
$output = 'output'; | ||
$response = (array)$this->client->validate(new SoapVar('input', XSD_BASE64BINARY)); | ||
|
||
$this->assertEquals($output, $response['output']); | ||
$this->assertEquals($input, $response['input']); | ||
$this->assertContains(base64_encode($input), $this->client->__getLastRequest()); | ||
$this->assertContains(base64_encode($output), $this->client->__getLastResponse()); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
test/PhproTest/SoapClient/Functional/Encoding/SimpleContentTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?php | ||
|
||
declare( strict_types=1 ); | ||
|
||
namespace PhproTest\SoapClient\Functional\Encoding; | ||
|
||
use PhproTest\SoapClient\Functional\AbstractSoapTestCase; | ||
use SoapServer; | ||
|
||
class SimpleContentTest extends AbstractSoapTestCase | ||
{ | ||
protected function configureServer(SoapServer $server) | ||
{ | ||
$server->setObject(new class() { | ||
public function validate($input) | ||
{ | ||
return $input; | ||
} | ||
}); | ||
} | ||
|
||
protected function getWsdl(): string | ||
{ | ||
return FIXTURE_DIR . '/wsdl/functional/simpleContent.wsdl'; | ||
} | ||
|
||
protected function getSoapOptions(): array { | ||
return $this->provideBasicWsdlOptions(); | ||
} | ||
|
||
/** | ||
* @test | ||
* @runInSeparateProcess | ||
*/ | ||
function it_uses_underscores_internally_as_node_value_of_simple_content() | ||
{ | ||
$input = $output = ['_' => 132, 'country' => 'BE']; | ||
$response = (array) $this->client->validate($input); | ||
|
||
$this->assertEquals($output, $response); | ||
$this->assertContains('<input xsi:type="ns2:SimpleContent" country="BE">132</input>', $this->client->__getLastRequest()); | ||
$this->assertContains('<output xsi:type="ns2:SimpleContent" country="BE">132</output>', $this->client->__getLastResponse()); | ||
} | ||
} |
Oops, something went wrong.