From 836a17bb17cdeffc497244b4f45942952d4e4104 Mon Sep 17 00:00:00 2001 From: Christo Yovev Date: Thu, 1 Feb 2024 19:09:56 +0100 Subject: [PATCH] Fix specifying a custom SoapClient for a service by overriding the default constant value --- src/AbstractSoapClientBase.php | 2 +- tests/CustomSoapClientService.php | 26 ++++++++++++++++++++++++++ tests/DefaultSoapClientService.php | 17 +++++++++++++++++ tests/SoapClientTest.php | 10 ++++++++++ 4 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 tests/CustomSoapClientService.php create mode 100644 tests/DefaultSoapClientService.php diff --git a/src/AbstractSoapClientBase.php b/src/AbstractSoapClientBase.php index e9aa85f..accac03 100644 --- a/src/AbstractSoapClientBase.php +++ b/src/AbstractSoapClientBase.php @@ -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; } diff --git a/tests/CustomSoapClientService.php b/tests/CustomSoapClientService.php new file mode 100644 index 0000000..7438fdd --- /dev/null +++ b/tests/CustomSoapClientService.php @@ -0,0 +1,26 @@ +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([ @@ -489,4 +498,5 @@ public function testGetOutputHeadersWithoutRequestMustReturnAnEmptyArray(): void $this->assertTrue(is_array($soapClient->getOutputHeaders())); $this->assertEmpty($soapClient->getOutputHeaders()); } + }