Skip to content

Commit d5c87b1

Browse files
committed
tests: Use latest PHPUnit version
1 parent 82ffc76 commit d5c87b1

File tree

11 files changed

+48
-79
lines changed

11 files changed

+48
-79
lines changed

.github/workflows/php.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ jobs:
1717
with:
1818
databases: true
1919
php-extensions: ldap
20-
phpunit-version: 9.6
2120
dependencies: |
2221
{
2322
"./icinga-php/ipl" : "https://github.com/Icinga/icinga-php-library.git#snapshot/nightly",

library/Icinga/Test/BaseTestCase.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ public function getResponseMock()
165165
* @return ConfigObject
166166
* @throws RuntimeException
167167
*/
168-
protected function createDbConfigFor($name)
168+
protected static function createDbConfigFor($name)
169169
{
170170
if (array_key_exists($name, self::$dbConfiguration)) {
171171
$config = new ConfigObject(self::$dbConfiguration[$name]);
@@ -193,10 +193,10 @@ protected function createDbConfigFor($name)
193193
*
194194
* @return array
195195
*/
196-
protected function createDbConnectionFor($name)
196+
protected static function createDbConnectionFor($name)
197197
{
198198
try {
199-
$conn = ResourceFactory::createResource($this->createDbConfigFor($name));
199+
$conn = ResourceFactory::createResource(static::createDbConfigFor($name));
200200
} catch (Exception $e) {
201201
$conn = $e->getMessage();
202202
}
@@ -211,29 +211,29 @@ protected function createDbConnectionFor($name)
211211
*
212212
* @return DbConnection
213213
*/
214-
public function mysqlDb()
214+
public static function mysqlDb()
215215
{
216-
return $this->createDbConnectionFor('mysql');
216+
return static::createDbConnectionFor('mysql');
217217
}
218218

219219
/**
220220
* PHPUnit provider for pgsql
221221
*
222222
* @return DbConnection
223223
*/
224-
public function pgsqlDb()
224+
public static function pgsqlDb()
225225
{
226-
return $this->createDbConnectionFor('pgsql');
226+
return static::createDbConnectionFor('pgsql');
227227
}
228228

229229
/**
230230
* PHPUnit provider for oracle
231231
*
232232
* @return DbConnection
233233
*/
234-
public function oracleDb()
234+
public static function oracleDb()
235235
{
236-
return $this->createDbConnectionFor('oracle');
236+
return static::createDbConnectionFor('oracle');
237237
}
238238

239239
/**
@@ -248,15 +248,15 @@ public function loadSql(DbConnection $resource, $filename)
248248
{
249249
if (!is_file($filename)) {
250250
throw new RuntimeException(
251-
'Sql file not found: ' . $filename . ' (test=' . $this->getName() . ')'
251+
'Sql file not found: ' . $filename . ' (test=' . $this->name() . ')'
252252
);
253253
}
254254

255255
$sqlData = file_get_contents($filename);
256256

257257
if (!$sqlData) {
258258
throw new RuntimeException(
259-
'Sql file is empty: ' . $filename . ' (test=' . $this->getName() . ')'
259+
'Sql file is empty: ' . $filename . ' (test=' . $this->name() . ')'
260260
);
261261
}
262262

library/Icinga/Test/DbTest.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,21 @@ interface DbTest
1212
*
1313
* @return DbConnection
1414
*/
15-
public function mysqlDb();
15+
public static function mysqlDb();
1616

1717
/**
1818
* PHPUnit provider for pgsql
1919
*
2020
* @return DbConnection
2121
*/
22-
public function pgsqlDb();
22+
public static function pgsqlDb();
2323

2424
/**
2525
* PHPUnit provider for oracle
2626
*
2727
* @return DbConnection
2828
*/
29-
public function oracleDb();
29+
public static function oracleDb();
3030

3131
/**
3232
* Executes sql file on PDO object

test/php/application/forms/Config/UserBackendReorderFormTest.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
use Icinga\Application\Config;
88
use Icinga\Forms\Config\UserBackendConfigForm;
99
use Icinga\Forms\Config\UserBackendReorderForm;
10-
use Icinga\Application\Icinga;
1110

1211
class UserBackendConfigFormWithoutSave extends UserBackendConfigForm
1312
{
@@ -30,7 +29,7 @@ public function getConfigForm()
3029
}
3130
}
3231

33-
class AuthenticationBackendReorderFormTest extends BaseTestCase
32+
class UserBackendReorderFormTest extends BaseTestCase
3433
{
3534
public function testMoveBackend()
3635
{

test/php/library/Icinga/File/Storage/LocalFileStorageTest.php

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,11 @@
1111

1212
class LocalFileStorageTest extends BaseTestCase
1313
{
14-
/**
15-
* @var int
16-
*/
17-
protected $oldErrorReportingLevel;
14+
protected static int $oldErrorReportingLevel;
1815

19-
public function __construct($name = null, array $data = array(), $dataName = '')
16+
public static function setUpBeforeClass(): void
2017
{
21-
parent::__construct($name, $data, $dataName);
22-
23-
$this->oldErrorReportingLevel = error_reporting();
18+
static::$oldErrorReportingLevel = error_reporting();
2419
error_reporting(E_ALL);
2520

2621
set_error_handler(function ($errno, $errstr, $errfile, $errline) {
@@ -40,9 +35,9 @@ public function __construct($name = null, array $data = array(), $dataName = '')
4035
});
4136
}
4237

43-
public function __destruct()
38+
public static function tearDownAfterClass(): void
4439
{
45-
error_reporting($this->oldErrorReportingLevel);
40+
error_reporting(static::$oldErrorReportingLevel);
4641
restore_error_handler();
4742
}
4843

test/php/library/Icinga/File/Storage/TemporaryLocalFileStorageTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ public function testDestructorRemovesFiles()
1919

2020
$storage = null;
2121

22-
$this->assertFileNotExists($fooPath);
23-
$this->assertFileNotExists($barPath);
22+
$this->assertFileDoesNotExist($fooPath);
23+
$this->assertFileDoesNotExist($barPath);
2424
}
2525

2626
public function testDestructorRemovesDirectories()
@@ -32,7 +32,7 @@ public function testDestructorRemovesDirectories()
3232

3333
$storage = null;
3434

35-
$this->assertDirectoryNotExists($dirPath);
35+
$this->assertDirectoryDoesNotExist($dirPath);
3636
}
3737

3838
public function testDestructorRemovesNestedDirectories()
@@ -46,6 +46,6 @@ public function testDestructorRemovesNestedDirectories()
4646

4747
$storage = null;
4848

49-
$this->assertDirectoryNotExists($aPath);
49+
$this->assertDirectoryDoesNotExist($aPath);
5050
}
5151
}

