-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add support for request custom headers 'X-AH-ExecutionMode'
- Loading branch information
Miguel Vela Romera
committed
Feb 24, 2020
1 parent
b0b003b
commit 5f6f563
Showing
6 changed files
with
149 additions
and
20 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
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
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
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
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,55 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Payvision\SDK\Infrastructure; | ||
|
||
use ArrayIterator; | ||
use Countable; | ||
use IteratorAggregate; | ||
use Traversable; | ||
|
||
class RequestHeaderCollection implements IteratorAggregate, Countable | ||
{ | ||
const HEADER_EXECUTION_MODE = 'X-AH-ExecutionMode'; | ||
|
||
/** | ||
* @var string[],array<string> | ||
*/ | ||
protected $headers = []; | ||
|
||
/** | ||
* @param string $header | ||
* @param string $value | ||
* @return $this | ||
*/ | ||
public function add(string $header, string $value): self | ||
{ | ||
$this->headers[$header] = $value; | ||
return $this; | ||
} | ||
|
||
/** | ||
* @return ArrayIterator|Traversable | ||
*/ | ||
public function getIterator() | ||
{ | ||
return new ArrayIterator($this->headers); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getHeaders(): array | ||
{ | ||
return $this->headers; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function count(): int | ||
{ | ||
return \count($this->headers); | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
tests/Test/Unit/Infrastructure/RequestHeaderCollectionTest.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,37 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
/** | ||
* @copyright Copyright (c) 2018-2019 Payvision B.V. (https://www.payvision.com/) | ||
* @license proprietary | ||
*/ | ||
|
||
namespace Payvision\SDK\Test\Unit\Infrastructure; | ||
|
||
use Payvision\SDK\Infrastructure\RequestHeaderCollection; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class RequestHeaderCollectionTest extends TestCase | ||
{ | ||
/** | ||
* @return null | ||
*/ | ||
public function testAddRequestHeaderCollectionSuccessfully() | ||
{ | ||
$requestHeaders = new RequestHeaderCollection(); | ||
$this->assertEquals(0, $requestHeaders->count()); | ||
|
||
$requestHeaders->add(RequestHeaderCollection::HEADER_EXECUTION_MODE, 'test'); | ||
$this->assertEquals(1, $requestHeaders->count()); | ||
|
||
foreach ($requestHeaders as $key => $value) { | ||
$this->assertEquals(RequestHeaderCollection::HEADER_EXECUTION_MODE, $key); | ||
$this->assertEquals('test', $value); | ||
} | ||
|
||
$headers = $requestHeaders->getHeaders(); | ||
$this->assertArrayHasKey(RequestHeaderCollection::HEADER_EXECUTION_MODE, $headers); | ||
$this->assertEquals($headers[RequestHeaderCollection::HEADER_EXECUTION_MODE], 'test'); | ||
} | ||
} |