CheckLockFileTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 64
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 38
dl 0
loc 64
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A testExecute() 0 13 1
A testExecuteFail() 0 14 1
A testExecuteNoHash() 0 14 1
A testExecuteInvalidPath() 0 13 1
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\Composer\Action;
13
14
use CaptainHook\App\Config;
15
use CaptainHook\App\Console\IO\NullIO;
16
use CaptainHook\App\Mockery;
17
use Exception;
18
use PHPUnit\Framework\TestCase;
19
20
class CheckLockFileTest extends TestCase
21
{
22
    use Mockery;
23
24
    public function testExecute(): void
25
    {
26
        $io     = new NullIO();
27
        $config = new Config(CH_PATH_FILES . '/captainhook.json');
28
        $repo   = $this->createRepositoryMock();
29
        $action = new Config\Action(
30
            CheckLockFile::class,
31
            ['path' => CH_PATH_FILES . '/composer/valid', 'name' => 'composer.fake']
32
        );
33
        $standard = new CheckLockFile();
34
        $standard->execute($config, $io, $repo, $action);
35
36
        $this->assertTrue(true);
37
    }
38
39
    public function testExecuteFail(): void
40
    {
41
        $this->expectException(Exception::class);
42
43
        $io     = new NullIO();
44
        $config = new Config(CH_PATH_FILES . '/captainhook.json');
45
        $repo   = $this->createRepositoryMock();
46
        $action = new Config\Action(
47
            CheckLockFile::class,
48
            ['path' => CH_PATH_FILES . '/composer/invalid-hash', 'name' => 'composer.fake']
49
        );
50
51
        $standard = new CheckLockFile();
52
        $standard->execute($config, $io, $repo, $action);
53
    }
54
55
    public function testExecuteNoHash(): void
56
    {
57
        $this->expectException(Exception::class);
58
59
        $io     = new NullIO();
60
        $config = new Config(CH_PATH_FILES . '/captainhook.json');
61
        $repo   = $this->createRepositoryMock();
62
        $action = new Config\Action(
63
            CheckLockFile::class,
64
            ['path' => CH_PATH_FILES . '/composer/no-hash', 'name' => 'composer.fake']
65
        );
66
67
        $standard = new CheckLockFile();
68
        $standard->execute($config, $io, $repo, $action);
69
    }
70
71
    public function testExecuteInvalidPath(): void
72
    {
73
        $this->expectException(Exception::class);
74
75
        $io     = new NullIO();
76
        $config = new Config(CH_PATH_FILES . '/captainhook.json');
77
        $repo   = $this->createRepositoryMock();
78
        $action = new Config\Action(
79
            CheckLockFile::class,
80
            ['path' => CH_PATH_FILES . '/composer/not-there']
81
        );
82
        $standard = new CheckLockFile();
83
        $standard->execute($config, $io, $repo, $action);
84
    }
85
}
86