Skip to content

Commit

Permalink
Test get/set request attributes, fully testing ServerRequest
Browse files Browse the repository at this point in the history
  • Loading branch information
g105b committed Jan 27, 2019
1 parent 655307c commit 6a5cfd9
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions test/unit/ServerRequestTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,45 @@ public function testWithParsedBody() {
self::assertCount(2, $sut->getParsedBody()->asArray());
}

public function testGetAttributesEmpty() {
$sut = self::getServerRequest();
self::assertEmpty($sut->getAttributes());
}

public function testWithAttribute() {
$sutWithout = self::getServerRequest();
$sutWith = $sutWithout->withAttribute("testAttr", "testValue");
self::assertEmpty($sutWithout->getAttributes());
self::assertCount(1, $sutWith->getAttributes());
}

public function testGetAttribute() {
$sut = self::getServerRequest()
->withAttribute("testAttr", "testValue");
self::assertEquals(
"testValue",
$sut->getAttribute("testAttr")
);
}

public function testGetAttributeDefault() {
$sut = self::getServerRequest()
->withAttribute("testAttr", "testValue");
self::assertEquals(
"defaultValue",
$sut->getAttribute("notExists", "defaultValue")
);
}

public function testGetAttributeWithout() {
$sut = self::getServerRequest()
->withAttribute("testAttr1", "testValue1")
->withAttribute("testAttr2", "testValue2")
->withAttribute("testAttr3", "testValue3")
->withoutAttribute("testAttr2");
self::assertCount(2, $sut->getAttributes());
}

protected function getServerRequest(
string $method = null,
string $uri = null,
Expand Down

0 comments on commit 6a5cfd9

Please sign in to comment.