summaryrefslogtreecommitdiffstats
path: root/library/Director/Test/TestSuiteLint.php
blob: 0010c286824b33cd694b660e414b6bea528de816 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
<?php

namespace Icinga\Module\Director\Test;

use Icinga\Application\Logger;

class TestSuiteLint extends TestSuite
{
    protected $checked;

    protected $failed;

    protected $result = [];

    public function run()
    {
        $this->checked = $this->failed = array();

        foreach ($this->listFiles() as $file) {
            $checked[] = $file;
            $cmd = "php -l '$file'";
            $this->result[$file] = $this
                ->process($cmd, $file)
                ->onFailure(array($this, 'failedCheck'))
                ->run();
        }
    }

    public function failedCheck($process)
    {
        Logger::error($process->getOutput());
        $this->failed[] = $process->getIdentifier();
    }

    public function hasFailures()
    {
        return ! empty($this->failed);
    }

    protected function listFiles()
    {
        $basedir = $this->getBaseDir();
        $files = array(
            $basedir . '/run.php',
            $basedir . '/configuration.php'
        );

        foreach ($this->filesByExtension('library/Director', 'php') as $file) {
            $files[] = $file;
        }

        foreach ($this->filesByExtension('application', array('php', 'phtml')) as $file) {
            $files[] = $file;
        }

        return $files;
    }
}