Skip to content

Commit

Permalink
Update abstract provider:
Browse files Browse the repository at this point in the history
- add verify Guzzle option
  • Loading branch information
webeweb committed Sep 23, 2024
1 parent dda09fc commit 8371813
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 3 deletions.
41 changes: 39 additions & 2 deletions src/Provider/AbstractProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -65,6 +72,7 @@ public function __construct(Authentication $authentication, LoggerInterface $log

$this->setAuthentication($authentication);
$this->setRequestSerializer(new RequestSerializer());
$this->setVerify(true);
}

/**
Expand All @@ -82,6 +90,7 @@ private function buildConfiguration(): array {
"User-Agent" => "webeweb/smsmode-library",
],
"synchronous" => true,
"verify" => $this->getVerify(),
];
}

Expand Down Expand Up @@ -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.
*
Expand All @@ -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;
}
}
24 changes: 23 additions & 1 deletion tests/Provider/AbstractProviderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class AbstractProviderTest extends AbstractTestCase {
/**
* Authentication.
*
* @var Authentication
* @var Authentication|null
*/
private $authentication;

Expand All @@ -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()
*
Expand Down

0 comments on commit 8371813

Please sign in to comment.