1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* admin |
5
|
|
|
* |
6
|
|
|
* @category Tollwerk |
7
|
|
|
* @package Tollwerk\Admin |
8
|
|
|
* @subpackage Tollwerk\Admin\Tests |
9
|
|
|
* @author Joschi Kuphal <[email protected]> / @jkphl |
10
|
|
|
* @copyright Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl |
11
|
|
|
* @license http://opensource.org/licenses/MIT The MIT License (MIT) |
12
|
|
|
*/ |
13
|
|
|
|
14
|
|
|
/*********************************************************************************** |
15
|
|
|
* The MIT License (MIT) |
16
|
|
|
* |
17
|
|
|
* Copyright © 2018 Joschi Kuphal <[email protected]> / @jkphl |
18
|
|
|
* |
19
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of |
20
|
|
|
* this software and associated documentation files (the "Software"), to deal in |
21
|
|
|
* the Software without restriction, including without limitation the rights to |
22
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of |
23
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so, |
24
|
|
|
* subject to the following conditions: |
25
|
|
|
* |
26
|
|
|
* The above copyright notice and this permission notice shall be included in all |
27
|
|
|
* copies or substantial portions of the Software. |
28
|
|
|
* |
29
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
30
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS |
31
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR |
32
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER |
33
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
34
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
35
|
|
|
***********************************************************************************/ |
36
|
|
|
|
37
|
|
|
namespace Tollwerk\Admin\Tests; |
38
|
|
|
|
39
|
|
|
use Doctrine\DBAL\DriverManager; |
40
|
|
|
use PHPUnit_Extensions_Database_DB_IDatabaseConnection; |
41
|
|
|
use Tollwerk\Admin\Infrastructure\App; |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* Abstract database test case |
45
|
|
|
* |
46
|
|
|
* @package Tollwerk\Admin |
47
|
|
|
* @subpackage Tollwerk\Admin\Tests |
48
|
|
|
*/ |
49
|
|
|
abstract class AbstractDatabaseTest extends \PHPUnit_Extensions_Database_TestCase |
50
|
|
|
{ |
51
|
|
|
/** |
52
|
|
|
* PDO instance |
53
|
|
|
* |
54
|
|
|
* @var null |
55
|
|
|
*/ |
56
|
|
|
private static $pdo = null; |
57
|
|
|
/** |
58
|
|
|
* DBAL instance |
59
|
|
|
* |
60
|
|
|
* @var null |
61
|
|
|
*/ |
62
|
|
|
private static $dbal = null; |
63
|
|
|
|
64
|
|
|
// only instantiate PHPUnit_Extensions_Database_DB_IDatabaseConnection once per test |
65
|
|
|
/** |
66
|
|
|
* Connection |
67
|
|
|
* |
68
|
|
|
* @var PHPUnit_Extensions_Database_DB_IDatabaseConnection |
69
|
|
|
*/ |
70
|
|
|
private $conn = null; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* Returns the test database connection. |
74
|
|
|
* |
75
|
|
|
* @return PHPUnit_Extensions_Database_DB_IDatabaseConnection Database connection |
76
|
|
|
*/ |
77
|
|
|
final protected function getConnection() |
78
|
|
|
{ |
79
|
|
|
if ($this->conn === null) { |
80
|
|
|
$dbparams = App::getConfig('doctrine.dbparams'); |
81
|
|
|
|
82
|
|
|
if (self::$pdo == null) { |
83
|
|
|
$dsn = 'mysql:dbname='.$dbparams['dbname'].';host='.$dbparams['host']; |
84
|
|
|
self::$pdo = new \PDO($dsn, $dbparams['user'], $dbparams['password']); |
|
|
|
|
85
|
|
|
} |
86
|
|
|
$this->conn = $this->createDefaultDBConnection(self::$pdo, $dbparams['dbname']); |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return $this->conn; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Return the PDO instance |
94
|
|
|
* |
95
|
|
|
* @return \PDO PDO instance |
96
|
|
|
*/ |
97
|
|
|
protected function getPdo() |
98
|
|
|
{ |
99
|
|
|
return $this->getConnection()->getConnection(); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* Return the DBAL connection |
104
|
|
|
* |
105
|
|
|
* @return \Doctrine\DBAL\Connection |
106
|
|
|
*/ |
107
|
|
|
protected function getDbal() |
108
|
|
|
{ |
109
|
|
|
if (self::$dbal === null) { |
110
|
|
|
self::$dbal = DriverManager::getConnection(array('pdo' => $this->getPdo())); |
|
|
|
|
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
return self::$dbal; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Return the absolute path to a fixture file |
118
|
|
|
* |
119
|
|
|
* @param string $fixture Fixture file name |
120
|
|
|
* @return string Absolute fixture file |
121
|
|
|
*/ |
122
|
|
|
protected function getFixture($fixture) |
123
|
|
|
{ |
124
|
|
|
return __DIR__.DIRECTORY_SEPARATOR.'Fixture'.DIRECTORY_SEPARATOR.$fixture; |
125
|
|
|
} |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* Create and return a dataset with certain replacements |
129
|
|
|
* |
130
|
|
|
* @param string $fixture Fixture file name |
131
|
|
|
* @return \PHPUnit_Extensions_Database_DataSet_ReplacementDataSet Data set |
132
|
|
|
*/ |
133
|
|
|
protected function getFixtureDataSet($fixture) |
134
|
|
|
{ |
135
|
|
|
$dataSet = $this->createFlatXMLDataSet($this->getFixture($fixture)); |
136
|
|
|
$replacementDataSet = new \PHPUnit_Extensions_Database_DataSet_ReplacementDataSet($dataSet); |
137
|
|
|
$replacementDataSet->addFullReplacement('##NULL##', null); |
138
|
|
|
return $replacementDataSet; |
139
|
|
|
} |
140
|
|
|
} |
141
|
|
|
|
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..