Skip to content

fix(feature/laravel soap-141): typo in factory & added unit test #142

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 23, 2021
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.idea
vendor
.env.test
.phpunit.result.cache
.phpunit.result.cache
/phpunit.xml.bak
24 changes: 9 additions & 15 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
verbose="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" bootstrap="vendor/autoload.php" backupGlobals="false"
backupStaticAttributes="false" colors="true" verbose="true" convertErrorsToExceptions="true"
convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false"
stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage>
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
<testsuites>
<testsuite name="Laravel Soap Test Suite">
<directory>tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist>
<directory suffix=".php">src/</directory>
</whitelist>
</filter>
<php>
<server name="APP_ENV" value="testing"/>
<server name="API_PREFIX" value="api"/>
Expand Down
3 changes: 2 additions & 1 deletion src/Facades/Soap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
13 changes: 9 additions & 4 deletions src/Handler/HttPlugHandle.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

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

public function __construct(
ClientInterface $client,
Client $client,
Psr7Converter $converter,
CollectLastRequestInfoMiddleware $lastRequestInfoCollector,
$requestHeaders = []
Expand All @@ -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,
Expand Down Expand Up @@ -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();
Expand Down
7 changes: 6 additions & 1 deletion src/SoapClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class SoapClient
protected $extSoapOptions;

/**
* @var
* @var HttPlugHandle
*/
protected $handler;

Expand Down Expand Up @@ -164,6 +164,11 @@ public function withHeaders(array $headers)
]));
}

public function getHandler(): HttPlugHandle
{
return $this->handler;
}

/**
* @param $options
* @return $this
Expand Down
34 changes: 28 additions & 6 deletions tests/Unit/SoapClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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';
});
}

Expand Down Expand Up @@ -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');
}

Expand All @@ -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,
]);
Expand Down Expand Up @@ -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']);
}
}