Completed
Push — master ( d372d6...3eec25 )
by Christian
02:37
created

ConfigTest   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 1
c 0
b 0
f 0
lcom 0
cbo 7
dl 0
loc 43
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B testConfigMergingFromDifferentSources() 0 40 1
1
<?php
2
3
namespace uuf6429\ElderBrother\Config;
4
5
use Psr\Log\NullLogger;
6
use uuf6429\ElderBrother\Action;
7
use uuf6429\ElderBrother\Change;
8
9
class ConfigTest extends \PHPUnit_Framework_TestCase
10
{
11
    public function testConfigMergingFromDifferentSources()
12
    {
13
        $testFile = tempnam(sys_get_temp_dir(), 'test');
14
        $content = sprintf(
15
            '<?php return ["event1" => [ new %s(%s::get()) ]];',
16
            Action\PhpLinter::class,
17
            Change\FullChangeSet::class
18
        );
19
        $this->assertNotFalse(file_put_contents($testFile, $content));
20
21
        $cfg = new Config();
22
        $cfg->loadFromFile($testFile, new NullLogger());
23
        $cfg->loadFromArray(
24
            [
25
                'event2' => [
26
                    new Action\PhpLinter(Change\FullChangeSet::get()),
27
                ],
28
                'event1' => [
29
                    new Action\RiskyFiles(Change\FullChangeSet::get(), ''),
30
                    new Action\ForbiddenFiles(Change\FullChangeSet::get(), ''),
31
                ],
32
            ],
33
            new NullLogger()
34
        );
35
36
        $this->assertSame(
37
            ['event1', 'event2'],
38
            array_keys($cfg->getAllEventActions())
39
        );
40
        $this->assertSame(
41
            [Action\RiskyFiles::class, Action\ForbiddenFiles::class],
42
            array_map('get_class', $cfg->getActionsForEvent('event1'))
43
        );
44
        $this->assertSame(
45
            [Action\PhpLinter::class],
46
            array_map('get_class', $cfg->getActionsForEvent('event2'))
47
        );
48
49
        $this->assertNotFalse(unlink($testFile));
50
    }
51
}
52