Skip to content

Commit

Permalink
Fix specifying a custom SoapClient for a service by overriding the de…
Browse files Browse the repository at this point in the history
…fault constant value
  • Loading branch information
chyovev committed Feb 1, 2024
1 parent b914ae0 commit 836a17b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/AbstractSoapClientBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ protected static function canInstantiateSoapClientWithOptions(array $wsdlOptions
*/
public function getSoapClientClassName(?string $soapClientClassName = null): string
{
$className = self::DEFAULT_SOAP_CLIENT_CLASS;
$className = static::DEFAULT_SOAP_CLIENT_CLASS;
if (!empty($soapClientClassName) && is_subclass_of($soapClientClassName, SoapClient::class)) {
$className = $soapClientClassName;
}
Expand Down
26 changes: 26 additions & 0 deletions tests/CustomSoapClientService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

declare(strict_types=1);

namespace WsdlToPhp\PackageBase\Tests;

use WsdlToPhp\PackageBase\AbstractSoapClientBase;

/**
* Services can specify a custom SoapClient class
* to be used instead of PHP default by overriding
* the constant below.
*
* @see \WsdlToPhp\PackageBase\SoapClientInterface
* @see \WsdlToPhp\PackageBase\AbstractSoapClientBase :: getSoapClientClassName()
*/

class CustomSoapClientService extends AbstractSoapClientBase
{

/**
* Custom SoapClient class used for current service.
*/
const DEFAULT_SOAP_CLIENT_CLASS = Client::class;

}
17 changes: 17 additions & 0 deletions tests/DefaultSoapClientService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace WsdlToPhp\PackageBase\Tests;

use WsdlToPhp\PackageBase\AbstractSoapClientBase;

/**
* By default all services extending the packagebase's
* abstract class rely on PHP's default SoapClient.
*/

class DefaultSoapClientService extends AbstractSoapClientBase
{

}
10 changes: 10 additions & 0 deletions tests/SoapClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,15 @@ public function testSoapClientNameDefault(): void
$this->assertSame(Client::class, $soapClient->getSoapClientClassName(Client::class));
}

public function testCustomSoapClientNameReadFromConstant()
{
$defaultService = new DefaultSoapClientService();
$customService = new CustomSoapClientService();

$this->assertSame(SoapClientBase::class, $defaultService->getSoapClientClassName());
$this->assertSame(Client::class, $customService->getSoapClientClassName());
}

public function testSoapClient(): void
{
$soapClient = new SoapClient([
Expand Down Expand Up @@ -489,4 +498,5 @@ public function testGetOutputHeadersWithoutRequestMustReturnAnEmptyArray(): void
$this->assertTrue(is_array($soapClient->getOutputHeaders()));
$this->assertEmpty($soapClient->getOutputHeaders());
}

}

0 comments on commit 836a17b

Please sign in to comment.