From 09e7956371d318cfe7b669ca6fd87b3141800cdb Mon Sep 17 00:00:00 2001 From: Matt Friedman Date: Sat, 28 Nov 2020 23:10:21 -0800 Subject: [PATCH] Update tests --- tests/core/similar_topics_test.php | 28 ++++++++++---------- tests/driver/driver_test.php | 26 +++++++++--------- tests/event/listener_test.php | 11 ++++---- tests/event/ucp_listener_test.php | 21 ++++++--------- tests/functional/create_forum_test.php | 2 +- tests/functional/similar_topics_acp_test.php | 2 +- tests/functional/similar_topics_base.php | 2 +- 7 files changed, 44 insertions(+), 48 deletions(-) diff --git a/tests/core/similar_topics_test.php b/tests/core/similar_topics_test.php index 0663f33..398d6b1 100644 --- a/tests/core/similar_topics_test.php +++ b/tests/core/similar_topics_test.php @@ -63,7 +63,7 @@ class similar_topics_test extends \phpbb_test_case /** @var string */ protected $phpEx; - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -305,19 +305,19 @@ public function test_is_available($config_data, $user_data, $auth_data, $sql_lay $this->config = new \phpbb\config\config($config_data); $this->user->data['user_similar_topics'] = $user_data['user_similar_topics']; $this->auth->method('acl_get') - ->with($this->stringContains('_'), $this->anything()) + ->with(self::stringContains('_'), self::anything()) ->willReturnMap(array($auth_data)); - $this->db->expects($this->atMost(2)) + $this->db->expects(self::atMost(2)) ->method('get_sql_layer') ->willReturn($sql_layer); - $this->manager->expects($this->once()) + $this->manager->expects(self::once()) ->method('get_driver') ->with($sql_layer) ->willReturn((in_array($sql_layer, array('mysqli', 'mysql4', 'postgres')) ? $this->driver : null)); $similar_topics = $this->get_similar_topics(); - $this->assertEquals($expected, $similar_topics->is_available()); + self::assertEquals($expected, $similar_topics->is_available()); } public function clean_topic_title_test_data() @@ -339,18 +339,18 @@ public function test_clean_topic_title($test_string, $ignore_words, $expected) $this->service->method('get_driver') ->willReturnCallback(array($this, 'set_cache')); - $this->config_text->expects($this->once()) + $this->config_text->expects(self::once()) ->method('get') ->with('similar_topics_words') ->willReturn($ignore_words); - $this->ext_manager->expects($this->once()) + $this->ext_manager->expects(self::once()) ->method('get_finder') ->willReturnCallback(array($this, 'get_finder')); $similar_topics = $this->get_similar_topics(); - $this->assertSame($expected, $similar_topics->clean_topic_title($test_string)); + self::assertSame($expected, $similar_topics->clean_topic_title($test_string)); } public function set_cache() @@ -368,22 +368,22 @@ public function get_finder() $finder = $this->getMockBuilder('\phpbb\finder') ->disableOriginalConstructor() ->getMock(); - $finder->expects($this->once()) + $finder->expects(self::once()) ->method('set_extensions') ->willReturnSelf(); - $finder->expects($this->once()) + $finder->expects(self::once()) ->method('prefix') ->willReturnSelf(); - $finder->expects($this->once()) + $finder->expects(self::once()) ->method('suffix') ->willReturnSelf(); - $finder->expects($this->once()) + $finder->expects(self::once()) ->method('extension_directory') ->willReturnSelf(); - $finder->expects($this->once()) + $finder->expects(self::once()) ->method('core_path') ->willReturnSelf(); - $finder->expects($this->once()) + $finder->expects(self::once()) ->method('get_files') ->willReturn(array()); diff --git a/tests/driver/driver_test.php b/tests/driver/driver_test.php index 18081be..db5b84e 100644 --- a/tests/driver/driver_test.php +++ b/tests/driver/driver_test.php @@ -26,12 +26,12 @@ protected static function setup_extensions() return array('vse/similartopics'); } - public function getDataSet() + protected function getDataSet() { return $this->createXMLDataSet(__DIR__ . '/fixtures/config.xml'); } - public function setUp(): void + protected function setUp(): void { parent::setUp(); @@ -66,22 +66,22 @@ public function get_driver() public function test_get_driver() { - $this->assertInstanceOf('\\vse\\similartopics\\driver\\' . $this->db->get_sql_layer(), $this->get_driver()); + self::assertInstanceOf('\\vse\\similartopics\\driver\\' . $this->db->get_sql_layer(), $this->get_driver()); } public function test_get_driver_fails() { - $this->assertNull($this->manager->get_driver('foo')); + self::assertNull($this->manager->get_driver('foo')); } public function test_get_name() { - $this->assertEquals($this->db->get_sql_layer(), $this->get_driver()->get_name()); + self::assertEquals($this->db->get_sql_layer(), $this->get_driver()->get_name()); } public function test_get_type() { - $this->assertSame(0, strpos($this->db->get_sql_layer(), $this->get_driver()->get_type())); + self::assertSame(0, strpos($this->db->get_sql_layer(), $this->get_driver()->get_type())); } public function test_get_query() @@ -99,10 +99,10 @@ public function test_get_query() $where = "MATCH (t.topic_title) AGAINST ('foo bar') >= 0 AND t.topic_status <> 2 AND t.topic_visibility = 1 AND t.topic_time > (UNIX_TIMESTAMP() - 0) AND t.topic_id <> 1"; } - $this->assertEquals($select, preg_replace('#\s\s+#', ' ', $sql['SELECT'])); - $this->assertArrayHasKey('FROM', $sql); - $this->assertArrayHasKey('LEFT_JOIN', $sql); - $this->assertEquals($where, preg_replace('#\s\s+#', ' ', $sql['WHERE'])); + self::assertEquals($select, preg_replace('#\s\s+#', ' ', $sql['SELECT'])); + self::assertArrayHasKey('FROM', $sql); + self::assertArrayHasKey('LEFT_JOIN', $sql); + self::assertEquals($where, preg_replace('#\s\s+#', ' ', $sql['WHERE'])); } public function test_is_supported() @@ -111,7 +111,7 @@ public function test_is_supported() $unsupported = $driver->get_engine() === 'innodb' && phpbb_version_compare($this->db->sql_server_info(true), '5.6.4', '<'); - $this->assertSame(!$unsupported, $this->get_driver()->is_supported()); + self::assertSame(!$unsupported, $this->get_driver()->is_supported()); } public function test_index() @@ -121,12 +121,12 @@ public function test_index() $column = 'topic_title'; // Check that the topic_title is NOT a fulltext index - $this->assertFalse($driver->is_fulltext($column)); + self::assertFalse($driver->is_fulltext($column)); // Make topic_title a fulltext index $driver->create_fulltext_index($column); // Now check that the topic_title is a fulltext index - $this->assertTrue($driver->is_fulltext($column)); + self::assertTrue($driver->is_fulltext($column)); } } diff --git a/tests/event/listener_test.php b/tests/event/listener_test.php index 59094d2..95d9d51 100644 --- a/tests/event/listener_test.php +++ b/tests/event/listener_test.php @@ -21,7 +21,7 @@ class listener_test extends \phpbb_test_case /** * Setup test environment */ - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -47,7 +47,7 @@ protected function set_listener() public function test_construct() { $this->set_listener(); - $this->assertInstanceOf('\Symfony\Component\EventDispatcher\EventSubscriberInterface', $this->listener); + self::assertInstanceOf('\Symfony\Component\EventDispatcher\EventSubscriberInterface', $this->listener); } /** @@ -55,7 +55,7 @@ public function test_construct() */ public function test_getSubscribedEvents() { - $this->assertEquals(array( + self::assertEquals(array( 'core.viewtopic_modify_page_title', 'core.permissions', ), array_keys(\vse\similartopics\event\listener::getSubscribedEvents())); @@ -81,11 +81,11 @@ public function display_similar_topics_data() */ public function test_display_similar_topics($topic_data, $is_available, $display) { - $this->similar_topics->expects($this->once()) + $this->similar_topics->expects(self::once()) ->method('is_available') ->willReturn($is_available); - $this->similar_topics->expects($is_available ? $this->once() : $this->never()) + $this->similar_topics->expects($is_available ? self::once() : self::never()) ->method('display_similar_topics') ->with($topic_data); @@ -94,6 +94,7 @@ public function test_display_similar_topics($topic_data, $is_available, $display $dispatcher = new \Symfony\Component\EventDispatcher\EventDispatcher(); $dispatcher->addListener('core.viewtopic_modify_page_title', array($this->listener, 'display_similar_topics')); + $forum_id = $topic_data['forum_id']; $event_data = array('forum_id', 'topic_data'); $event = new \phpbb\event\data(compact($event_data)); $dispatcher->dispatch('core.viewtopic_modify_page_title', $event); diff --git a/tests/event/ucp_listener_test.php b/tests/event/ucp_listener_test.php index 8fb045f..da27857 100644 --- a/tests/event/ucp_listener_test.php +++ b/tests/event/ucp_listener_test.php @@ -36,7 +36,7 @@ class ucp_listener_test extends \phpbb_test_case /** * Setup test environment */ - public function setUp() + protected function setUp(): void { parent::setUp(); @@ -75,7 +75,7 @@ protected function set_listener() public function test_construct() { $this->set_listener(); - $this->assertInstanceOf('\Symfony\Component\EventDispatcher\EventSubscriberInterface', $this->listener); + self::assertInstanceOf('\Symfony\Component\EventDispatcher\EventSubscriberInterface', $this->listener); } /** @@ -83,7 +83,7 @@ public function test_construct() */ public function test_getSubscribedEvents() { - $this->assertEquals(array( + self::assertEquals(array( 'core.ucp_prefs_view_data', 'core.ucp_prefs_view_update_data', ), array_keys(\vse\similartopics\event\ucp_listener::getSubscribedEvents())); @@ -97,11 +97,6 @@ public function test_getSubscribedEvents() public function ucp_prefs_set_data_data() { return array( - array( - array(), - array(), - array('user_similar_topics' => 0), - ), array( array('similar_topics' => 1), array(), @@ -149,7 +144,7 @@ public function test_ucp_prefs_set_data($data, $sql_ary, $expected) $event_data_after = $event->get_data_filtered($event_data); - $this->assertEquals($expected, $event_data_after['sql_ary']); + self::assertEquals($expected, $event_data_after['sql_ary']); } /** @@ -280,11 +275,11 @@ public function ucp_prefs_get_data_data() public function test_ucp_prefs_get_data($similar_topics, $submit, $u_similar_topics, $data, $expected) { $this->auth->method('acl_get') - ->with($this->stringContains('u_similar_topics'), $this->anything()) + ->with(self::stringContains('u_similar_topics'), self::anything()) ->willReturn($u_similar_topics); $this->user->data['user_similar_topics'] = 0; - $this->request->expects($this->once()) + $this->request->expects(self::once()) ->method('variable') ->willReturn($similar_topics); @@ -292,7 +287,7 @@ public function test_ucp_prefs_get_data($similar_topics, $submit, $u_similar_top if (!$submit) { - $this->template->expects($this->once()) + $this->template->expects(self::once()) ->method('assign_vars') ->with(array( 'S_SIMILAR_TOPICS' => $u_similar_topics, @@ -309,6 +304,6 @@ public function test_ucp_prefs_get_data($similar_topics, $submit, $u_similar_top $data = $event->get_data_filtered($event_data); - $this->assertEquals($expected, $data['data']); + self::assertEquals($expected, $data['data']); } } diff --git a/tests/functional/create_forum_test.php b/tests/functional/create_forum_test.php index 7e40480..5ee0ade 100644 --- a/tests/functional/create_forum_test.php +++ b/tests/functional/create_forum_test.php @@ -37,6 +37,6 @@ public function test_create_forum() )); $crawler = self::submit($form); - $this->assertGreaterThan(0, $crawler->filter('.successbox')->count()); + self::assertGreaterThan(0, $crawler->filter('.successbox')->count()); } } diff --git a/tests/functional/similar_topics_acp_test.php b/tests/functional/similar_topics_acp_test.php index ed7356e..83c66be 100644 --- a/tests/functional/similar_topics_acp_test.php +++ b/tests/functional/similar_topics_acp_test.php @@ -15,7 +15,7 @@ */ class similar_topics_acp_test extends similar_topics_base { - public function setUp(): void + protected function setUp(): void { parent::setUp(); diff --git a/tests/functional/similar_topics_base.php b/tests/functional/similar_topics_base.php index 34555bc..1afe00e 100644 --- a/tests/functional/similar_topics_base.php +++ b/tests/functional/similar_topics_base.php @@ -20,7 +20,7 @@ protected static function setup_extensions() return array('vse/similartopics'); } - public function setUp(): void + protected function setUp(): void { parent::setUp(); $this->enable_similar_topics();