Skip to content

Commit a561334

Browse files
CodeDreddGregor Becker
and
Gregor Becker
authored
fix(feature/laravel soap-141): typo in factory & added unit test (#142)
* fix(laravel-soap-141): fix typo in facade * refactor(laravel-soap-141): add unit test for handler options - upgraded phpunit.xml to newe format - add new function to get the Guzzle Client for testing * refactor(laravel-soap-141): add getHandler to factory Co-authored-by: Gregor Becker <[email protected]>
1 parent bc80aae commit a561334

File tree

6 files changed

+56
-28
lines changed

6 files changed

+56
-28
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.idea
22
vendor
33
.env.test
4-
.phpunit.result.cache
4+
.phpunit.result.cache
5+
/phpunit.xml.bak

phpunit.xml

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit bootstrap="vendor/autoload.php"
3-
backupGlobals="false"
4-
backupStaticAttributes="false"
5-
colors="true"
6-
verbose="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
10-
processIsolation="false"
11-
stopOnFailure="false">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false"
3+
backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true"
4+
convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false"
5+
stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
6+
<coverage>
7+
<include>
8+
<directory suffix=".php">src/</directory>
9+
</include>
10+
</coverage>
1211
<testsuites>
1312
<testsuite name="Laravel Soap Test Suite">
1413
<directory>tests</directory>
1514
</testsuite>
1615
</testsuites>
17-
<filter>
18-
<whitelist>
19-
<directory suffix=".php">src/</directory>
20-
</whitelist>
21-
</filter>
2216
<php>
2317
<server name="APP_ENV" value="testing"/>
2418
<server name="API_PREFIX" value="api"/>

src/Facades/Soap.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,14 @@
88
/**
99
* Class Soap.
1010
*
11+
* @method static \CodeDredd\Soap\Handler\HttPlugHandle getHandler()
1112
* @method static \CodeDredd\Soap\SoapClient baseWsdl(string $wsdl)
1213
* @method static \CodeDredd\Soap\SoapClient stub(callable $callback)
1314
* @method static \CodeDredd\Soap\SoapClient buildClient(string $setup = '')
1415
* @method static \CodeDredd\Soap\SoapClient byConfig(string $setup = '')
1516
* @method static \CodeDredd\Soap\SoapClient withOptions(array $options)
1617
* @method static \CodeDredd\Soap\SoapClient withHeaders(array $options)
17-
* @method static \CodeDredd\Soap\SoapClient handlerOptions(array $options)
18+
* @method static \CodeDredd\Soap\SoapClient withHandlerOptions(array $options)
1819
* @method static \CodeDredd\Soap\SoapClient withWsse(array $config)
1920
* @method static \CodeDredd\Soap\SoapClient withWsa()
2021
* @method static \CodeDredd\Soap\SoapClient withRemoveEmptyNodes()

src/Handler/HttPlugHandle.php

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace CodeDredd\Soap\Handler;
44

55
use CodeDredd\Soap\HttpBinding\Converter\Psr7Converter;
6+
use GuzzleHttp\Client;
67
use Http\Client\Common\PluginClient;
78
use Http\Discovery\HttpClientDiscovery;
89
use Http\Discovery\MessageFactoryDiscovery;
@@ -15,12 +16,11 @@
1516
use Phpro\SoapClient\Soap\HttpBinding\LastRequestInfo;
1617
use Phpro\SoapClient\Soap\HttpBinding\SoapRequest;
1718
use Phpro\SoapClient\Soap\HttpBinding\SoapResponse;
18-
use Psr\Http\Client\ClientInterface;
1919

2020
class HttPlugHandle implements HandlerInterface, MiddlewareSupportingInterface
2121
{
2222
/**
23-
* @var ClientInterface
23+
* @var Client
2424
*/
2525
private $client;
2626

@@ -45,7 +45,7 @@ class HttPlugHandle implements HandlerInterface, MiddlewareSupportingInterface
4545
private $requestHeaders = [];
4646

4747
public function __construct(
48-
ClientInterface $client,
48+
Client $client,
4949
Psr7Converter $converter,
5050
CollectLastRequestInfoMiddleware $lastRequestInfoCollector,
5151
$requestHeaders = []
@@ -61,7 +61,7 @@ public static function createWithDefaultClient(): HttPlugHandle
6161
return self::createForClient(HttpClientDiscovery::find());
6262
}
6363

64-
public static function createForClient(ClientInterface $client, $requestHeaders = []): HttPlugHandle
64+
public static function createForClient(Client $client, $requestHeaders = []): HttPlugHandle
6565
{
6666
return new self(
6767
$client,
@@ -95,6 +95,11 @@ public function request(SoapRequest $request): SoapResponse
9595
return $this->converter->convertSoapResponse($psr7Response);
9696
}
9797

98+
public function getClient(): Client
99+
{
100+
return $this->client;
101+
}
102+
98103
public function collectLastRequestInfo(): LastRequestInfo
99104
{
100105
return $this->lastRequestInfoCollector->collectLastRequestInfo();

src/SoapClient.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class SoapClient
5353
protected $extSoapOptions;
5454

5555
/**
56-
* @var
56+
* @var HttPlugHandle
5757
*/
5858
protected $handler;
5959

@@ -164,6 +164,11 @@ public function withHeaders(array $headers)
164164
]));
165165
}
166166

