Skip to content
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

Fix overriding the custom SoapClient class #51

Merged
merged 1 commit into from
Feb 5, 2024
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
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());
}

}
Loading