Completed
Push — master ( b91597...be19b0 )
by Mitchel
02:09
created

CertificateTypeTest   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 66
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A itRepresentsACertificateType() 0 7 1
A itGivesAllTypesAsList() 0 11 1
A itGivesAllTypesAsStringList() 0 11 1
A itTellsIfItsEqualOrNot() 0 9 1
A itThrowsAnErrorWhenTypeIsNotKnown() 0 4 1
1
<?php
2
3
namespace Bunq\Tests\Certificate;
4
5
use Bunq\Certificate\CertificateType;
6
use PHPUnit\Framework\TestCase;
7
8
final class CertificateTypeTest extends TestCase
9
{
10
    /**
11
     * @test
12
     */
13
    public function itRepresentsACertificateType()
14
    {
15
        $certificateType = CertificateType::fromString('private.pem');
16
17
        $this->assertInstanceOf(CertificateType::class, $certificateType);
18
        $this->assertEquals($certificateType->toString(), 'private.pem');
19
    }
20
21
    /**
22
     * @test
23
     */
24
    public function itGivesAllTypesAsList()
25
    {
26
        $expected = [
27
            CertificateType::PRIVATE_KEY(),
28
            CertificateType::PUBLIC_KEY(),
29
            CertificateType::BUNQ_SERVER_KEY(),
30
        ];
31
        $result = CertificateType::all();
32
33
        $this->assertEquals($expected, $result);
34
    }
35
36
    /**
37
     * @test
38
     */
39
    public function itGivesAllTypesAsStringList()
40
    {
41
        $expected = [
42
            'private.pem',
43
            'public.pem',
44
            'public_server_key.pem',
45
        ];
46
        $result = CertificateType::allAsString();
47
48
        $this->assertEquals($expected, $result);
49
    }
50
51
    /**
52
     * @test
53
     */
54
    public function itTellsIfItsEqualOrNot()
55
    {
56
        $certificate = CertificateType::PRIVATE_KEY();
57
58
        $this->assertTrue($certificate->equals(CertificateType::PRIVATE_KEY()));
59
        $this->assertFalse($certificate->equals(CertificateType::PUBLIC_KEY()));
60
        $this->assertFalse($certificate->equals(new \stdClass()));
61
        $this->assertFalse($certificate->equals('private key'));
62
    }
63
64
    /**
65
     * @test
66
     * @expectedException \InvalidArgumentException
67
     * @expectedExceptionMessage Invalid certificate type test
68
     */
69
    public function itThrowsAnErrorWhenTypeIsNotKnown()
70
    {
71
        CertificateType::fromString('test');
72
    }
73
}
74