testExpectationDocsLinked()   B
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 27
Code Lines 16

Duplication

Lines 27
Ratio 100 %

Importance

Changes 0
Metric Value
dl 27
loc 27
rs 8.5806
c 0
b 0
f 0
cc 4
eloc 16
nc 3
nop 0
1
<?php
2
3
namespace Overwatch\ServiceBundle\Tests\Expectation;
4
5
use FilesystemIterator;
6
use Symfony\Component\Filesystem\Filesystem;
7
8
/**
9
 * ExpectationDocumentationTest
10
 */
11 View Code Duplication
class ExpectationDocumentationTest 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 $expectationDir;
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/expectations';
24
        $this->expectationDir = __DIR__ . '/../../Expectation';
25
    }
26
    
27
    public function testExpectationsDocumented()
28
    {
29
        $this->assertEquals(
30
            $this->countFiles($this->expectationDir),
31
            $this->countFiles($this->docDir)
32
        );
33
    }
34
    
35
    public function testExpectationDocsLinked()
36
    {
37
        $indexMd = file_get_contents($this->docDir . '/../index.md');
38
        $expectations = explode("\n", strstr(strstr($indexMd, '##Getting test results', true), '##Expectations'));
39
        $countExpectationsInIndex = 0;
40
        
41
        foreach ($expectations as $expectation) {
42
            if (strpos($expectation, '- ') !== 0) {
43
                continue;
44
            }
45
            
46
            $matches = [];
47
            preg_match('/^- \[[A-Z]+\]\(expectations(\/[A-Z_]+\.md)\)/i', $expectation, $matches);
48
            
49
            $this->assertTrue((
50
                file_exists(realpath($this->docDir . $matches[1])) &&
51
                !is_dir(realpath($this->docDir . $matches[1]))
52
            ));
53
            
54
            $countExpectationsInIndex++;
55
        }
56
                
57
        $this->assertEquals(
58
            $this->countFiles($this->docDir),
59
            $countExpectationsInIndex
60
        );
61
    }
62
    
63
    private function countFiles($dir)
64
    {
65
        return iterator_count(new FilesystemIterator($dir, FilesystemIterator::SKIP_DOTS));
66
    }
67
}
68