Skip to content
This repository was archived by the owner on Mar 29, 2022. It is now read-only.

Commit dfd6ea0

Browse files
author
Changwan Jun
committed
bug fix, #12
1 parent 2a34079 commit dfd6ea0

2 files changed

Lines changed: 20 additions & 3 deletions

File tree

src/Traits/ServerRequestTrait.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,10 +124,10 @@ public function getAttributes()
124124
*/
125125
public function getAttribute($name, $default = null)
126126
{
127-
if (!isset($this->attributes[$name])) {
128-
return $default;
127+
if (array_key_exists($name, $this->attributes)) {
128+
return $this->attributes[$name];
129129
}
130-
return $this->attributes[$name];
130+
return $default;
131131
}
132132

133133
/**

tests/Issues/Issue12Test.php

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
namespace Wandu\Http\Issues;
3+
4+
use Mockery;
5+
use PHPUnit_Framework_TestCase;
6+
use Wandu\Http\Psr\ServerRequest;
7+
8+
class Issue12Test extends PHPUnit_Framework_TestCase
9+
{
10+
public function testGetAttribute()
11+
{
12+
$request = (new ServerRequest())->withAttribute('null', null);
13+
14+
$this->assertNull($request->getAttribute('null'));
15+
$this->assertNull($request->getAttribute('null', 20));
16+
}
17+
}

0 commit comments

Comments
 (0)