167+
public function getHandler(): HttPlugHandle
168+
{
169+
return $this->handler;
170+
}
171+
167172
/**
168173
* @param $options
169174
* @return $this

tests/Unit/SoapClientTest.php

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
use CodeDredd\Soap\SoapFactory;
1010
use CodeDredd\Soap\Tests\Fixtures\CustomSoapClient;
1111
use CodeDredd\Soap\Tests\TestCase;
12+
use GuzzleHttp\RedirectMiddleware;
1213

1314
class SoapClientTest extends TestCase
1415
{
@@ -77,7 +78,7 @@ public function testRequestWithArguments()
7778
self::assertTrue($response->ok());
7879
Soap::assertSent(function (Request $request) use ($arguments) {
7980
return $request->arguments() === $arguments &&
80-
$request->action() === 'Submit_User';
81+
$request->action() === 'Submit_User';
8182
});
8283
}
8384

@@ -149,7 +150,8 @@ public function testSoapOptions(): void
149150
$lastRequestInfo = $client->getEngine()->collectLastRequestInfo();
150151

151152
self::assertTrue($response->ok());
152-
self::assertStringContainsString('application/soap+xml; charset="utf-8', $lastRequestInfo->getLastRequestHeaders());
153+
self::assertStringContainsString('application/soap+xml; charset="utf-8',
154+
$lastRequestInfo->getLastRequestHeaders());
153155
Soap::assertActionCalled('Get_User');
154156
}
155157

@@ -158,10 +160,10 @@ public function testRealSoapCall(): void
158160
$this->markTestSkipped('Real Soap Call Testing. Comment the line out for testing');
159161
// location has to be set because the wsdl has a wrong location declaration
160162
$client = Soap::baseWsdl('https://www.w3schools.com/xml/tempconvert.asmx?wsdl')
161-
->withOptions([
162-
'soap_version' => SOAP_1_2,
163-
'location' => 'https://www.w3schools.com/xml/tempconvert.asmx?wsdl',
164-
]);
163+
->withOptions([
164+
'soap_version' => SOAP_1_2,
165+
'location' => 'https://www.w3schools.com/xml/tempconvert.asmx?wsdl',
166+
]);
165167
$result = $client->call('FahrenheitToCelsius', [
166168
'Fahrenheit' => 75,
167169
]);
@@ -211,4 +213,24 @@ public function testSoapClientClassMayBeCustomized(): void
211213
$client = Soap::buildClient('laravel_soap');
212214
$this->assertInstanceOf(CustomSoapClient::class, $client);
213215
}
216+
217+
public function testHandlerOptions(): void
218+
{
219+
Soap::fake();
220+
$client = Soap::baseWsdl('https://laravel-soap.wsdl');
221+
$response = $client->call('Get_User');
222+
self::assertTrue($response->ok());
223+
self::assertEquals(true, $client->getHandler()->getClient()->getConfig()['verify']);
224+
$client = $client->withHandlerOptions([
225+
'allow_redirects' => RedirectMiddleware::$defaultSettings,
226+
'http_errors' => true,
227+
'decode_content' => true,
228+
'verify' => false,
229+
'cookies' => false,
230+
'idn_conversion' => false,
231+
]);
232+
$response = $client->call('Get_User');
233+
self::assertTrue($response->ok());
234+
self::assertEquals(false, $client->getHandler()->getClient()->getConfig()['verify']);
235+
}
214236
}

0 commit comments

Comments
 (0)