Skip to content

Commit f131e31

Browse files
committed
[ticket/17543] Optimize installing extensions
Make several functions static to be able to use in *BeforeClass() methods. PHPBB-17543
1 parent b51f8bc commit f131e31

17 files changed

Lines changed: 176 additions & 254 deletions

tests/functional/acp_permissions_test.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,7 @@ public function test_change_permission($description, $permission_type, $permissi
9898
// XXX globals for \phpbb\auth\auth, refactor it later
9999
global $db, $cache;
100100
$db = $this->get_db();
101+
101102
$cache = new phpbb_mock_null_cache;
102103

103104
$auth = new \phpbb\auth\auth;

tests/functional/download_test.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,6 @@ public function test_download_softdeleted_topic()
225225

226226
public function load_ids($data)
227227
{
228-
$this->db = $this->get_db();
229-
230228
if (!empty($data['forums']))
231229
{
232230
array_walk($data['forums'], function(&$value, $key)

tests/functional/extension_controller_test.php

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -22,44 +22,33 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c
2222
'./',
2323
);
2424

25-
static public function setUpBeforeClass(): void
25+
public static function setUpBeforeClass(): void
2626
{
2727
parent::setUpBeforeClass();
2828

2929
self::$helper = new phpbb_test_case_helpers(__CLASS__);
3030
self::$helper->copy_ext_fixtures(__DIR__ . '/fixtures/ext/', self::$fixtures);
31+
32+
self::install_ext('foo/bar');
33+
self::install_ext('foo/foo');
3134
}
3235

33-
static public function tearDownAfterClass(): void
36+
public static function tearDownAfterClass(): void
3437
{
3538
parent::tearDownAfterClass();
3639

40+
self::uninstall_ext('foo/bar');
41+
self::uninstall_ext('foo/foo');
3742
self::$helper->restore_original_ext_dir();
3843
}
3944

40-
protected static function setup_extensions()
41-
{
42-
return self::$tests_count == self::$tests_number ? ['foo/bar', 'foo/foo'] : [];
43-
}
44-
4545
protected function setUp(): void
4646
{
4747
parent::setUp();
4848

4949
$this->purge_cache();
5050
}
5151

52-
protected function tearDown(): void
53-
{
54-
if (self::$tests_count == 1)
55-
{
56-
$this->uninstall_ext('foo/bar');
57-
$this->uninstall_ext('foo/foo');
58-
}
59-
60-
parent::tearDown();
61-
}
62-
6352
/**
6453
* Check a controller for extension foo/bar.
6554
*/

tests/functional/extension_module_test.php

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -23,36 +23,24 @@ class phpbb_functional_extension_module_test extends phpbb_functional_test_case
2323
'./',
2424
);
2525

26-
static public function setUpBeforeClass(): void
26+
public static function setUpBeforeClass(): void
2727
{
2828
parent::setUpBeforeClass();
2929

3030
self::$helper = new phpbb_test_case_helpers(__CLASS__);
3131
self::$helper->copy_ext_fixtures(__DIR__ . '/fixtures/ext/', self::$fixtures);
32+
33+
self::install_ext('foo/bar');
3234
}
3335

34-
static public function tearDownAfterClass(): void
36+
public static function tearDownAfterClass(): void
3537
{
3638
parent::tearDownAfterClass();
3739

40+
self::uninstall_ext('foo/bar');
3841
self::$helper->restore_original_ext_dir();
3942
}
4043

41-
protected function tearDown(): void
42-
{
43-
if (self::$tests_count == 1)
44-
{
45-
$this->uninstall_ext('foo/bar');
46-
}
47-
48-
parent::tearDown();
49-
}
50-
51-
protected static function setup_extensions()
52-
{
53-
return self::$tests_count == self::$tests_number ? ['foo/bar'] : [];
54-
}
55-
5644
public function test_acp()
5745
{
5846
$this->add_lang('common');

tests/functional/extension_template_event_order_test.php

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,29 @@
1616
*/
1717
class phpbb_functional_extension_template_event_order_test extends phpbb_functional_test_case
1818
{
19-
static private $helper;
19+
private static $helper;
2020

21-
static protected $fixtures = [
21+
protected static $fixtures = [
2222
'./',
2323
];
2424

25-
static public function setUpBeforeClass(): void
25+
public static function setUpBeforeClass(): void
2626
{
2727
parent::setUpBeforeClass();
2828

2929
self::$helper = new phpbb_test_case_helpers(__CLASS__);
3030
self::$helper->copy_ext_fixtures(__DIR__ . '/fixtures/ext/', self::$fixtures);
31+
32+
self::install_ext('foo/bar');
33+
self::install_ext('foo/foo');
3134
}
3235

33-
static public function tearDownAfterClass(): void
36+
public static function tearDownAfterClass(): void
3437
{
3538
parent::tearDownAfterClass();
3639

40+
self::uninstall_ext('foo/bar');
41+
self::uninstall_ext('foo/foo');
3742
self::$helper->restore_original_ext_dir();
3843
}
3944

@@ -44,21 +49,6 @@ protected function setUp(): void
4449
$this->purge_cache();
4550
}
4651

47-
protected function tearDown(): void
48-
{
49-
if (self::$tests_count == 1)
50-
{
51-
$this->uninstall_ext('foo/bar');
52-
$this->uninstall_ext('foo/foo');
53-
}
54-
55-
parent::tearDown();
56-
}
57-
58-
protected static function setup_extensions()
59-
{
60-
return self::$tests_count == self::$tests_number ? ['foo/bar', 'foo/foo'] : [];
61-
}
6252

6353
/**
6454
* Check extensions template event listener prioritizing

tests/functional/feed_test.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1450,8 +1450,6 @@ protected function assert_feed($params, $data)
14501450

14511451
protected function load_ids($data)
14521452
{
1453-
$this->db = $this->get_db();
1454-
14551453
if (!empty($data['forums']))
14561454
{
14571455
$sql = 'SELECT *

tests/functional/metadata_manager_test.php

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,21 @@ class phpbb_functional_metadata_manager_test extends phpbb_functional_test_case
2222
'./',
2323
);
2424

25-
protected function tearDown(): void
26-
{
27-
if (self::$tests_count == 1)
28-
{
29-
$this->uninstall_ext('foo/bar');
30-
}
31-
32-
parent::tearDown();
33-
}
34-
3525
public static function setUpBeforeClass(): void
3626
{
3727
parent::setUpBeforeClass();
3828

3929
self::$helper = new phpbb_test_case_helpers(__CLASS__);
4030
self::$helper->copy_ext_fixtures(__DIR__ . '/fixtures/ext/', self::$fixtures);
31+
32+
self::install_ext('foo/bar');
4133
}
4234

4335
public static function tearDownAfterClass(): void
4436
{
4537
parent::tearDownAfterClass();
4638

39+
self::uninstall_ext('foo/bar');
4740
self::$helper->restore_original_ext_dir();
4841
}
4942

@@ -56,11 +49,6 @@ protected function setUp(): void
5649
$this->add_lang('acp/extensions');
5750
}
5851

59-
protected static function setup_extensions()
60-
{
61-
return self::$tests_count == self::$tests_number ? ['foo/bar'] : [];
62-
}
63-
6452
public function test_extensions_list()
6553
{
6654
$crawler = self::request('GET', 'adm/index.php?i=acp_extensions&mode=main&sid=' . $this->sid);

tests/functional/prune_shadow_topic_test.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,6 @@ public function test_move_topic()
121121
'forum_topics_softdeleted' => 0,
122122
), 'after moving');
123123

124-
$this->db = $this->get_db();
125124
// Date topic 3 days back
126125
$sql = 'UPDATE phpbb_topics
127126
SET topic_last_post_time = ' . (time() - 60*60*24*3) . '
@@ -153,8 +152,6 @@ public function test_move_topic()
153152

154153
public function assert_forum_details($forum_id, $details, $additional_error_message = '')
155154
{
156-
$this->db = $this->get_db();
157-
158155
$sql = 'SELECT ' . implode(', ', array_keys($details)) . '
159156
FROM phpbb_forums
160157
WHERE forum_id = ' . (int) $forum_id;
@@ -167,8 +164,6 @@ public function assert_forum_details($forum_id, $details, $additional_error_mess
167164

168165
public function load_ids($data)
169166
{
170-
$this->db = $this->get_db();
171-
172167
if (!empty($data['forums']))
173168
{
174169
$sql = 'SELECT *

tests/functional/subforum_test.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public function test_display_subforums_limit()
9191

9292
protected function get_forum_id($forum_name)
9393
{
94-
$this->db = $this->get_db();
9594
$forum_id = 0;
9695

9796
$sql = 'SELECT *

tests/functional/ucp_groups_test.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,19 +18,13 @@
1818
*/
1919
class phpbb_functional_ucp_groups_test extends phpbb_functional_common_groups_test_case
2020
{
21-
protected $db;
22-
2321
protected function get_url()
2422
{
2523
return 'ucp.php?i=groups&mode=manage&action=edit';
2624
}
2725

2826
protected function get_teampage_settings()
2927
{
30-
if (!isset($this->db))
31-
{
32-
$this->db = $this->get_db();
33-
}
3428
$sql = 'SELECT g.group_legend AS group_legend, t.teampage_position AS group_teampage
3529
FROM ' . GROUPS_TABLE . ' g
3630
LEFT JOIN ' . TEAMPAGE_TABLE . ' t

0 commit comments

Comments
 (0)