test/php/library/Icinga/Test/BaseTestCaseTest.php

Lines changed: 17 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
use Mockery;
77
use Icinga\Test\BaseTestCase;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use PHPUnit\Framework\Attributes\Depends;
810

911
class BaseTestCaseTest extends BaseTestCase
1012
{
@@ -19,27 +21,21 @@ public function tearDown(): void
1921
}
2022
}
2123

22-
/**
23-
* @dataProvider mysqlDb
24-
*/
24+
#[DataProvider('mysqlDb')]
2525
public function testWhetherMySqlProviderAnnotationSetsUpZendDbAdapter($resource)
2626
{
2727
$this->setupDbProvider($resource);
2828
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Mysql', $resource->getDbAdapter());
2929
}
3030

31-
/**
32-
* @dataProvider mysqlDb
33-
*/
31+
#[DataProvider('mysqlDb')]
3432
public function testWhetherMySqlAdapterWorks($resource)
3533
{
3634
$this->setupDbProvider($resource);
3735
$this->dbAdapterSqlLoadTable($resource);
3836
}
3937

40-
/**
41-
* @dataProvider mysqlDb
42-
*/
38+
#[DataProvider('mysqlDb')]
4339
public function testWhetherCreatingTablesWithMySqlAdapterWorks($resource)
4440
{
4541
$this->setupDbProvider($resource);
@@ -50,10 +46,8 @@ public function testWhetherCreatingTablesWithMySqlAdapterWorks($resource)
5046
$this->assertCount(1, $tables);
5147
}
5248

53-
/**
54-
* @dataProvider mysqlDb
55-
* @depends testWhetherCreatingTablesWithMySqlAdapterWorks
56-
*/
49+
#[DataProvider('mysqlDb')]
50+
#[Depends('testWhetherCreatingTablesWithMySqlAdapterWorks')]
5751
public function testWhetherSetupDbProviderCleansUpMySqlAdapter($resource)
5852
{
5953
$this->setupDbProvider($resource);
@@ -62,27 +56,21 @@ public function testWhetherSetupDbProviderCleansUpMySqlAdapter($resource)
6256
$this->assertCount(0, $tables);
6357
}
6458

