-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #71 from adriansuter/patch-headerTest
Add Header Test
- Loading branch information
Showing
1 changed file
with
71 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,71 @@ | ||
<?php | ||
/** | ||
* Slim Framework (https://slimframework.com) | ||
* | ||
* @license https://github.com/slimphp/Slim-Psr7/blob/master/LICENSE.md (MIT License) | ||
*/ | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Slim\Tests\Psr7; | ||
|
||
use InvalidArgumentException; | ||
use PHPUnit\Framework\TestCase; | ||
use Slim\Psr7\Header; | ||
|
||
class HeaderTest extends TestCase | ||
{ | ||
/** | ||
* Instantiate a default header. | ||
* | ||
* @return Header | ||
*/ | ||
protected function headerFactory(): Header | ||
{ | ||
$originalName = 'ACCEPT'; | ||
$normalizedName = 'accept'; | ||
$values = ['application/json']; | ||
|
||
return new Header($originalName, $normalizedName, $values); | ||
} | ||
|
||
public function testGetOriginalName() | ||
{ | ||
$header = $this->headerFactory(); | ||
$this->assertEquals('ACCEPT', $header->getOriginalName()); | ||
} | ||
|
||
public function testGetNormalizedName() | ||
{ | ||
$header = $this->headerFactory(); | ||
$this->assertEquals('accept', $header->getNormalizedName()); | ||
} | ||
|
||
public function testAddValue() | ||
{ | ||
$header = $this->headerFactory(); | ||
$header2 = $header->addValue('text/html'); | ||
|
||
$this->assertEquals(['application/json', 'text/html'], $header->getValues()); | ||
$this->assertSame($header2, $header); | ||
} | ||
|
||
public function testAddValuesString() | ||
{ | ||
$header = $this->headerFactory(); | ||
$header2 = $header->addValues('text/html'); | ||
|
||
$this->assertEquals(['application/json', 'text/html'], $header->getValues()); | ||
$this->assertSame($header2, $header); | ||
} | ||
|
||
/** | ||
* @expectedException InvalidArgumentException | ||
* @expectedExceptionMessage Parameter 1 of Header::addValues() should be a string or an array. | ||
*/ | ||
public function testAddValuesNull() | ||
{ | ||
$header = $this->headerFactory(); | ||
$header->addValues(null); | ||
} | ||
} |