Passed
Push — main ( 4c5bd3...8fb247 )
by Sebastian
15:06
created

CloverXMLTest::testValid100Percent()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
/**
4
 * This file is part of CaptainHook
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CaptainHook\App\Hook\PHP\CoverageResolver;
13
14
use Exception;
15
use PHPUnit\Framework\TestCase;
16
17
class CloverXMLTest extends TestCase
18
{
19
    /**
20
     * Tests CloverXML::getCoverage
21
     */
22
    public function testValid(): void
23
    {
24
        $resolver = new CloverXML(CH_PATH_FILES . '/coverage/valid.xml');
25
        $coverage = $resolver->getCoverage();
26
27
        $this->assertEquals(95, $coverage);
28
    }
29
30
    /**
31
     * Tests CloverXML::getCoverage
32
     */
33
    public function testValid100Percent(): void
34
    {
35
        $resolver = new CloverXML(CH_PATH_FILES . '/coverage/valid-100.xml');
36
        $coverage = $resolver->getCoverage();
37
38
        $this->assertEquals(100, $coverage);
39
    }
40
41
    /**
42
     * Tests CloverXML::__construct
43
     */
44
    public function testFileNotFound(): void
45
    {
46
        $this->expectException(Exception::class);
47
48
        $resolver = new CloverXML('foo.xml');
49
        $this->assertNull($resolver);
50
    }
51
52
    /**
53
     * Tests CloverXML::__construct
54
     */
55
    public function testCrapMetrics(): void
56
    {
57
        $this->expectException(Exception::class);
58
59
        $resolver = new CloverXML(CH_PATH_FILES . '/coverage/invalid-crap.xml');
60
        $resolver->getCoverage();
61
    }
62
63
    /**
64
     * Tests CloverXML::__construct
65
     */
66
    public function testInvalidXML(): void
67
    {
68
        $this->expectException(Exception::class);
69
70
        $resolver = new CloverXML(CH_PATH_FILES . '/coverage/no-metrics.xml');
71
        $this->assertNull($resolver);
72
    }
73
74
    /**
75
     * Tests CloverXML::__construct
76
     */
77
    public function testInvalidMetrics(): void
78
    {
79
        $this->expectException(Exception::class);
80
81
        $resolver = new CloverXML(CH_PATH_FILES . '/coverage/invalid-metrics.xml');
82
        $resolver->getCoverage();
83
    }
84
}
85