1
|
|
|
<?php |
2
|
|
|
/** |
3
|
|
|
* This file is part of the Gerrie package. |
4
|
|
|
* |
5
|
|
|
* (c) Andreas Grunwald <[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
|
|
|
|
11
|
|
|
namespace Gerrie\Tests\Check; |
12
|
|
|
|
13
|
|
|
use Gerrie\Check\ConfigurationValidationCheck; |
14
|
|
|
|
15
|
|
|
class ConfigFileValidationCheckTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var \Gerrie\Check\CheckInterface |
20
|
|
|
*/ |
21
|
|
|
protected $checkInstance; |
22
|
|
|
|
23
|
|
|
public function setUp() |
24
|
|
|
{ |
25
|
|
|
$configuration = $this->getConfigurationMock(); |
26
|
|
|
$this->checkInstance = new ConfigurationValidationCheck($configuration); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
public function tearDown() |
30
|
|
|
{ |
31
|
|
|
$this->checkInstance = null; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
public function getConfigurationMock($allTrue = false) |
35
|
|
|
{ |
36
|
|
|
$configuration = $this->getMock('Gerrie\Component\Configuration\Configuration', ['hasConfigurationKey']); |
37
|
|
|
$configuration->expects($this->any()) |
38
|
|
|
->method('hasConfigurationKey') |
39
|
|
|
->withConsecutive( |
40
|
|
|
array($this->equalTo('Database.Host')), |
41
|
|
|
array($this->equalTo('Database.Username')), |
42
|
|
|
array($this->equalTo('Database.Password')), |
43
|
|
|
array($this->equalTo('Database.Port')), |
44
|
|
|
array($this->equalTo('Database.Name')) |
45
|
|
|
) |
46
|
|
|
->willReturnOnConsecutiveCalls( |
47
|
|
|
$this->returnValue(true), |
48
|
|
|
$this->returnValue(true), |
49
|
|
|
$this->returnValue($allTrue), |
50
|
|
|
$this->returnValue(true), |
51
|
|
|
$this->returnValue($allTrue) |
52
|
|
|
); |
53
|
|
|
|
54
|
|
|
return $configuration; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
public function testCheckWithAllProperties() |
58
|
|
|
{ |
59
|
|
|
$configuration = $this->getConfigurationMock(true); |
60
|
|
|
$configFileValidationCheck = new ConfigurationValidationCheck($configuration); |
61
|
|
|
$this->assertTrue($configFileValidationCheck->check()); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
public function testCheckWithMissingProperties() |
65
|
|
|
{ |
66
|
|
|
$this->assertFalse($this->checkInstance->check()); |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/* |
70
|
|
|
public function testWithNotExistingConfigCheck() |
71
|
|
|
{ |
72
|
|
|
$checkInstance = new ConfigFileCheck(''); |
73
|
|
|
$this->assertFalse($checkInstance->check()); |
74
|
|
|
} |
75
|
|
|
*/ |
76
|
|
|
|
77
|
|
|
public function testGetFailureMessage() |
78
|
|
|
{ |
79
|
|
|
$this->assertInternalType('string', $this->checkInstance->getFailureMessage()); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
public function testGetSuccessMessage() |
83
|
|
|
{ |
84
|
|
|
$this->assertInternalType('string', $this->checkInstance->getSuccessMessage()); |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
public function testIsOptional() |
88
|
|
|
{ |
89
|
|
|
$this->assertInternalType('bool', $this->checkInstance->isOptional()); |
90
|
|
|
} |
91
|
|
|
} |