Passed
Push — master ( 1eca82...577019 )
by Sebastian
03:18 queued 45s
created

PHPTest::testSrcTemplateExtExecutable()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 9
c 0
b 0
f 0
dl 0
loc 12
rs 9.9666
cc 1
nc 1
nop 0
1
<?php
2
3
/**
4
 * This file is part of CaptainHook
5
 *
6
 * (c) Sebastian Feldmann <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace CaptainHook\App\Hook\Template\Local;
13
14
use PHPUnit\Framework\TestCase;
15
use SebastianFeldmann\Camino\Path\Directory;
16
use SebastianFeldmann\Camino\Path\File;
17
18
class PHPTest extends TestCase
19
{
20
    /**
21
     * Tests PHP::getCode
22
     */
23
    public function testSrcTemplate(): void
24
    {
25
        $repo       = new Directory('/foo/bar');
26
        $config     = new File('/foo/bar/captainhook.json');
27
        $bootstrap  = new File('/foo/bar/vendor/autoload.php');
28
        $executable = new File('/foo/bar/vendor/bin/captainhook');
29
        $template   = new PHP($repo, $config, $executable, $bootstrap, false);
30
        $code       = $template->getCode('commit-msg');
31
32
        $this->assertStringContainsString('#!/usr/bin/env php', $code);
33
        $this->assertStringContainsString('commit-msg', $code);
34
        $this->assertStringContainsString('$captainHook->run(', $code);
35
    }
36
37
    /**
38
     * Tests PHP::getCode
39
     */
40
    public function testSrcTemplateExtExecutable(): void
41
    {
42
        $repo       = new Directory('/foo/bar');
43
        $config     = new File('/foo/bar/captainhook.json');
44
        $bootstrap  = new File('/foo/bar/vendor/autoload.php');
45
        $executable = new File('/usr/local/bin/captainhook');
46
        $template   = new PHP($repo, $config, $executable, $bootstrap, false);
47
        $code       = $template->getCode('commit-msg');
48
49
        $this->assertStringContainsString('#!/usr/bin/env php', $code);
50
        $this->assertStringContainsString('commit-msg', $code);
51
        $this->assertStringContainsString('$captainHook->run(', $code);
52
    }
53
54
    /**
55
     * Tests PHP::getCode
56
     */
57
    public function testPharTemplate(): void
58
    {
59
        $repo       = new Directory('/foo/bar');
60
        $config     = new File('/foo/bar/captainhook.json');
61
        $bootstrap  = new File('/foo/bar/vendor/autoload.php');
62
        $executable = new File('/foo/bar/tools/captainhook.phar');
63
        $template   = new PHP($repo, $config, $executable, $bootstrap, true);
64
        $code       = $template->getCode('commit-msg');
65
66
        $this->assertStringContainsString('#!/usr/bin/env php', $code);
67
        $this->assertStringContainsString('hook:commit-msg', $code);
68
        $this->assertStringContainsString('tools/captainhook.phar', $code);
69
    }
70
}
71