65-
/**
66-
* @dataProvider pgsqlDb
67-
*/
59+
#[DataProvider('pgsqlDb')]
6860
public function testWhetherPgSqlProviderAnnotationSetsUpZendDbAdapter($resource)
6961
{
7062
$this->setupDbProvider($resource);
7163
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Pgsql', $resource->getDbAdapter());
7264
}
7365

74-
/**
75-
* @dataProvider pgsqlDb
76-
*/
66+
#[DataProvider('pgsqlDb')]
7767
public function testWhetherPgSqlAdapterWorks($resource)
7868
{
7969
$this->setupDbProvider($resource);
8070
$this->dbAdapterSqlLoadTable($resource);
8171
}
8272

83-
/**
84-
* @dataProvider pgsqlDb
85-
*/
73+
#[DataProvider('pgsqlDb')]
8674
public function testWhetherCreatingTablesWithPgSqlAdapterWorks($resource)
8775
{
8876
$this->setupDbProvider($resource);
@@ -93,10 +81,8 @@ public function testWhetherCreatingTablesWithPgSqlAdapterWorks($resource)
9381
$this->assertCount(1, $tables);
9482
}
9583

96-
/**
97-
* @dataProvider pgsqlDb
98-
* @depends testWhetherCreatingTablesWithPgSqlAdapterWorks
99-
*/
84+
#[DataProvider('pgsqlDb')]
85+
#[Depends('testWhetherCreatingTablesWithPgSqlAdapterWorks')]
10086
public function testWhetherSetupDbProviderCleansUpPgSqlAdapter($resource)
10187
{
10288
$this->setupDbProvider($resource);
@@ -105,27 +91,21 @@ public function testWhetherSetupDbProviderCleansUpPgSqlAdapter($resource)
10591
$this->assertCount(0, $tables);
10692
}
10793

108-
/**
109-
* @dataProvider oracleDb
110-
*/
94+
#[DataProvider('oracleDb')]
11195
public function testWhetherOciProviderAnnotationSetsUpZendDbAdapter($resource)
11296
{
11397
$this->setupDbProvider($resource);
11498
$this->assertInstanceOf('Zend_Db_Adapter_Pdo_Oci', $resource->getDbAdapter());
11599
}
116100

117-
/**
118-
* @dataProvider oracleDb
119-
*/
101+
#[DataProvider('oracleDb')]
120102
public function testWhetherOciAdapterWorks($resource)
121103
{
122104
$this->setupDbProvider($resource);
123105
$this->dbAdapterSqlLoadTable($resource);
124106
}
125107

126-
/**
127-
* @dataProvider oracleDb
128-
*/
108+
#[DataProvider('oracleDb')]
129109
public function testWhetherCreatingTablesWithOciAdapterWorks($resource)
130110
{
131111
$this->setupDbProvider($resource);
@@ -136,10 +116,8 @@ public function testWhetherCreatingTablesWithOciAdapterWorks($resource)
136116
$this->assertCount(1, $tables);
137117
}
138118

139-
/**
140-
* @dataProvider oracleDb
141-
* @depends testWhetherCreatingTablesWithOciAdapterWorks
142-
*/
119+
#[DataProvider('oracleDb')]
120+
#[Depends('testWhetherCreatingTablesWithOciAdapterWorks')]
143121
public function testWhetherSetupDbProviderCleansUpOciAdapter($resource)
144122
{
145123
$this->setupDbProvider($resource);

test/php/library/Icinga/User/PreferencesTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Icinga\User\Preferences;
77
use Icinga\Test\BaseTestCase;
88

9-
class PreferfencesTest extends BaseTestCase
9+
class PreferencesTest extends BaseTestCase
1010
{
1111
public function testWhetherPreferencesCanBeSet()
1212
{

test/php/library/Icinga/Util/StringHelperTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
use Icinga\Test\BaseTestCase;
77
use Icinga\Util\StringHelper;
88

9-
class StringTest extends BaseTestCase
9+
class StringHelperTest extends BaseTestCase
1010
{
1111
public function testWhetherTrimSplitReturnsACorrectValue()
1212
{

test/php/library/Icinga/Web/Session/PhpSessionTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ private function getSession()
1515
}
1616
return PhpSession::create(
1717
array(
18-
'use_cookies' => false,
1918
'save_path' => '/tmp',
2019
'test_session_name' => 'IcingawebUnittest'
2120
)

0 commit comments

Comments
 (0)