Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Header Test #71

Merged
merged 3 commits into from
May 2, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions tests/HeaderTest.php
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);
}
}