Failed Conditions
Push — master ( f4dd73...badc21 )
by Luís
15s
created

getPassphraseShouldReturnAnEmptyStringWhenNothingWasConfigured()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 5
rs 10
c 0
b 0
f 0
1
<?php
2
declare(strict_types=1);
3
4
namespace Lcobucci\JWT\Signer;
5
6
use InvalidArgumentException;
7
use org\bovigo\vfs\vfsStream;
8
use PHPUnit\Framework\TestCase;
9
10
final class KeyTest extends TestCase
11
{
12
    /**
13
     * @before
14
     */
15
    public function configureRootDir(): void
16
    {
17
        vfsStream::setup(
18
            'root',
19
            null,
20
            ['test.pem' => 'testing']
21
        );
22
    }
23
24
    /**
25
     * @test
26
     *
27
     * @covers \Lcobucci\JWT\Signer\Key::__construct
28
     * @covers \Lcobucci\JWT\Signer\Key::setContent
29
     * @covers \Lcobucci\JWT\Signer\Key::readFile
30
     */
31
    public function constructShouldRaiseExceptionWhenFileDoesNotExists(): void
32
    {
33
        $this->expectException(InvalidArgumentException::class);
34
        $this->expectExceptionMessage('You must inform a valid key file');
35
36
        new Key('file://' . vfsStream::url('root/test2.pem'));
37
    }
38
39
    /**
40
     * @test
41
     *
42
     * @covers \Lcobucci\JWT\Signer\Key::getContent
43
     *
44
     * @uses \Lcobucci\JWT\Signer\Key::__construct
45
     * @uses \Lcobucci\JWT\Signer\Key::setContent
46
     */
47
    public function getContentShouldReturnConfiguredData(): void
48
    {
49
        $key = new Key('testing', 'test');
50
51
        self::assertSame('testing', $key->getContent());
52
    }
53
54
    /**
55
     * @test
56
     *
57
     * @covers \Lcobucci\JWT\Signer\Key::__construct
58
     * @covers \Lcobucci\JWT\Signer\Key::setContent
59
     * @covers \Lcobucci\JWT\Signer\Key::readFile
60
     * @covers \Lcobucci\JWT\Signer\Key::getContent
61
     */
62
    public function getContentShouldReturnFileContentsWhenFilePathHasBeenPassed(): void
63
    {
64
        $key = new Key('file://' . vfsStream::url('root/test.pem'));
65
66
        self::assertSame('testing', $key->getContent());
67
    }
68
69
    /**
70
     * @test
71
     *
72
     * @covers \Lcobucci\JWT\Signer\Key::getPassphrase
73
     *
74
     * @uses \Lcobucci\JWT\Signer\Key::__construct
75
     * @uses \Lcobucci\JWT\Signer\Key::setContent
76
     */
77
    public function getPassphraseShouldReturnConfiguredData(): void
78
    {
79
        $key = new Key('testing', 'test');
80
81
        self::assertSame('test', $key->getPassphrase());
82
    }
83
84
    /**
85
     * @test
86
     *
87
     * @covers \Lcobucci\JWT\Signer\Key::getPassphrase
88
     *
89
     * @uses \Lcobucci\JWT\Signer\Key::__construct
90
     * @uses \Lcobucci\JWT\Signer\Key::setContent
91
     */
92
    public function getPassphraseShouldReturnAnEmptyStringWhenNothingWasConfigured(): void
93
    {
94
        $key = new Key('testing');
95
96
        self::assertSame('', $key->getPassphrase());
97
    }
98
}
99