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; |
11
|
|
|
|
12
|
|
|
class ConfigTest extends \PHPUnit_Framework_TestCase |
13
|
|
|
{ |
14
|
|
|
/** |
15
|
|
|
* Tests Config::__construct |
16
|
|
|
*/ |
17
|
|
|
public function testConstructor() |
18
|
|
|
{ |
19
|
|
|
$config = new Config('./no-config.json'); |
20
|
|
|
|
21
|
|
|
$this->assertTrue($config->getHookConfig('commit-msg') instanceof Config\Hook); |
22
|
|
|
$this->assertTrue($config->getHookConfig('pre-commit') instanceof Config\Hook); |
23
|
|
|
$this->assertTrue($config->getHookConfig('pre-push') instanceof Config\Hook); |
24
|
|
|
|
25
|
|
|
$this->assertFalse($config->isLoadedFromFile()); |
26
|
|
|
} |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Tests Config::isLoadedFromFile |
30
|
|
|
*/ |
31
|
|
|
public function testIsLoadedFromFile() |
32
|
|
|
{ |
33
|
|
|
$path = realpath(__DIR__ . '/../files/config/valid.json'); |
34
|
|
|
$config = new Config($path, true); |
35
|
|
|
|
36
|
|
|
$this->assertTrue($config->isLoadedFromFile()); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
/** |
40
|
|
|
* Tests Config::getHookConfig |
41
|
|
|
* |
42
|
|
|
* @expectedException \Exception |
43
|
|
|
*/ |
44
|
|
|
public function testGetInvalidHook() |
45
|
|
|
{ |
46
|
|
|
$config = new Config('./no-config.json'); |
47
|
|
|
$config->getHookConfig('foo'); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Tests Config::getPath |
52
|
|
|
*/ |
53
|
|
|
public function testGetPath() |
54
|
|
|
{ |
55
|
|
|
$path = realpath(__DIR__ . '/../files/config/valid.json'); |
56
|
|
|
$config = new Config($path); |
57
|
|
|
|
58
|
|
|
$this->assertEquals($path, $config->getPath()); |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* Tests Config::getJsonData |
63
|
|
|
*/ |
64
|
|
|
public function testGetJsonData() |
65
|
|
|
{ |
66
|
|
|
$config = new Config('./no-config.json'); |
67
|
|
|
$json = $config->getJsonData(); |
68
|
|
|
|
69
|
|
|
$this->assertTrue(is_array($json)); |
70
|
|
|
$this->assertTrue(is_array($json['pre-commit'])); |
71
|
|
|
$this->assertTrue(is_array($json['commit-msg'])); |
72
|
|
|
$this->assertTrue(is_array($json['pre-push'])); |
73
|
|
|
} |
74
|
|
|
} |
75
|
|
|
|