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\DatabaseConnectionCheck; |
14
|
|
|
|
15
|
|
|
class DatabaseConnectionCheckTest extends \PHPUnit_Framework_TestCase |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @var \Gerrie\Check\CheckInterface |
20
|
|
|
*/ |
21
|
|
|
protected $checkInstance; |
22
|
|
|
|
23
|
|
|
public function setUp() |
24
|
|
|
{ |
25
|
|
|
$databaseMock = $this->getDatabaseMock(); |
26
|
|
|
$this->checkInstance = new DatabaseConnectionCheck($databaseMock); |
27
|
|
|
} |
28
|
|
|
|
29
|
|
|
protected function getDatabaseMock($connectWillThrowException = false) |
30
|
|
|
{ |
31
|
|
|
$database = $this->getMock('Gerrie\Component\Database\Database', [], [[]]); |
32
|
|
|
|
33
|
|
|
if ($connectWillThrowException === true) { |
34
|
|
|
$database->expects($this->any()) |
35
|
|
|
->method('connect') |
36
|
|
|
->will($this->throwException(new \Exception())); |
37
|
|
|
} |
38
|
|
|
|
39
|
|
|
return $database; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
public function tearDown() |
43
|
|
|
{ |
44
|
|
|
$this->checkInstance = null; |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
public function testCheckWithDatabaseConnection() |
48
|
|
|
{ |
49
|
|
|
$this->assertTrue($this->checkInstance->check()); |
50
|
|
|
} |
51
|
|
|
|
52
|
|
|
public function testCheckWithoutDatabaseConnection() |
53
|
|
|
{ |
54
|
|
|
$databaseMock = $this->getDatabaseMock(true); |
55
|
|
|
$checkInstance = new DatabaseConnectionCheck($databaseMock); |
56
|
|
|
|
57
|
|
|
$this->assertFalse($checkInstance->check()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function testGetFailureMessage() |
61
|
|
|
{ |
62
|
|
|
$this->checkInstance->check(); |
63
|
|
|
$this->assertInternalType('string', $this->checkInstance->getFailureMessage()); |
64
|
|
|
} |
65
|
|
|
|
66
|
|
|
public function testGetSuccessMessage() |
67
|
|
|
{ |
68
|
|
|
$this->assertInternalType('string', $this->checkInstance->getSuccessMessage()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
public function testIsOptional() |
72
|
|
|
{ |
73
|
|
|
$this->assertInternalType('bool', $this->checkInstance->isOptional()); |
74
|
|
|
} |
75
|
|
|
} |