Passed
Push — master ( 21c505...12ca40 )
by Sebastian
02:34
created

ConfiguratorTest::testConfigureFileExtend()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 14
nc 1
nop 0
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 sebastianfeldmann\CaptainHook\Runner;
11
12
class ConfiguratorTest extends BaseTestRunner
13
{
14
    /**
15
     * Tests Installer::installHook
16
     */
17
    public function testConfigureCliHook()
18
    {
19
        $io     = $this->getIOMock();
20
        $config = $this->getConfigMock();
21
        $repo   = $this->getRepositoryMock();
22
        $runner = new Configurator($io, $config, $repo);
23
        $config->method('getHookConfig')->willReturn($this->getHookConfigMock());
24
        $io->method('ask')->will($this->onConsecutiveCalls('y', 'y', 'echo \'foo\'', 'n'));
25
        $runner->configureHook($config, 'pre-push', true);
26
    }
27
28
    /**
29
     * Tests Installer::installHook
30
     */
31
    public function testConfigurePHPHook()
32
    {
33
        $io     = $this->getIOMock();
34
        $config = $this->getConfigMock();
35
        $repo   = $this->getRepositoryMock();
36
        $runner = new Configurator($io, $config, $repo);
37
        $config->method('getHookConfig')->willReturn($this->getHookConfigMock());
38
        $io->method('ask')->will($this->onConsecutiveCalls('y', 'y', '\\Foo\\Bar', 'y', 'n'));
39
        $io->expects($this->once())->method('askAndValidate')->willReturn('foo:bar');
40
        $runner->configureHook($config, 'pre-push', true);
41
    }
42
43
    /**
44
     * Tests Installer::installHook
45
     *
46
     * @expectedException \Exception
47
     */
48
    public function testConfigureFileExists()
49
    {
50
        $io     = $this->getIOMock();
51
        $config = $this->getConfigMock();
52
        $repo   = $this->getRepositoryMock();
53
        $runner = new Configurator($io, $config, $repo);
54
        $config->expects($this->once())->method('isLoadedFromFile')->willReturn(true);
55
        $io->method('ask')->will($this->onConsecutiveCalls('y', 'y', '\\Foo\\Bar', 'y', 'n'));
56
        $runner->run();
57
58
    }
59
60
61
    /**
62
     * Tests Installer::installHook
63
     */
64
    public function testConfigureFileExtend()
65
    {
66
        $path   = sys_get_temp_dir() . DIRECTORY_SEPARATOR . md5(__FILE__);
67
        $io     = $this->getIOMock();
68
        $config = $this->getConfigMock();
69
        $repo   = $this->getRepositoryMock();
70
        $runner = new Configurator($io, $config, $repo);
71
        $config->method('getHookConfig')->willReturn($this->getHookConfigMock());
72
        $config->method('getPath')->willReturn($path);
73
        $io->method('ask')->will($this->onConsecutiveCalls('y', 'y', '\\Foo\\Bar', 'y', 'n'));
74
        $io->expects($this->once())->method('askAndValidate')->willReturn('foo:bar');
75
        $runner->extend(true);
76
        $runner->run();
77
78
        $this->assertTrue(file_exists($path));
79
        unlink($path);
80
    }
81
}
82