Passed
Push — master ( 7bee4d...457c92 )
by Sebastian
01:54
created

EnableTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 25
dl 0
loc 51
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testExecuteNoConfig() 0 14 1
A testExecuteEnablePrePush() 0 27 1
1
<?php
2
/**
3
 * This file is part of CaptainHook.
4
 *
5
 * (c) Sebastian Feldmann <[email protected]>
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
namespace CaptainHook\App\Console\Command;
11
12
use CaptainHook\App\Console\IO\DefaultIO;
13
use CaptainHook\App\Console\IO\NullIO;
14
use Symfony\Component\Console\Input\ArrayInput;
15
use Symfony\Component\Console\Tests\Fixtures\DummyOutput;
16
use PHPUnit\Framework\TestCase;
17
18
class EnableTest extends TestCase
19
{
20
    /**
21
     * Tests Enable::run
22
     */
23
    public function testExecuteNoConfig(): void
24
    {
25
        $this->expectException(\Exception::class);
26
27
        $input   = new ArrayInput(
28
            [
29
                'hook' => 'pre-commit',
30
                '--configuration' => 'foo'
31
            ]
32
        );
33
        $output  = new DummyOutput();
34
        $install = new Enable();
35
        $install->setIO(new NullIO());
36
        $install->run($input, $output);
37
    }
38
39
    /**
40
     * Tests Enable::run
41
     */
42
    public function testExecuteEnablePrePush(): void
43
    {
44
        $config = sys_get_temp_dir() . '/captainhook-enable.json';
45
        copy(CH_PATH_FILES . '/config/valid.json', $config);
46
47
48
        $add    = new Enable();
49
        $output = new DummyOutput();
50
        $input  = new ArrayInput(
51
            [
52
                'hook'            => 'pre-push',
53
                '--configuration' => $config
54
            ]
55
        );
56
57
        $io = $this->getMockBuilder(DefaultIO::class)
58
                   ->disableOriginalConstructor()
59
                   ->getMock();
60
        $io->expects($this->once())->method('write');
61
62
        $add->setIO($io);
63
        $add->run($input, $output);
64
65
        $json = json_decode(file_get_contents($config), true);
66
        $this->assertTrue($json['pre-push']['enabled']);
67
68
        unlink($config);
69
    }
70
}
71