Skip to content

Commit

Permalink
Revert "Clean up trigger error tests"
Browse files Browse the repository at this point in the history
This reverts commit c1abae3.
  • Loading branch information
iMattPro committed Jan 18, 2024
1 parent 8083ffd commit a747b17
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 7 deletions.
6 changes: 5 additions & 1 deletion tests/controller/add_prefix_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ public function test_add_prefix($prefix, $submit, $valid_form)

if (!$valid_form)
{
$this->setExpectedTriggerError(E_USER_WARNING, 'The submitted form was invalid. Try submitting again.');
// 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);
}
else
{
Expand Down
12 changes: 10 additions & 2 deletions tests/controller/delete_prefix_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,11 @@ public function test_delete_prefix($prefix_id, $confirm)
->will(self::throwException(new \OutOfBoundsException()));
$this->log->expects(self::never())
->method('add');
$this->setExpectedTriggerError(E_USER_WARNING);
// 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);
}
else
{
Expand All @@ -79,7 +83,11 @@ public function test_delete_prefix($prefix_id, $confirm)
$this->db->expects(static::once())
->method('sql_fetchrow')
->willReturn(['forum_name' => 'Test Forum']);
$this->setExpectedTriggerError(E_USER_NOTICE, 'TOPIC_PREFIX_DELETED');
// 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->controller->delete_prefix($prefix_id);
Expand Down
12 changes: 10 additions & 2 deletions tests/controller/edit_prefix_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ public function test_edit_prefix($prefix_id, $valid_form, $is_ajax)
->method('get_prefix');
$this->manager->expects(self::never())
->method('update_prefix');
$this->setExpectedTriggerError(E_USER_WARNING, 'The submitted form was invalid. Try submitting again.');
// 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);
}
else if ($prefix_id === 0)
{
Expand All @@ -66,7 +70,11 @@ public function test_edit_prefix($prefix_id, $valid_form, $is_ajax)
$this->manager->expects(self::once())
->method('update_prefix')
->will(self::throwException(new \OutOfBoundsException));
$this->setExpectedTriggerError(E_USER_WARNING);
// 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);
}
else
{
Expand Down
12 changes: 10 additions & 2 deletions tests/controller/move_prefix_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,21 @@ public function test_move_prefix($prefix_id, $direction, $valid_form, $is_ajax)
if (!$valid_form)
{
$prefix_id = 0;
$this->setExpectedTriggerError(E_USER_WARNING, 'The submitted form was invalid. Try submitting again.');
// 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->manager->expects(static::never())
->method('move_prefix');
}
else if ($prefix_id === 0)
{
$this->setExpectedTriggerError(E_USER_WARNING);
// 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->manager->expects(static::once())
->method('move_prefix')
->with(static::equalTo(0), static::stringContains($direction))
Expand Down

0 comments on commit a747b17

Please sign in to comment.