diff --git a/system/Database/Exceptions/DatabaseException.php b/system/Database/Exceptions/DatabaseException.php index a2b3b7637ce7..13f58dc12954 100644 --- a/system/Database/Exceptions/DatabaseException.php +++ b/system/Database/Exceptions/DatabaseException.php @@ -20,5 +20,5 @@ class DatabaseException extends Error implements ExceptionInterface * * @var int */ - protected $code = 8; + protected $code = EXIT_DATABASE; } diff --git a/system/Entity/Exceptions/CastException.php b/system/Entity/Exceptions/CastException.php index 2cda4d72238d..224bbdc7eb68 100644 --- a/system/Entity/Exceptions/CastException.php +++ b/system/Entity/Exceptions/CastException.php @@ -15,6 +15,10 @@ /** * CastException is thrown for invalid cast initialization and management. + * + * @TODO CodeIgniter\Exceptions\CastException is deprecated and this class is used. + * CodeIgniter\Exceptions\CastException has the property $code = EXIT_CONFIG, + * but this class does not have the code. */ class CastException extends FrameworkException { diff --git a/system/Exceptions/CastException.php b/system/Exceptions/CastException.php index 5e41631536c7..06511f73907f 100644 --- a/system/Exceptions/CastException.php +++ b/system/Exceptions/CastException.php @@ -23,11 +23,11 @@ class CastException extends CriticalError use DebugTraceableTrait; /** - * Error code + * Exit status code * * @var int */ - protected $code = 3; + protected $code = EXIT_CONFIG; public static function forInvalidJsonFormatException(int $error) { diff --git a/system/Exceptions/ConfigException.php b/system/Exceptions/ConfigException.php index 41ae4959e594..ced8afc6e04f 100644 --- a/system/Exceptions/ConfigException.php +++ b/system/Exceptions/ConfigException.php @@ -19,11 +19,11 @@ class ConfigException extends CriticalError use DebugTraceableTrait; /** - * Error code + * Exit status code * * @var int */ - protected $code = 3; + protected $code = EXIT_CONFIG; public static function forDisabledMigrations() { diff --git a/system/Exceptions/PageNotFoundException.php b/system/Exceptions/PageNotFoundException.php index 2a773f1785dc..531df0e48f11 100644 --- a/system/Exceptions/PageNotFoundException.php +++ b/system/Exceptions/PageNotFoundException.php @@ -19,7 +19,7 @@ class PageNotFoundException extends OutOfBoundsException implements ExceptionInt use DebugTraceableTrait; /** - * Error code + * HTTP status code * * @var int */ diff --git a/system/Router/Exceptions/RedirectException.php b/system/Router/Exceptions/RedirectException.php index b2456f367676..d5a1616b481b 100644 --- a/system/Router/Exceptions/RedirectException.php +++ b/system/Router/Exceptions/RedirectException.php @@ -19,7 +19,7 @@ class RedirectException extends Exception { /** - * Status code for redirects + * HTTP status code for redirects * * @var int */ diff --git a/tests/system/Debug/ExceptionsTest.php b/tests/system/Debug/ExceptionsTest.php index 8bd4f01e0925..3ef643c831e3 100644 --- a/tests/system/Debug/ExceptionsTest.php +++ b/tests/system/Debug/ExceptionsTest.php @@ -11,6 +11,9 @@ namespace CodeIgniter\Debug; +use CodeIgniter\Database\Exceptions\DatabaseException; +use CodeIgniter\Entity\Exceptions\CastException; +use CodeIgniter\Exceptions\ConfigException; use CodeIgniter\Exceptions\PageNotFoundException; use CodeIgniter\Test\CIUnitTestCase; use CodeIgniter\Test\ReflectionHelper; @@ -57,9 +60,16 @@ public function testDetermineCodes(): void { $determineCodes = $this->getPrivateMethodInvoker($this->exception, 'determineCodes'); - $this->assertSame([500, 9], $determineCodes(new RuntimeException('This.'))); - $this->assertSame([500, 1], $determineCodes(new RuntimeException('That.', 600))); - $this->assertSame([404, 1], $determineCodes(new RuntimeException('There.', 404))); + $this->assertSame([500, EXIT__AUTO_MIN], $determineCodes(new RuntimeException('This.'))); + $this->assertSame([500, EXIT_ERROR], $determineCodes(new RuntimeException('That.', 600))); + $this->assertSame([404, EXIT_ERROR], $determineCodes(new RuntimeException('There.', 404))); + $this->assertSame([167, EXIT_ERROR], $determineCodes(new RuntimeException('This.', 167))); + // @TODO This exit code should be EXIT_CONFIG. + $this->assertSame([500, 12], $determineCodes(new ConfigException('This.'))); + // @TODO This exit code should be EXIT_CONFIG. + $this->assertSame([500, 9], $determineCodes(new CastException('This.'))); + // @TODO This exit code should be EXIT_DATABASE. + $this->assertSame([500, 17], $determineCodes(new DatabaseException('This.'))); } public function testRenderBacktrace(): void