From 8371813e38aea7d7404b6e5fe7e2faec5ee6077e Mon Sep 17 00:00:00 2001 From: webeweb Date: Mon, 23 Sep 2024 14:09:07 +0200 Subject: [PATCH] Update abstract provider: - add verify Guzzle option --- src/Provider/AbstractProvider.php | 41 +++++++++++++++++++++++-- tests/Provider/AbstractProviderTest.php | 24 ++++++++++++++- 2 files changed, 62 insertions(+), 3 deletions(-) diff --git a/src/Provider/AbstractProvider.php b/src/Provider/AbstractProvider.php index 343c258..375eec0 100644 --- a/src/Provider/AbstractProvider.php +++ b/src/Provider/AbstractProvider.php @@ -43,17 +43,24 @@ abstract class AbstractProvider extends BaseProvider { /** * Authentication. * - * @var Authentication + * @var Authentication|null */ private $authentication; /** * Request serializer. * - * @var RequestSerializer + * @var RequestSerializer|null */ private $requestSerializer; + /** + * Verify CA. + * + * @var bool|string|null + */ + private $verify; + /** * Constructor. * @@ -65,6 +72,7 @@ public function __construct(Authentication $authentication, LoggerInterface $log $this->setAuthentication($authentication); $this->setRequestSerializer(new RequestSerializer()); + $this->setVerify(true); } /** @@ -82,6 +90,7 @@ private function buildConfiguration(): array { "User-Agent" => "webeweb/smsmode-library", ], "synchronous" => true, + "verify" => $this->getVerify(), ]; } @@ -142,6 +151,15 @@ public function getRequestSerializer(): RequestSerializer { return $this->requestSerializer; } + /** + * Get the verify CA. + * + * @return bool|string|null Returns the verify CA. + */ + public function getVerify() { + return $this->verify; + } + /** * Set the authentication. * @@ -163,4 +181,23 @@ protected function setRequestSerializer(RequestSerializer $requestSerializer): A $this->requestSerializer = $requestSerializer; return $this; } + + /** + * Set the verify CA. + * + * @param bool|string|null $verify The verify CA. + * @return AbstractProvider Returns this provider. + */ + public function setVerify($verify): AbstractProvider { + + if (true === is_bool($verify) || true === is_string($verify)) { + $this->verify = $verify; + } + + if (true === is_null($verify)) { + $this->verify = true; + } + + return $this; + } } diff --git a/tests/Provider/AbstractProviderTest.php b/tests/Provider/AbstractProviderTest.php index 4d68135..aad3f11 100644 --- a/tests/Provider/AbstractProviderTest.php +++ b/tests/Provider/AbstractProviderTest.php @@ -30,7 +30,7 @@ class AbstractProviderTest extends AbstractTestCase { /** * Authentication. * - * @var Authentication + * @var Authentication|null */ private $authentication; @@ -46,6 +46,28 @@ protected function setUp(): void { $this->authentication->setPass("pass"); } + /** + * Test setVerify() + * + * @return void + */ + public function testSetVerifyCA(): void { + + $obj = new TestProvider($this->authentication); + + $obj->setVerify(true); + $this->assertTrue($obj->getVerify()); + + $obj->setVerify(false); + $this->assertFalse($obj->getVerify()); + + $obj->setVerify("verify"); + $this->assertEquals("verify", $obj->getVerify()); + + $obj->setVerify(null); + $this->assertTrue($obj->getVerify()); + } + /** * Test __construct() *