Completed
Push — master ( 0aa69f...1f2f47 )
by Hannes
04:03
created

AssertReadme::assertFile()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.2
c 0
b 0
f 0
cc 4
eloc 10
nc 3
nop 2
1
<?php
2
3
namespace hanneskod\readmetester\PHPUnit;
4
5
use hanneskod\readmetester\ReadmeTester;
6
7
class AssertReadme
8
{
9
    /**
10
     * @var \PHPUnit_Framework_TestCase
11
     */
12
    private $testCase;
13
14
    /**
15
     * @var ReadmeTester
16
     */
17
    private $tester;
18
19
    public function __construct(\PHPUnit_Framework_TestCase $testCase, ReadmeTester $tester = null)
20
    {
21
        $this->testCase = $testCase;
22
        $this->tester = $tester ?: new ReadmeTester;
23
    }
24
25
    public function assertReadme($filename)
26
    {
27
        $result = $this->testCase->getTestResultObject();
28
29
        foreach ($this->tester->test(file_get_contents($filename)) as $example => $returnObj) {
30
            $this->testCase->addToAssertionCount(1);
31
            if ($returnObj->isFailure()) {
32
                $result->addFailure(
33
                    $this->testCase,
34
                    new \PHPUnit_Framework_AssertionFailedError("Example $example: {$returnObj->getMessage()}"),
35
                    0.0
36
                );
37
            }
38
        }
39
    }
40
}
41