summaryrefslogtreecommitdiffstats
path: root/library/Director/Test/TestSuiteLint.php
blob: 41941eb59637fb5e5318a52dca15ae9e2cb8c9da (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
<?php

namespace Icinga\Module\Director\Test;

use Icinga\Application\Logger;

class TestSuiteLint extends TestSuite
{
    protected $checked;

    protected $failed;

    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;
    }
}