From cef8aaf1a49957b6991f1933fb921c1b69695e33 Mon Sep 17 00:00:00 2001 From: Marc Alexander Date: Sat, 19 Aug 2023 13:04:25 +0200 Subject: [PATCH] [ticket/17176] Update implementations to be compatible with Symfony 6.3 PHPBB3-17176 --- phpBB/phpbb/controller/resolver.php | 4 ++-- phpBB/phpbb/di/extension/config.php | 2 +- phpBB/phpbb/di/extension/core.php | 2 +- phpBB/phpbb/di/extension/tables.php | 2 +- phpBB/phpbb/exception/http_exception.php | 8 ++++---- phpBB/phpbb/extension/di/extension_base.php | 2 +- phpBB/phpbb/routing/loader_resolver.php | 2 +- phpBB/phpbb/routing/router.php | 6 +++--- tests/console/cron/cron_list_test.php | 3 ++- tests/console/cron/run_test.php | 9 ++++++--- tests/cron/manager_test.php | 3 ++- tests/functional/acp_smilies_test.php | 2 +- tests/functional/extension_controller_test.php | 1 + tests/functional/ucp_attachments_test.php | 10 +++++----- tests/mock/container_builder.php | 14 +++++++------- tests/path_helper/path_helper_test.php | 4 ++-- 16 files changed, 40 insertions(+), 34 deletions(-) diff --git a/phpBB/phpbb/controller/resolver.php b/phpBB/phpbb/controller/resolver.php index 1e65b2324b..087c1e89b9 100644 --- a/phpBB/phpbb/controller/resolver.php +++ b/phpBB/phpbb/controller/resolver.php @@ -65,10 +65,10 @@ class resolver implements ControllerResolverInterface * Load a controller callable * * @param Request $request Symfony Request object - * @return false|Callable Callable or false (fixme: method is returning an array) + * @return callable|false Callable or false * @throws \phpbb\controller\exception */ - public function getController(Request $request) + public function getController(Request $request): callable|false { $controller = $request->attributes->get('_controller'); diff --git a/phpBB/phpbb/di/extension/config.php b/phpBB/phpbb/di/extension/config.php index 775de380ec..2b73a4871a 100644 --- a/phpBB/phpbb/di/extension/config.php +++ b/phpBB/phpbb/di/extension/config.php @@ -60,7 +60,7 @@ class config extends Extension * * @return string The alias */ - public function getAlias() + public function getAlias(): string { return 'config'; } diff --git a/phpBB/phpbb/di/extension/core.php b/phpBB/phpbb/di/extension/core.php index c0725942be..41b510ba2b 100644 --- a/phpBB/phpbb/di/extension/core.php +++ b/phpBB/phpbb/di/extension/core.php @@ -144,7 +144,7 @@ class core extends Extension * * @return string The alias */ - public function getAlias() + public function getAlias(): string { return 'core'; } diff --git a/phpBB/phpbb/di/extension/tables.php b/phpBB/phpbb/di/extension/tables.php index 40684b6038..fc3d9e75c6 100644 --- a/phpBB/phpbb/di/extension/tables.php +++ b/phpBB/phpbb/di/extension/tables.php @@ -52,7 +52,7 @@ class tables extends Extension * * @return string The alias */ - public function getAlias() + public function getAlias(): string { return 'tables'; } diff --git a/phpBB/phpbb/exception/http_exception.php b/phpBB/phpbb/exception/http_exception.php index cae4a282d4..f22c90128e 100644 --- a/phpBB/phpbb/exception/http_exception.php +++ b/phpBB/phpbb/exception/http_exception.php @@ -25,14 +25,14 @@ class http_exception extends runtime_exception implements HttpExceptionInterface * * @var integer */ - private $status_code; + private int $status_code; /** * Additional headers to set in the response. * * @var array */ - private $headers; + private array $headers; /** * Constructor @@ -55,7 +55,7 @@ class http_exception extends runtime_exception implements HttpExceptionInterface /** * {@inheritdoc} */ - public function getStatusCode() + public function getStatusCode(): int { return $this->status_code; } @@ -63,7 +63,7 @@ class http_exception extends runtime_exception implements HttpExceptionInterface /** * {@inheritdoc} */ - public function getHeaders() + public function getHeaders(): array { return $this->headers; } diff --git a/phpBB/phpbb/extension/di/extension_base.php b/phpBB/phpbb/extension/di/extension_base.php index fcc358dd79..45ed5c4c19 100644 --- a/phpBB/phpbb/extension/di/extension_base.php +++ b/phpBB/phpbb/extension/di/extension_base.php @@ -132,7 +132,7 @@ class extension_base extends Extension * * @return string The alias */ - public function getAlias() + public function getAlias(): string { return str_replace('/', '_', $this->extension_name); } diff --git a/phpBB/phpbb/routing/loader_resolver.php b/phpBB/phpbb/routing/loader_resolver.php index 13fbc6405c..de3adcaa34 100644 --- a/phpBB/phpbb/routing/loader_resolver.php +++ b/phpBB/phpbb/routing/loader_resolver.php @@ -33,7 +33,7 @@ class loader_resolver implements LoaderResolverInterface /** * {@inheritdoc} */ - public function resolve($resource, $type = null) + public function resolve($resource, $type = null): false|\Symfony\Component\Config\Loader\LoaderInterface { /** @var \Symfony\Component\Config\Loader\LoaderInterface $loader */ foreach ($this->loaders as $loader) diff --git a/phpBB/phpbb/routing/router.php b/phpBB/phpbb/routing/router.php index e6f887cca7..18d32ca12b 100644 --- a/phpBB/phpbb/routing/router.php +++ b/phpBB/phpbb/routing/router.php @@ -171,7 +171,7 @@ class router implements RouterInterface /** * {@inheritdoc} */ - public function getContext() + public function getContext(): RequestContext { return $this->context; } @@ -179,7 +179,7 @@ class router implements RouterInterface /** * {@inheritdoc} */ - public function generate($name, $parameters = array(), $referenceType = self::ABSOLUTE_PATH) + public function generate(string $name, array $parameters = [], int $referenceType = self::ABSOLUTE_PATH): string { return $this->get_generator()->generate($name, $parameters, $referenceType); } @@ -187,7 +187,7 @@ class router implements RouterInterface /** * {@inheritdoc} */ - public function match($pathinfo) + public function match(string $pathinfo): array { return $this->get_matcher()->match($pathinfo); } diff --git a/tests/console/cron/cron_list_test.php b/tests/console/cron/cron_list_test.php index 0c1b8b1ccc..cdda4fb886 100644 --- a/tests/console/cron/cron_list_test.php +++ b/tests/console/cron/cron_list_test.php @@ -97,7 +97,8 @@ class phpbb_console_command_cron_list_test extends phpbb_test_case ); $mock_container = new phpbb_mock_container_builder(); - $mock_container->set('cron.task_collection', []); + $task_collection = new \phpbb\di\service_collection($mock_container); + $mock_container->set('cron.task_collection', $task_collection); $this->cron_manager = new \phpbb\cron\manager($mock_container, $routing_helper, $phpbb_root_path, $pathEx, null); $this->cron_manager->load_tasks($tasks); diff --git a/tests/console/cron/run_test.php b/tests/console/cron/run_test.php index 7de1b3455e..90fa2a9fd0 100644 --- a/tests/console/cron/run_test.php +++ b/tests/console/cron/run_test.php @@ -74,7 +74,8 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case ); $mock_container = new phpbb_mock_container_builder(); - $mock_container->set('cron.task_collection', []); + $task_collection = new \phpbb\di\service_collection($mock_container); + $mock_container->set('cron.task_collection', $task_collection); $this->cron_manager = new \phpbb\cron\manager($mock_container, $routing_helper, $phpbb_root_path, $phpEx, null); $this->cron_manager->load_tasks($tasks); @@ -152,7 +153,8 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case ); $mock_container = new phpbb_mock_container_builder(); - $mock_container->set('cron.task_collection', []); + $task_collection = new \phpbb\di\service_collection($mock_container); + $mock_container->set('cron.task_collection', $task_collection); $this->cron_manager = new \phpbb\cron\manager($mock_container, $routing_helper, $phpbb_root_path, $phpEx, null); $this->cron_manager->load_tasks($tasks); @@ -199,7 +201,8 @@ class phpbb_console_command_cron_run_test extends phpbb_database_test_case ); $mock_container = new phpbb_mock_container_builder(); - $mock_container->set('cron.task_collection', []); + $task_collection = new \phpbb\di\service_collection($mock_container); + $mock_container->set('cron.task_collection', $task_collection); $this->cron_manager = new \phpbb\cron\manager($mock_container, $routing_helper, $phpbb_root_path, $phpEx, null); $this->cron_manager->load_tasks($tasks); diff --git a/tests/cron/manager_test.php b/tests/cron/manager_test.php index 658980d0c5..45736e82fe 100644 --- a/tests/cron/manager_test.php +++ b/tests/cron/manager_test.php @@ -105,7 +105,8 @@ class phpbb_cron_manager_test extends \phpbb_test_case ); $mock_container = new phpbb_mock_container_builder(); - $mock_container->set('cron.task_collection', []); + $task_collection = new \phpbb\di\service_collection($mock_container); + $mock_container->set('cron.task_collection', $task_collection); $cron_manager = new \phpbb\cron\manager($mock_container, $routing_helper, $phpbb_root_path, $phpEx, null); $cron_manager->load_tasks($tasks); diff --git a/tests/functional/acp_smilies_test.php b/tests/functional/acp_smilies_test.php index ebe8717fa7..c24b884dd0 100644 --- a/tests/functional/acp_smilies_test.php +++ b/tests/functional/acp_smilies_test.php @@ -38,6 +38,6 @@ class phpbb_functional_acp_smilies_test extends phpbb_functional_test_case $crawler = self::submit($form); $html = $crawler->filter('#preview')->html(); - $this->assertRegexp('(]+ alt=">:D" title=">:D"[^>]*>)', $html); + $this->assertRegexp('(]+ alt=">:D" title=">:D"[^>]*>)', $html); } } diff --git a/tests/functional/extension_controller_test.php b/tests/functional/extension_controller_test.php index c235278d9d..b4518cfa23 100644 --- a/tests/functional/extension_controller_test.php +++ b/tests/functional/extension_controller_test.php @@ -106,6 +106,7 @@ class phpbb_functional_extension_controller_test extends phpbb_functional_test_c $crawler = self::request('GET', 'app.php/foo/baz', array(), false); $this->assert_response_html(500); $this->assertStringContainsString('Controller "foo\bar\controller\controller::baz()" requires that you provide a value for the "$test" argument', $crawler->filter('body')->text()); + $this->phpbb_extension_manager->purge('foo/bar'); } /** diff --git a/tests/functional/ucp_attachments_test.php b/tests/functional/ucp_attachments_test.php index dad085498d..fbd352ea28 100644 --- a/tests/functional/ucp_attachments_test.php +++ b/tests/functional/ucp_attachments_test.php @@ -134,7 +134,7 @@ class phpbb_functional_ucp_attachments_test extends phpbb_functional_test_case $attachment_filename = $crawler->filter('.attachment-filename'); $this->assertEquals('valid.jpg', $attachment_filename->attr('title')); $this->assertStringContainsString('app.php/download/attachment/' . $attach_id . '/valid.jpg', $attachment_filename->attr('href')); - $this->assertEquals('', $crawler->filter('[name="attachment[' . $attach_id . ']"]')->attr('disabled')); + $this->assertFalse($crawler->filter('[name="attachment[' . $attach_id . ']"]')->getNode(0)->hasAttribute('disabled')); } public function test_ucp_delete_expired_attachment() @@ -219,7 +219,7 @@ class phpbb_functional_ucp_attachments_test extends phpbb_functional_test_case $this->assertEquals('valid.jpg', $attachment_node->attr('title')); $this->assertStringContainsString('download/attachment/' . $attach_id . '/valid.jpg', $attachment_node->attr('href')); - $this->assertEquals('disabled', $crawler->filter('[name="attachment[' . $attach_id . ']"]')->attr('disabled')); + $this->assertTrue($crawler->filter('[name="attachment[' . $attach_id . ']"]')->getNode(0)->hasAttribute('disabled')); // It should not be possible to delete the attachment $crawler = self::request('POST', 'ucp.php?i=ucp_attachments&mode=attachments&sid=' . $this->sid, [ @@ -238,7 +238,7 @@ class phpbb_functional_ucp_attachments_test extends phpbb_functional_test_case }); $this->assertEquals('valid.jpg', $attachment_node->attr('title')); $this->assertStringContainsString('download/attachment/' . $attach_id . '/valid.jpg', $attachment_node->attr('href')); - $this->assertEquals('disabled', $crawler->filter('[name="attachment[' . $attach_id . ']"]')->attr('disabled')); + $this->assertTrue($crawler->filter('[name="attachment[' . $attach_id . ']"]')->getNode(0)->hasAttribute('disabled')); $this->logout(); @@ -327,7 +327,7 @@ class phpbb_functional_ucp_attachments_test extends phpbb_functional_test_case $this->assertEquals('valid.jpg', $attachment_node->attr('title')); $this->assertStringContainsString('download/attachment/' . $attach_id . '/valid.jpg', $attachment_node->attr('href')); - $this->assertEquals('', $crawler->filter('[name="attachment[' . $attach_id . ']"]')->attr('disabled')); + $this->assertFalse($crawler->filter('[name="attachment[' . $attach_id . ']"]')->getNode(0)->hasAttribute('disabled')); // Update message time to 60 minutes later $sql = 'UPDATE ' . PRIVMSGS_TABLE . ' @@ -347,7 +347,7 @@ class phpbb_functional_ucp_attachments_test extends phpbb_functional_test_case $this->assertEquals('valid.jpg', $attachment_node->attr('title')); $this->assertStringContainsString('download/attachment/' . $attach_id . '/valid.jpg', $attachment_node->attr('href')); - $this->assertEquals('disabled', $crawler->filter('[name="attachment[' . $attach_id . ']"]')->attr('disabled')); + $this->assertTrue($crawler->filter('[name="attachment[' . $attach_id . ']"]')->getNode(0)->hasAttribute('disabled')); $this->set_flood_interval(15); diff --git a/tests/mock/container_builder.php b/tests/mock/container_builder.php index 29050825db..9200ed0767 100644 --- a/tests/mock/container_builder.php +++ b/tests/mock/container_builder.php @@ -56,7 +56,7 @@ class phpbb_mock_container_builder implements ContainerInterface * * @api */ - public function get($id, $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE) + public function get(string $id, int $invalidBehavior = self::EXCEPTION_ON_INVALID_REFERENCE): ?object { if ($this->has($id)) { @@ -79,11 +79,11 @@ class phpbb_mock_container_builder implements ContainerInterface * * @param string $id The service identifier * - * @return Boolean true if the service is defined, false otherwise + * @return bool true if the service is defined, false otherwise * * @api */ - public function has($id) + public function has(string $id): bool { return isset($this->services[$id]); } @@ -99,7 +99,7 @@ class phpbb_mock_container_builder implements ContainerInterface * * @api */ - public function getParameter($name) + public function getParameter(string $name): mixed { if ($this->hasParameter($name)) { @@ -114,11 +114,11 @@ class phpbb_mock_container_builder implements ContainerInterface * * @param string $name The parameter name * - * @return Boolean The presence of parameter in container + * @return bool The presence of parameter in container * * @api */ - public function hasParameter($name) + public function hasParameter(string $name): bool { return isset($this->parameters[$name]); } @@ -202,7 +202,7 @@ class phpbb_mock_container_builder implements ContainerInterface return false; } - public function initialized($id) + public function initialized($id): bool { return true; } diff --git a/tests/path_helper/path_helper_test.php b/tests/path_helper/path_helper_test.php index 73d235e0cd..a2abefb108 100644 --- a/tests/path_helper/path_helper_test.php +++ b/tests/path_helper/path_helper_test.php @@ -127,8 +127,8 @@ class phpbb_path_helper_test extends phpbb_test_case array( $this->phpbb_root_path . 'test.php', '/', - null, - null, + '', + '', '', ), array(