Skip to content

Commit

Permalink
Test new cookie with value
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Jan 16, 2018
1 parent 88f7fb7 commit 66547ea
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Cookie.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,10 @@ class Cookie {

public function __construct(string $name, string $value = "") {
if(!Validity::isValidName($name)) {
throw new InvalidCharactersException($name);
throw new InvalidCharactersException("Name contains invalid characters: $name");
}
if(!Validity::isValidValue($value)) {
throw new InvalidCharactersException($value);
throw new InvalidCharactersException("Value contains invalid characters: $value");
}

$this->name = $name;
Expand Down
2 changes: 1 addition & 1 deletion src/Validity.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public static function isValidValue(string $value):bool {
}

$nameChars = str_split($value, 1);
$validChars = self::getValidNameCharacters();
$validChars = self::getValidValueCharacters();
foreach($nameChars as $c) {
if(!in_array($c, $validChars)) {
$valid = false;
Expand Down
13 changes: 13 additions & 0 deletions test/unit/CookieTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,19 @@ public function testSetInvalidValue(string $name, string $value) {
$cookie->withValue($value);
}

/**
* @dataProvider dataNameValue
*/
public function testWithValue(string $name, string $value) {
$cookie = new Cookie($name, $value);
$value = $cookie->getValue();

$eulav = strrev($value);
$eikooc = new Cookie($name, $eulav);
self::assertNotSame($eikooc, $cookie);
self::assertNotEquals($value, $eikooc->getValue());
}

public static function dataNameValue():array {
$data = [];

Expand Down

0 comments on commit 66547ea

Please sign in to comment.