Skip to content

Commit

Permalink
Clean up trigger error tests
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Friedman <[email protected]>
  • Loading branch information
iMattPro committed Jan 18, 2024
1 parent c0b90e9 commit c1abae3
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 35 deletions.
6 changes: 1 addition & 5 deletions tests/controller/add_prefix_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,11 +53,7 @@ public function test_add_prefix($prefix, $submit, $valid_form)

if (!$valid_form)
{
// Throws E_WARNING in PHP 8.0+ and E_USER_WARNING in earlier versions
$exceptionName = version_compare(PHP_VERSION, '8.0', '<') ? \PHPUnit\Framework\Error\Error::class : \PHPUnit\Framework\Error\Warning::class;
$errno = version_compare(PHP_VERSION, '8.0', '<') ? E_USER_WARNING : E_WARNING;
$this->expectException($exceptionName);
$this->expectExceptionCode($errno);
$this->setExpectedTriggerError(E_USER_WARNING, $this->language->lang('FORM_INVALID'));
}
else
{
Expand Down
12 changes: 2 additions & 10 deletions tests/controller/delete_prefix_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,7 @@ public function test_delete_prefix($prefix_id, $confirm)
->will(self::throwException(new \OutOfBoundsException()));
$this->log->expects(self::never())
->method('add');
// Throws E_WARNING in PHP 8.0+ and E_USER_WARNING in earlier versions
$exceptionName = PHP_VERSION_ID < 80000 ? \PHPUnit\Framework\Error\Error::class : \PHPUnit\Framework\Error\Warning::class;
$errno = PHP_VERSION_ID < 80000 ? E_USER_WARNING : E_WARNING;
$this->expectException($exceptionName);
$this->expectExceptionCode($errno);
$this->setExpectedTriggerError(E_USER_WARNING);
}
else
{
Expand All @@ -83,11 +79,7 @@ public function test_delete_prefix($prefix_id, $confirm)
$this->db->expects(static::once())
->method('sql_fetchrow')
->willReturn(['forum_name' => 'Test Forum']);
// Throws E_WARNING in PHP 8.0+ and E_USER_WARNING in earlier versions
$exceptionName = PHP_VERSION_ID < 80000 ? \PHPUnit\Framework\Error\Error::class : \PHPUnit\Framework\Error\Warning::class;
$errno = PHP_VERSION_ID < 80000 ? E_USER_NOTICE : E_WARNING;
$this->expectException($exceptionName);
$this->expectExceptionCode($errno);
$this->setExpectedTriggerError(E_USER_NOTICE, $this->language->lang('TOPIC_PREFIX_DELETED'));
}

$this->controller->delete_prefix($prefix_id);
Expand Down
12 changes: 2 additions & 10 deletions tests/controller/edit_prefix_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,7 @@ public function test_edit_prefix($prefix_id, $valid_form, $is_ajax)
->method('get_prefix');
$this->manager->expects(self::never())
->method('update_prefix');
// Throws E_WARNING in PHP 8.0+ and E_USER_WARNING in earlier versions
$exceptionName = PHP_VERSION_ID < 80000 ? \PHPUnit\Framework\Error\Error::class : \PHPUnit\Framework\Error\Warning::class;
$errno = PHP_VERSION_ID < 80000 ? E_USER_WARNING : E_WARNING;
$this->expectException($exceptionName);
$this->expectExceptionCode($errno);
$this->setExpectedTriggerError(E_USER_WARNING, $this->language->lang('FORM_INVALID'));
}
else if ($prefix_id === 0)
{
Expand All @@ -70,11 +66,7 @@ public function test_edit_prefix($prefix_id, $valid_form, $is_ajax)
$this->manager->expects(self::once())
->method('update_prefix')
->will(self::throwException(new \OutOfBoundsException));
// Throws E_WARNING in PHP 8.0+ and E_USER_WARNING in earlier versions
$exceptionName = PHP_VERSION_ID < 80000 ? \PHPUnit\Framework\Error\Error::class : \PHPUnit\Framework\Error\Warning::class;
$errno = PHP_VERSION_ID < 80000 ? E_USER_WARNING : E_WARNING;
$this->expectException($exceptionName);
$this->expectExceptionCode($errno);
$this->setExpectedTriggerError(E_USER_WARNING);
}
else
{
Expand Down
12 changes: 2 additions & 10 deletions tests/controller/move_prefix_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,21 +58,13 @@ public function test_move_prefix($prefix_id, $direction, $valid_form, $is_ajax)
if (!$valid_form)
{
$prefix_id = 0;
// Throws E_WARNING in PHP 8.0+ and E_USER_WARNING in earlier versions
$exceptionName = PHP_VERSION_ID < 80000 ? \PHPUnit\Framework\Error\Error::class : \PHPUnit\Framework\Error\Warning::class;
$errno = PHP_VERSION_ID < 80000 ? E_USER_WARNING : E_WARNING;
$this->expectException($exceptionName);
$this->expectExceptionCode($errno);
$this->setExpectedTriggerError(E_USER_WARNING, $this->language->lang('FORM_INVALID'));
$this->manager->expects(static::never())
->method('move_prefix');
}
else if ($prefix_id === 0)
{
// Throws E_WARNING in PHP 8.0+ and E_USER_WARNING in earlier versions
$exceptionName = PHP_VERSION_ID < 80000 ? \PHPUnit\Framework\Error\Error::class : \PHPUnit\Framework\Error\Warning::class;
$errno = PHP_VERSION_ID < 80000 ? E_USER_WARNING : E_WARNING;
$this->expectException($exceptionName);
$this->expectExceptionCode($errno);
$this->setExpectedTriggerError(E_USER_WARNING);
$this->manager->expects(static::once())
->method('move_prefix')
->with(static::equalTo(0), static::stringContains($direction))
Expand Down

0 comments on commit c1abae3

Please sign in to comment.