Passed
Push — master ( 813fe9...62056b )
by Sebastian
06:01
created

HookTest::testRunNoHook()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 10
rs 9.4285
cc 1
eloc 7
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 CaptainHook\App\Console\Application;
11
12
use CaptainHook\App\Config;
13
use CaptainHook\App\Git\DummyRepo;
14
use Symfony\Component\Console\Input\ArrayInput;
15
use Symfony\Component\Console\Output\NullOutput;
16
17
class HookTest extends \PHPUnit_Framework_TestCase
18
{
19
    /**
20
     * Tests Hook::run
21
     */
22
    public function testRun()
23
    {
24
        $config = new Config(HMU_PATH_FILES . '/config/valid.json');
25
        $repo   = new DummyRepo();
26
        $output = new NullOutput();
27
        $input  = new ArrayInput([
28
            'file' => HMU_PATH_FILES . '/git/message/valid.txt',
29
        ]);
30
        $app = new Hook();
31
        $app->setConfigFile($config);
0 ignored issues
show
Documentation introduced by
$config is of type object<CaptainHook\App\Config>, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
32
        $app->setRepositoryPath($repo->getPath());
33
        $app->setHook('commit-msg');
34
        $app->setAutoExit(false);
35
        $app->run($input, $output);
36
37
        $repo->cleanup();
38
    }
39
40
    /**
41
     * Tests Hook::executeHook
42
     *
43
     * @expectedException \Exception
44
     */
45
    public function testRunInvalidHook()
46
    {
47
        $app = new Hook();
48
        $app->setHook('pre-foo');
49
    }
50
51
    /**
52
     * Tests Hook::executeHook
53
     */
54
    public function testRunNoHook()
55
    {
56
        $input  = new ArrayInput([]);
57
        $output = new NullOutput();
58
        $app    = new Hook();
59
        $app->setAutoExit(false);
60
        $exit = $app->run($input, $output);
61
62
        $this->assertTrue($exit != 0);
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $exit of type null|integer to 0; this is ambiguous as not only 0 == 0 is true, but null == 0 is true, too. Consider using a strict comparison ===.
Loading history...
63
    }
64
65
    /**
66
     * Tests Hook::getRepositoryPath
67
     */
68
    public function testGetRepositoryPath()
69
    {
70
        $app = new Hook();
71
        $this->assertEquals(getcwd(), $app->getRepositoryPath());
72
    }
73
74
    /**
75
     * Tests Hook::getConfigFile
76
     */
77
    public function testGetConfigFile()
78
    {
79
        $app = new Hook();
80
        $this->assertEquals(getcwd()  . '/captainhook.json', $app->getConfigFile());
81
    }
82
83
    /**
84
     * Tests Application::getHelp
85
     */
86
    public function testGetHelp()
87
    {
88
        $hook = new Hook();
89
        $help = $hook->getHelp();
90
91
        $this->assertTrue(
92
            (bool)strpos(
93
                $help,
94
                '$$$$b ^ceeeee.  4$$ECL.F*$$$$$$$'
95
            )
96
        );
97
    }
98
}
99