-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from Ricorocks-Digital-Agency/tracing
Tracing
- Loading branch information
Showing
10 changed files
with
285 additions
and
15 deletions.
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
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,19 @@ | ||
<?php | ||
|
||
namespace RicorocksDigitalAgency\Soap\Support\Tracing; | ||
|
||
class Trace | ||
{ | ||
public $xmlRequest; | ||
public $xmlResponse; | ||
|
||
public static function thisXmlRequest($xml): self | ||
{ | ||
return tap(new static, fn($instance) => $instance->xmlRequest = $xml); | ||
} | ||
|
||
public function thisXmlResponse($xml): self | ||
{ | ||
return tap($this, fn($self) => $self->xmlResponse = $xml); | ||
} | ||
} |
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,94 @@ | ||
<?php | ||
|
||
|
||
namespace RicorocksDigitalAgency\Soap\Tests\Mocks; | ||
|
||
|
||
class MockSoapClient | ||
{ | ||
protected $shouldTrace = false; | ||
|
||
/* Methods */ | ||
public function __construct($wsdl, $options = []) | ||
{ | ||
if ($options['trace'] ?? false) { | ||
$this->shouldTrace = true; | ||
} | ||
} | ||
|
||
public function __call(string $function_name, array $arguments) | ||
{ | ||
} | ||
|
||
public function __doRequest(string $request, string $location, string $action, int $version, $one_way = 0) | ||
{ | ||
} | ||
|
||
public function __getCookies() | ||
{ | ||
} | ||
|
||
public function __getFunctions() | ||
{ | ||
return [ | ||
"The mock client does not actually have functions!" | ||
]; | ||
} | ||
|
||
public function __getLastRequest() | ||
{ | ||
if (!$this->shouldTrace) { | ||
return null; | ||
} | ||
|
||
return '<?xml version="1.0" encoding="UTF-8"?><FooBar><Hello>World</Hello></FooBar>'; | ||
} | ||
|
||
public function __getLastRequestHeaders() | ||
{ | ||
} | ||
|
||
public function __getLastResponse() | ||
{ | ||
if (!$this->shouldTrace) { | ||
return null; | ||
} | ||
|
||
return '<?xml version="1.0" encoding="UTF-8"?><Status>Success!</Status>'; | ||
} | ||
|
||
public function __getLastResponseHeaders() | ||
{ | ||
} | ||
|
||
public function __getTypes() | ||
{ | ||
} | ||
|
||
public function __setCookie(string $name, string $value = null) | ||
{ | ||
} | ||
|
||
public function __setLocation(string $new_location = null) | ||
{ | ||
} | ||
|
||
public function __setSoapHeaders($soapheaders) | ||
{ | ||
} | ||
|
||
public function __soapCall( | ||
string $function_name, | ||
array $arguments, | ||
array $options = [], | ||
$input_headers = [], | ||
&$output_headers = [] | ||
) { | ||
} | ||
|
||
public function SoapClient(mixed $wsdl, array $options = []) | ||
{ | ||
return new static($wsdl, $options); | ||
} | ||
|
||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
<?php | ||
|
||
namespace RicorocksDigitalAgency\Soap\Tests\Tracing; | ||
|
||
use RicorocksDigitalAgency\Soap\Facades\Soap; | ||
use RicorocksDigitalAgency\Soap\Support\Tracing\Trace; | ||
use RicorocksDigitalAgency\Soap\Tests\TestCase; | ||
|
||
class SoapTracingTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
$this->fakeClient(); | ||
} | ||
|
||
/** @test */ | ||
public function a_trace_can_be_requested_at_time_of_request() | ||
{ | ||
$response = Soap::to(static::EXAMPLE_SOAP_ENDPOINT) | ||
->trace() | ||
->call('Add', ['intA' => 10, 'intB' => 25]); | ||
|
||
$this->assertEquals('<?xml version="1.0" encoding="UTF-8"?><FooBar><Hello>World</Hello></FooBar>', $response->trace()->xmlRequest); | ||
$this->assertEquals('<?xml version="1.0" encoding="UTF-8"?><Status>Success!</Status>', $response->trace()->xmlResponse); | ||
} | ||
|
||
/** @test */ | ||
public function a_trace_can_be_requested_globally() | ||
{ | ||
Soap::trace(); | ||
|
||
$response = Soap::to(static::EXAMPLE_SOAP_ENDPOINT) | ||
->call('Add', ['intA' => 10, 'intB' => 25]); | ||
|
||
$this->assertEquals('<?xml version="1.0" encoding="UTF-8"?><FooBar><Hello>World</Hello></FooBar>', $response->trace()->xmlRequest); | ||
$this->assertEquals('<?xml version="1.0" encoding="UTF-8"?><Status>Success!</Status>', $response->trace()->xmlResponse); | ||
} | ||
|
||
/** @test */ | ||
public function by_default_the_trace_has_no_content_on_the_response() | ||
{ | ||
$response = Soap::to(static::EXAMPLE_SOAP_ENDPOINT) | ||
->call('Add', ['intA' => 10, 'intB' => 25]); | ||
|
||
$this->assertEmpty($response->trace()->xmlRequest); | ||
$this->assertEmpty($response->trace()->xmlResponse); | ||
} | ||
} |
Oops, something went wrong.