TokenTest::setToken()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace TonicHealthCheck\Test\CachetHQ\Authentication;
4
5
use PHPUnit_Framework_TestCase;
6
use Psr\Http\Message\RequestInterface;
7
use TonicHealthCheck\CachetHQ\Authentication\Token;
8
9
/**
10
 * Authenticate a PSR-7 Request using a token.
11
 */
12
class TokenTest extends PHPUnit_Framework_TestCase
13
{
14
    const DEFAULT_TOKEN = 'xsf322tg2r14tf1wfwff';
15
    /**
16
     * @var string
17
     */
18
    private $tokenString = self::DEFAULT_TOKEN;
19
20
    /**
21
     * @var Token
22
     */
23
    private $token;
24
25
    /**
26
     * Test that Authenticate set header.
27
     */
28
    public function testAuthenticate()
29
    {
30
        $this->setToken(new Token($this->getTokenString()));
31
        $request = $this->getMockBuilder(RequestInterface::class)->getMock();
32
33
        $request
34
            ->expects($this->once())
35
            ->method('withHeader')
36
            ->with(Token::COOKIE_CACHET_TOKEN, $this->equalTo($this->getTokenString()));
37
38
        $this->getToken()->authenticate($request);
39
    }
40
41
    /**
42
     * @return string
43
     */
44
    protected function getTokenString()
45
    {
46
        return $this->tokenString;
47
    }
48
49
    /**
50
     * @param string $tokenString
51
     */
52
    protected function setTokenString($tokenString)
53
    {
54
        $this->tokenString = $tokenString;
55
    }
56
57
    /**
58
     * @return Token
59
     */
60
    protected function getToken()
61
    {
62
        return $this->token;
63
    }
64
65
    /**
66
     * @param Token $token
67
     */
68
    protected function setToken(Token $token)
69
    {
70
        $this->token = $token;
71
    }
72
}
73