Skip to content

Commit d71ac7f

Browse files
authored
Merge pull request #36 from iMattPro/fixes
Fix test deprecations
2 parents 7e3039b + b2f47b8 commit d71ac7f

7 files changed

Lines changed: 186 additions & 96 deletions

File tree

phpunit.xml.dist

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
3+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
44
backupGlobals="true"
5-
backupStaticAttributes="false"
65
colors="true"
7-
convertErrorsToExceptions="true"
8-
convertNoticesToExceptions="true"
9-
convertWarningsToExceptions="true"
106
processIsolation="false"
117
stopOnFailure="false"
128
cacheResult="false"
139
bootstrap="../../../../tests/bootstrap.php"
14-
>
15-
<coverage>
16-
<include>
17-
<directory suffix=".php">./</directory>
18-
</include>
19-
<exclude>
20-
<directory suffix=".php">./language/</directory>
21-
<directory suffix=".php">./migrations/</directory>
22-
<directory suffix=".php">./tests/</directory>
23-
</exclude>
24-
</coverage>
10+
backupStaticProperties="false">
2511
<testsuites>
2612
<testsuite name="Extension Test Suite">
2713
<directory suffix="_test.php">./tests</directory>
@@ -31,4 +17,16 @@
3117
<directory suffix="_test.php">./tests/functional/</directory>
3218
</testsuite>
3319
</testsuites>
20+
<source restrictDeprecations="true"
21+
restrictNotices="true"
22+
restrictWarnings="true">
23+
<include>
24+
<directory suffix=".php">./</directory>
25+
</include>
26+
<exclude>
27+
<directory suffix=".php">./language/</directory>
28+
<directory suffix=".php">./migrations/</directory>
29+
<directory suffix=".php">./tests/</directory>
30+
</exclude>
31+
</source>
3432
</phpunit>

tests/unit/acp_module_test.php

Lines changed: 53 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@ protected function setUp(): void
5757
$phpbb_dispatcher = new phpbb_mock_event_dispatcher();
5858
}
5959

60-
public function test_module_info()
60+
public function test_module_info(): void
6161
{
62-
self::assertEquals([
62+
$expected = [
6363
'\\phpbb\\pwakit\\acp\\pwa_acp_module' => [
6464
'filename' => '\\phpbb\\pwakit\\acp\\pwa_acp_module',
6565
'title' => 'ACP_PWA_KIT_TITLE',
@@ -71,10 +71,15 @@ public function test_module_info()
7171
],
7272
],
7373
],
74-
], $this->module_manager->get_module_infos('acp', 'pwa_acp_module'));
74+
];
75+
76+
$this->assertSame(
77+
$expected,
78+
$this->module_manager->get_module_infos('acp', 'pwa_acp_module')
79+
);
7580
}
7681

