Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iMattPro committed Nov 29, 2020
1 parent ed447f5 commit 09e7956
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 48 deletions.
28 changes: 14 additions & 14 deletions tests/core/similar_topics_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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());

Expand Down
26 changes: 13 additions & 13 deletions tests/driver/driver_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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));
}
}
11 changes: 6 additions & 5 deletions tests/event/listener_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class listener_test extends \phpbb_test_case
/**
* Setup test environment
*/
public function setUp()
protected function setUp(): void
{
parent::setUp();

Expand All @@ -47,15 +47,15 @@ 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);
}

/**
* Test the event listener is subscribing events
*/
public function test_getSubscribedEvents()
{
$this->assertEquals(array(
self::assertEquals(array(
'core.viewtopic_modify_page_title',
'core.permissions',
), array_keys(\vse\similartopics\event\listener::getSubscribedEvents()));
Expand All @@ -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);

Expand All @@ -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);
Expand Down
21 changes: 8 additions & 13 deletions tests/event/ucp_listener_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class ucp_listener_test extends \phpbb_test_case
/**
* Setup test environment
*/
public function setUp()
protected function setUp(): void
{
parent::setUp();

Expand Down Expand Up @@ -75,15 +75,15 @@ 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);
}

/**
* Test the event listener is subscribing events
*/
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()));
Expand All @@ -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(),
Expand Down Expand Up @@ -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']);
}

/**
Expand Down Expand Up @@ -280,19 +275,19 @@ 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);

$this->set_listener();

if (!$submit)
{
$this->template->expects($this->once())
$this->template->expects(self::once())
->method('assign_vars')
->with(array(
'S_SIMILAR_TOPICS' => $u_similar_topics,
Expand All @@ -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']);
}
}
2 changes: 1 addition & 1 deletion tests/functional/create_forum_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
2 changes: 1 addition & 1 deletion tests/functional/similar_topics_acp_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/
class similar_topics_acp_test extends similar_topics_base
{
public function setUp(): void
protected function setUp(): void
{
parent::setUp();

Expand Down
2 changes: 1 addition & 1 deletion tests/functional/similar_topics_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down

0 comments on commit 09e7956

Please sign in to comment.