RequestContextTest::testConstructDefaultValues()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
1
<?php
2
3
/*
4
 *
5
 * (c) Yaroslav Honcharuk <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Yarhon\RouteGuardBundle\Tests\Security\Http;
12
13
use PHPUnit\Framework\TestCase;
14
use Yarhon\RouteGuardBundle\Security\Http\RequestContext;
15
16
/**
17
 * @author Yaroslav Honcharuk <[email protected]>
18
 */
19
class RequestContextTest extends TestCase
20
{
21
    public function testConstructDefaultValues()
22
    {
23
        $context = new RequestContext();
24
25
        $this->assertNull($context->getPathInfo());
26
        $this->assertNull($context->getHost());
27
        $this->assertNull($context->getMethod());
28
        $this->assertNull($context->getClientIp());
29
    }
30
31
    public function testConstructAllValues()
32
    {
33
        $context = new RequestContext('/foo', 'site.com', 'GET', '127.0.0.1');
34
35
        $this->assertEquals('/foo', $context->getPathInfo());
36
        $this->assertEquals('site.com', $context->getHost());
37
        $this->assertEquals('GET', $context->getMethod());
38
        $this->assertEquals('127.0.0.1', $context->getClientIp());
39
    }
40
41
    public function testPathInfoClosure()
42
    {
43
        $context = new RequestContext(function () { return '/foo'; });
44
        $this->assertEquals('/foo', $context->getPathInfo());
45
    }
46
47
    public function testHostClosure()
48
    {
49
        $context = new RequestContext(null, function () { return 'site.com'; });
50
        $this->assertEquals('site.com', $context->getHost());
51
    }
52
}
53