Skip to content

Commit

Permalink
#184 - AllowRedirects object - represents allow_redirects Guzzle opti…
Browse files Browse the repository at this point in the history
  • Loading branch information
AloisJasa committed Apr 6, 2023
1 parent 94fe10b commit 6f61f73
Show file tree
Hide file tree
Showing 5 changed files with 146 additions and 0 deletions.
33 changes: 33 additions & 0 deletions app/Check/Consumers/Client/Conf/AllowRedirects.php
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);
}

}
33 changes: 33 additions & 0 deletions app/Check/Consumers/Client/Conf/AllowRedirectsArray.php
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 app/Check/Consumers/Client/Conf/AllowRedirectsInterface.php
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;

}
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 tests/phpunit/Check/Consumers/Client/Conf/AllowRedirectsTest.php
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,
],
];
}

}

0 comments on commit 6f61f73

Please sign in to comment.