Failed Conditions
Push — master ( b9670c...4ba57f )
by Zac
16:20 queued 37s
created

testExpectationDocsLinked()   B

Complexity

Conditions 4
Paths 3

Size

Total Lines 27
Code Lines 16

Duplication

Lines 27
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 27
loc 27
rs 8.5806
cc 4
eloc 16
nc 3
nop 0
1
<?php
2
3
namespace Overwatch\ServiceBundle\Tests\Reporter;
4
5
use FilesystemIterator;
6
use Symfony\Component\Filesystem\Filesystem;
7
8
/**
9
 * ReporterDocumentationTest
10
 */
11 View Code Duplication
class ReporterDocumentationTest extends \PHPUnit_Framework_TestCase
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
12
{
13
    private $docDir;
14
    private $reporterDir;
15
    private $fs;
16
    
17
    public function setUp()
18
    {
19
        if ($this->fs === null) {
20
            $this->fs = new Filesystem();
21
        }
22
        
23
        $this->docDir = __DIR__ . '/../../../../app/Resources/docs/result-reporters';
24
        $this->reporterDir = __DIR__ . '/../../Reporter';
25
    }
26
    
27
    public function testExpectationsDocumented()
28
    {
29
        $this->assertEquals(
30
            $this->countFiles($this->reporterDir),
31
            $this->countFiles($this->docDir)
32
        );
33
    }
34
    
35
    public function testExpectationDocsLinked()
36
    {
37
        $indexMd = file_get_contents($this->docDir . '/../index.md');
38
        $reporters = explode("\n", strstr(strstr($indexMd, '##Overwatch REST API', true), '##Getting test results'));
39
        $countReportersInIndex = 0;
40
        
41
        foreach ($reporters as $reporter) {
42
            if (strpos($reporter, '- ') !== 0) {
43
                continue;
44
            }
45
            
46
            $matches = [];
47
            preg_match('/^- \[[A-Z]+\]\(result-reporters(\/[A-Z_]+\.md)\)/i', $reporter, $matches);
48
            
49
            $this->assertTrue((
50
                file_exists(realpath($this->docDir . $matches[1])) &&
51
                !is_dir(realpath($this->docDir . $matches[1]))
52
            ));
53
            
54
            $countReportersInIndex++;
55
        }
56
                
57
        $this->assertEquals(
58
            $this->countFiles($this->docDir),
59
            $countReportersInIndex
60
        );
61
    }
62
    
63
    private function countFiles($dir)
64
    {
65
        return iterator_count(new FilesystemIterator($dir, FilesystemIterator::SKIP_DOTS));
66
    }
67
}
68