Skip to content

Commit b595368

Browse files
committed
Fix tests
1 parent c0d7db3 commit b595368

7 files changed

Lines changed: 58 additions & 24 deletions

File tree

phpunit.xml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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"
55
backupStaticAttributes="false"
66
colors="true"

tests/acp/acp_test.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424
use phpbb_mock_extension_manager;
2525
use phpbb_mock_lang;
2626
use phpbb_mock_user;
27-
use PHPUnit\DbUnit\DataSet\DefaultDataSet;
28-
use PHPUnit\DbUnit\DataSet\XmlDataSet;
2927
use PHPUnit\Framework\MockObject\MockObject;
3028
use RuntimeException;
3129
use Symfony\Component\DependencyInjection\ContainerInterface;
@@ -74,7 +72,7 @@ protected static function setup_extensions(): array
7472
return ['vse/abbc3'];
7573
}
7674

77-
public function getDataSet(): XmlDataSet|DefaultDataSet
75+
public function getDataSet()
7876
{
7977
return $this->createXMLDataSet(__DIR__ . '/../core/fixtures/config_text.xml');
8078
}

tests/core/acp_base.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
use phpbb_database_test_case;
2323
use phpbb_mock_event_dispatcher;
2424
use phpbb_mock_request;
25-
use PHPUnit\DbUnit\DataSet\DefaultDataSet;
26-
use PHPUnit\DbUnit\DataSet\XmlDataSet;
2725
use PHPUnit\Framework\MockObject\MockObject;
2826
use vse\abbc3\core\acp_manager;
2927
use phpbb\datetime;
@@ -52,7 +50,7 @@ protected static function setup_extensions(): array
5250
/** @var user */
5351
protected user $user;
5452

55-
public function getDataSet(): XmlDataSet|DefaultDataSet
53+
public function getDataSet()
5654
{
5755
return $this->createXMLDataSet(__DIR__ . '/fixtures/bbcodes.xml');
5856
}

tests/core/acp_bbcode_drag_drop_test.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace vse\abbc3\tests\core;
1212

1313
use phpbb\request\request_interface;
14+
use vse\abbc3\core\acp_manager;
1415

1516
class acp_bbcode_drag_drop_test extends acp_base
1617
{
@@ -43,11 +44,11 @@ public function test_bbcode_drag_drop($bbcodes)
4344
])
4445
;
4546

46-
// Handle trigger_error() output called from json_response
47-
$this->setExpectedTriggerError(E_WARNING);
47+
// Expect JSON output but prevent exit()
48+
$this->expectOutputString('{"success":true}');
4849

49-
// Get the acp_manager
50-
$acp_manager = $this->get_acp_manager();
50+
// Get the testable acp_manager
51+
$acp_manager = $this->get_testable_acp_manager();
5152

5253
// Call move_drag()
5354
$acp_manager->move_drag();
@@ -70,4 +71,17 @@ public function test_bbcode_drag_drop_fails()
7071
// Call move_drag()
7172
$acp_manager->move_drag();
7273
}
74+
75+
protected function get_testable_acp_manager(): acp_manager
76+
{
77+
return new class($this->db, $this->group_helper, $this->lang, $this->request) extends acp_manager {
78+
protected function send_json_response(bool $content): void
79+
{
80+
if ($this->request->is_ajax())
81+
{
82+
echo json_encode(['success' => (bool) $content]);
83+
}
84+
}
85+
};
86+
}
7387
}

tests/core/acp_bbcode_move_test.php

Lines changed: 26 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace vse\abbc3\tests\core;
1212

1313
use phpbb\request\request_interface;
14+
use vse\abbc3\core\acp_manager;
1415

1516
class acp_bbcode_move_test extends acp_base
1617
{
@@ -127,13 +128,33 @@ public function test_bbcode_move_triggers_error($item, $action, $hash, $ajax, $e
127128
])
128129
;
129130

130-
// Handle trigger_error() output
131-
$this->setExpectedTriggerError($errNo);
132-
133-
// Get the acp_manager
134-
$acp_manager = $this->get_acp_manager();
131+
if ($ajax)
132+
{
133+
// Expect JSON output for ajax requests
134+
$this->expectOutputString('{"success":true}');
135+
$acp_manager = $this->get_testable_acp_manager();
136+
}
137+
else
138+
{
139+
// Handle trigger_error() output for non-ajax
140+
$this->setExpectedTriggerError($errNo);
141+
$acp_manager = $this->get_acp_manager();
142+
}
135143

136144
// Call move()
137145
$acp_manager->move($action);
138146
}
147+
148+
protected function get_testable_acp_manager(): acp_manager
149+
{
150+
return new class($this->db, $this->group_helper, $this->lang, $this->request) extends acp_manager {
151+
protected function send_json_response(bool $content): void
152+
{
153+
if ($this->request->is_ajax())
154+
{
155+
echo json_encode(['success' => (bool) $content]);
156+
}
157+
}
158+
};
159+
}
139160
}

tests/core/bbcodes_test.php

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919
use phpbb\user;
2020
use phpbb_database_test_case;
2121
use phpbb_mock_extension_manager;
22-
use PHPUnit\DbUnit\DataSet\DefaultDataSet;
23-
use PHPUnit\DbUnit\DataSet\XmlDataSet;
2422
use PHPUnit\Framework\MockObject\MockObject;
2523
use phpbb\datetime;
2624
use s9e\TextFormatter\Parser;
@@ -50,7 +48,7 @@ protected static function setup_extensions(): array
5048
/** @var phpbb_mock_extension_manager */
5149
protected phpbb_mock_extension_manager $ext_manager;
5250

53-
public function getDataSet(): XmlDataSet|DefaultDataSet
51+
public function getDataSet()
5452
{
5553
return $this->createXMLDataSet(__DIR__ . '/fixtures/user_group.xml');
5654
}
@@ -353,12 +351,17 @@ public function test_set_renderer_params_caching()
353351
->method('get_renderer')
354352
->willReturn($s9e_renderer_mock);
355353

354+
$expectedCalls = [
355+
['param1' => 'value1', 'param2' => 'value2'],
356+
['param3' => 'value3']
357+
];
358+
$callIndex = 0;
356359
$s9e_renderer_mock->expects(self::exactly(2))
357360
->method('setParameters')
358-
->withConsecutive(
359-
[['param1' => 'value1', 'param2' => 'value2']],
360-
[['param3' => 'value3']]
361-
);
361+
->willReturnCallback(function($params) use (&$expectedCalls, &$callIndex) {
362+
self::assertEquals($expectedCalls[$callIndex], $params);
363+
$callIndex++;
364+
});
362365

363366
$bbcodes_manager = $this->bbcodes_manager();
364367

tests/core/faq_test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ protected static function setup_extensions(): array
4343
/** @var bbcodes_help */
4444
protected bbcodes_help $bbcodes_help;
4545

46-
public function getDataSet(): CompositeDataSet
46+
public function getDataSet()
4747
{
4848
// Aggregate multiple fixtures into a single dataset
4949
$ds1 = $this->createXMLDataSet(__DIR__ . '/fixtures/bbcodes.xml');

0 commit comments

Comments
 (0)