diff --git a/.gitignore b/.gitignore index 232460d..2320511 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,5 @@ .idea vendor .env.test -.phpunit.result.cache \ No newline at end of file +.phpunit.result.cache +/phpunit.xml.bak diff --git a/phpunit.xml b/phpunit.xml index 09508f1..752baff 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,24 +1,18 @@ - + + + + src/ + + tests - - - src/ - - diff --git a/src/Facades/Soap.php b/src/Facades/Soap.php index d5bcb8c..94f7a08 100644 --- a/src/Facades/Soap.php +++ b/src/Facades/Soap.php @@ -8,13 +8,14 @@ /** * Class Soap. * + * @method static \CodeDredd\Soap\Handler\HttPlugHandle getHandler() * @method static \CodeDredd\Soap\SoapClient baseWsdl(string $wsdl) * @method static \CodeDredd\Soap\SoapClient stub(callable $callback) * @method static \CodeDredd\Soap\SoapClient buildClient(string $setup = '') * @method static \CodeDredd\Soap\SoapClient byConfig(string $setup = '') * @method static \CodeDredd\Soap\SoapClient withOptions(array $options) * @method static \CodeDredd\Soap\SoapClient withHeaders(array $options) - * @method static \CodeDredd\Soap\SoapClient handlerOptions(array $options) + * @method static \CodeDredd\Soap\SoapClient withHandlerOptions(array $options) * @method static \CodeDredd\Soap\SoapClient withWsse(array $config) * @method static \CodeDredd\Soap\SoapClient withWsa() * @method static \CodeDredd\Soap\SoapClient withRemoveEmptyNodes() diff --git a/src/Handler/HttPlugHandle.php b/src/Handler/HttPlugHandle.php index 8322750..ef89679 100644 --- a/src/Handler/HttPlugHandle.php +++ b/src/Handler/HttPlugHandle.php @@ -3,6 +3,7 @@ namespace CodeDredd\Soap\Handler; use CodeDredd\Soap\HttpBinding\Converter\Psr7Converter; +use GuzzleHttp\Client; use Http\Client\Common\PluginClient; use Http\Discovery\HttpClientDiscovery; use Http\Discovery\MessageFactoryDiscovery; @@ -15,12 +16,11 @@ use Phpro\SoapClient\Soap\HttpBinding\LastRequestInfo; use Phpro\SoapClient\Soap\HttpBinding\SoapRequest; use Phpro\SoapClient\Soap\HttpBinding\SoapResponse; -use Psr\Http\Client\ClientInterface; class HttPlugHandle implements HandlerInterface, MiddlewareSupportingInterface { /** - * @var ClientInterface + * @var Client */ private $client; @@ -45,7 +45,7 @@ class HttPlugHandle implements HandlerInterface, MiddlewareSupportingInterface private $requestHeaders = []; public function __construct( - ClientInterface $client, + Client $client, Psr7Converter $converter, CollectLastRequestInfoMiddleware $lastRequestInfoCollector, $requestHeaders = [] @@ -61,7 +61,7 @@ public static function createWithDefaultClient(): HttPlugHandle return self::createForClient(HttpClientDiscovery::find()); } - public static function createForClient(ClientInterface $client, $requestHeaders = []): HttPlugHandle + public static function createForClient(Client $client, $requestHeaders = []): HttPlugHandle { return new self( $client, @@ -95,6 +95,11 @@ public function request(SoapRequest $request): SoapResponse return $this->converter->convertSoapResponse($psr7Response); } + public function getClient(): Client + { + return $this->client; + } + public function collectLastRequestInfo(): LastRequestInfo { return $this->lastRequestInfoCollector->collectLastRequestInfo(); diff --git a/src/SoapClient.php b/src/SoapClient.php index b54191d..2e1c3ad 100644 --- a/src/SoapClient.php +++ b/src/SoapClient.php @@ -53,7 +53,7 @@ class SoapClient protected $extSoapOptions; /** - * @var + * @var HttPlugHandle */ protected $handler; @@ -164,6 +164,11 @@ public function withHeaders(array $headers) ])); } + public function getHandler(): HttPlugHandle + { + return $this->handler; + } + /** * @param $options * @return $this diff --git a/tests/Unit/SoapClientTest.php b/tests/Unit/SoapClientTest.php index cca61a5..f4e8584 100644 --- a/tests/Unit/SoapClientTest.php +++ b/tests/Unit/SoapClientTest.php @@ -9,6 +9,7 @@ use CodeDredd\Soap\SoapFactory; use CodeDredd\Soap\Tests\Fixtures\CustomSoapClient; use CodeDredd\Soap\Tests\TestCase; +use GuzzleHttp\RedirectMiddleware; class SoapClientTest extends TestCase { @@ -77,7 +78,7 @@ public function testRequestWithArguments() self::assertTrue($response->ok()); Soap::assertSent(function (Request $request) use ($arguments) { return $request->arguments() === $arguments && - $request->action() === 'Submit_User'; + $request->action() === 'Submit_User'; }); } @@ -149,7 +150,8 @@ public function testSoapOptions(): void $lastRequestInfo = $client->getEngine()->collectLastRequestInfo(); self::assertTrue($response->ok()); - self::assertStringContainsString('application/soap+xml; charset="utf-8', $lastRequestInfo->getLastRequestHeaders()); + self::assertStringContainsString('application/soap+xml; charset="utf-8', + $lastRequestInfo->getLastRequestHeaders()); Soap::assertActionCalled('Get_User'); } @@ -158,10 +160,10 @@ public function testRealSoapCall(): void $this->markTestSkipped('Real Soap Call Testing. Comment the line out for testing'); // location has to be set because the wsdl has a wrong location declaration $client = Soap::baseWsdl('https://www.w3schools.com/xml/tempconvert.asmx?wsdl') - ->withOptions([ - 'soap_version' => SOAP_1_2, - 'location' => 'https://www.w3schools.com/xml/tempconvert.asmx?wsdl', - ]); + ->withOptions([ + 'soap_version' => SOAP_1_2, + 'location' => 'https://www.w3schools.com/xml/tempconvert.asmx?wsdl', + ]); $result = $client->call('FahrenheitToCelsius', [ 'Fahrenheit' => 75, ]); @@ -211,4 +213,24 @@ public function testSoapClientClassMayBeCustomized(): void $client = Soap::buildClient('laravel_soap'); $this->assertInstanceOf(CustomSoapClient::class, $client); } + + public function testHandlerOptions(): void + { + Soap::fake(); + $client = Soap::baseWsdl('https://laravel-soap.wsdl'); + $response = $client->call('Get_User'); + self::assertTrue($response->ok()); + self::assertEquals(true, $client->getHandler()->getClient()->getConfig()['verify']); + $client = $client->withHandlerOptions([ + 'allow_redirects' => RedirectMiddleware::$defaultSettings, + 'http_errors' => true, + 'decode_content' => true, + 'verify' => false, + 'cookies' => false, + 'idn_conversion' => false, + ]); + $response = $client->call('Get_User'); + self::assertTrue($response->ok()); + self::assertEquals(false, $client->getHandler()->getClient()->getConfig()['verify']); + } }