-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#184 - AllowRedirects object - represents allow_redirects Guzzle opti…
- Loading branch information
Showing
5 changed files
with
146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Pd\Monitoring\Check\Consumers\Client\Conf; | ||
|
||
class AllowRedirects implements AllowRedirectsInterface | ||
{ | ||
|
||
private bool $isAllowed; | ||
|
||
|
||
private function __construct(bool $isAllowed) | ||
{ | ||
$this->isAllowed = $isAllowed; | ||
} | ||
|
||
|
||
/** | ||
* @return array<string, bool> | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return [ | ||
'allow_redirects' => $this->isAllowed, | ||
]; | ||
} | ||
|
||
|
||
public static function create(bool $isAllowed): self | ||
{ | ||
return new self($isAllowed); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Pd\Monitoring\Check\Consumers\Client\Conf; | ||
|
||
class AllowRedirectsArray implements AllowRedirectsInterface | ||
{ | ||
|
||
/** | ||
* @var array<string, mixed> | ||
*/ | ||
private array $conf; | ||
|
||
|
||
/** | ||
* @param array<string, mixed> $conf | ||
*/ | ||
public function __construct(array $conf) | ||
{ | ||
$this->conf = $conf; | ||
} | ||
|
||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
public function toArray(): array | ||
{ | ||
return [ | ||
'allow_redirects' => $this->conf, | ||
]; | ||
} | ||
|
||
} |
13 changes: 13 additions & 0 deletions
13
app/Check/Consumers/Client/Conf/AllowRedirectsInterface.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Pd\Monitoring\Check\Consumers\Client\Conf; | ||
|
||
interface AllowRedirectsInterface | ||
{ | ||
|
||
/** | ||
* @return array<string, mixed> | ||
*/ | ||
public function toArray(): array; | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
tests/phpunit/Check/Consumers/Client/Conf/AllowRedirectsArrayTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Pd\Monitoring\Check\Consumers\Client\Conf; | ||
|
||
class AllowRedirectsArrayTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
|
||
/** | ||
* @dataProvider dataProvider | ||
*/ | ||
public function testToArray(array $conf): void | ||
{ | ||
$allowRedirects = new \Pd\Monitoring\Check\Consumers\Client\Conf\AllowRedirectsArray($conf); | ||
$this->assertSame([ | ||
'allow_redirects' => $conf, | ||
], $allowRedirects->toArray()); | ||
} | ||
|
||
|
||
public function dataProvider(): array | ||
{ | ||
return [ | ||
[ | ||
'conf' => [ | ||
'max' => 10, | ||
'strict' => true, | ||
'referer' => true, | ||
'protocols' => ['https'], | ||
'track_redirects' => true | ||
], | ||
], | ||
]; | ||
} | ||
|
||
} |
32 changes: 32 additions & 0 deletions
32
tests/phpunit/Check/Consumers/Client/Conf/AllowRedirectsTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace Tests\Pd\Monitoring\Check\Consumers\Client\Conf; | ||
|
||
class AllowRedirectsTest extends \PHPUnit\Framework\TestCase | ||
{ | ||
|
||
/** | ||
* @dataProvider dataProvider | ||
*/ | ||
public function testToArray(bool $isAllowed): void | ||
{ | ||
$allowRedirects = \Pd\Monitoring\Check\Consumers\Client\Conf\AllowRedirects::create($isAllowed); | ||
$this->assertSame([ | ||
'allow_redirects' => $isAllowed, | ||
], $allowRedirects->toArray()); | ||
} | ||
|
||
|
||
public function dataProvider(): array | ||
{ | ||
return [ | ||
[ | ||
'isAllowed' => TRUE, | ||
], | ||
[ | ||
'isAllowed' => FALSE, | ||
], | ||
]; | ||
} | ||
|
||
} |