77-
public function module_auth_test_data(): array
82+
public static function module_auth_test_data(): array
7883
{
7984
return [
8085
'invalid auth' => ['ext_foo/bar', false],
@@ -85,12 +90,12 @@ public function module_auth_test_data(): array
8590
/**
8691
* @dataProvider module_auth_test_data
8792
*/
88-
public function test_module_auth($module_auth, $expected)
93+
public function test_module_auth(string $module_auth, bool $expected): void
8994
{
90-
self::assertEquals($expected, p_master::module_auth($module_auth, 0));
95+
$this->assertEquals($expected, p_master::module_auth($module_auth, 0));
9196
}
9297

93-
public function main_module_test_data(): array
98+
public static function main_module_test_data(): array
9499
{
95100
return [
96101
'valid mode' => ['settings'],
@@ -100,7 +105,7 @@ public function main_module_test_data(): array
100105
/**
101106
* @dataProvider main_module_test_data
102107
*/
103-
public function test_main_module($mode)
108+
public function test_main_module(string $mode): void
104109
{
105110
global $phpbb_container, $request, $template;
106111

@@ -123,18 +128,56 @@ public function test_main_module($mode)
123128
->getMock();
124129

125130
$phpbb_container
126-
->expects(self::once())
131+
->expects($this->once())
127132
->method('get')
128133
->with('phpbb.pwakit.admin.controller')
129134
->willReturn($admin_controller);
130135

131136
$admin_controller
132-
->expects(self::once())
137+
->expects($this->once())
133138
->method('main');
134139

135140
$p_master = new p_master();
136141
$p_master->module_ary[0]['is_duplicate'] = 0;
137142
$p_master->module_ary[0]['url_extra'] = '';
138143
$p_master->load('acp', pwa_acp_module::class, $mode);
139144
}
145+
146+
public function test_main_module_with_missing_controller(): void
147+
{
148+
global $phpbb_container, $template, $request;
149+
150+
$this->expectException(\RuntimeException::class);
151+
$this->expectExceptionMessage('Service not found: phpbb.pwakit.admin.controller');
152+
153+
if (!defined('IN_ADMIN')) {
154+
define('IN_ADMIN', true);
155+
}
156+
157+
// Set up template mock
158+
$template = $this->getMockBuilder(template::class)
159+
->disableOriginalConstructor()
160+
->getMock();
161+
162+
// Set up request mock
163+
$request = $this->getMockBuilder(request::class)
164+
->disableOriginalConstructor()
165+
->getMock();
166+
167+
// Set up container mock
168+
$phpbb_container = $this->getMockBuilder(ContainerInterface::class)
169+
->disableOriginalConstructor()
170+
->getMock();
171+
172+
$phpbb_container
173+
->expects($this->once())
174+
->method('get')
175+
->with('phpbb.pwakit.admin.controller')
176+
->willThrowException(new \RuntimeException('Service not found: phpbb.pwakit.admin.controller'));
177+
178+
$p_master = new p_master();
179+
$p_master->module_ary[0]['is_duplicate'] = 0;
180+
$p_master->module_ary[0]['url_extra'] = '';
181+
$p_master->load('acp', pwa_acp_module::class, 'settings');
182+
}
140183
}

tests/unit/admin_controller_test.php

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@
1414
use phpbb\db\driver\driver_interface as dbal;
1515
use phpbb_mock_cache;
1616
use phpbb_mock_event_dispatcher;
17-
use PHPUnit\DbUnit\DataSet\DefaultDataSet;
18-
use PHPUnit\DbUnit\DataSet\IDataSet;
19-
use PHPUnit\DbUnit\DataSet\XmlDataSet;
2017
use PHPUnit\Framework\MockObject\MockObject;
2118
use phpbb\config\config;
2219
use phpbb\exception\runtime_exception;
@@ -42,13 +39,14 @@ class admin_controller_test extends phpbb_database_test_case
4239
protected helper $helper;
4340
protected upload $upload;
4441
protected string $phpbb_root_path;
42+
protected admin_controller $admin_controller;
4543

4644
protected static function setup_extensions(): array
4745
{
4846
return ['phpbb/pwakit'];
4947
}
5048

51-
protected function getDataSet(): IDataSet|XmlDataSet|DefaultDataSet
49+
protected function getDataSet()
5250
{
5351
return $this->createXMLDataSet(__DIR__ . '/../fixtures/styles.xml');
5452
}
@@ -112,7 +110,7 @@ protected function setUp(): void
112110
);
113111
}
114112

115-
public function module_access_test_data(): array
113+
public static function module_access_test_data(): array
116114
{
117115
return [
118116
'correct mode' => ['settings', true],
@@ -135,7 +133,7 @@ public function test_module_access($mode, $expected)
135133
$this->call_admin_controller($mode);
136134
}
137135

138-
public function form_checks_data(): array
136+
public static function form_checks_data(): array
139137
{
140138
return [
141139
'submit test' => ['submit'],
@@ -159,7 +157,7 @@ public function test_form_checks($action)
159157
$this->call_admin_controller();
160158
}
161159

162-
public function display_settings_test_data(): array
160+
public static function display_settings_test_data(): array
163161
{
164162
return [
165163
'site name and short name' => [
@@ -260,7 +258,7 @@ public function test_display_settings($configs, $expected)
260258
$this->call_admin_controller();
261259
}
262260

263-
public function submit_test_data(): array
261+
public static function submit_test_data(): array
264262
{
265263
return [
266264
'all good inputs' => [
@@ -443,7 +441,7 @@ public function test_resync()
443441
$this->call_admin_controller();
444442
}
445443

446-
public function delete_test_data(): array
444+
public static function delete_test_data(): array
447445
{
448446
return [
449447
'not confirmed' => [

0 commit comments

Comments
 (0)