diff --git a/src/Auth/Enums/AuthKeys.php b/src/Auth/Enums/AuthKeys.php index 475b1a6c5..b59d6d47e 100644 --- a/src/Auth/Enums/AuthKeys.php +++ b/src/Auth/Enums/AuthKeys.php @@ -19,8 +19,9 @@ /** * Class AuthKeys * @package Quantum\Auth + * @codeCoverageIgnore */ -class AuthKeys +final class AuthKeys { /** * One time password key @@ -71,4 +72,8 @@ class AuthKeys * Remember token key */ public const REMEMBER_TOKEN = 'rememberToken'; + + private function __construct() + { + } } diff --git a/src/Cache/Exceptions/CacheException.php b/src/Cache/Exceptions/CacheException.php index 934e9c0c4..1ec164fc6 100644 --- a/src/Cache/Exceptions/CacheException.php +++ b/src/Cache/Exceptions/CacheException.php @@ -21,6 +21,7 @@ /** * Class CacheException * @package Quantum\Cache + * @codeCoverageIgnore */ class CacheException extends BaseException { diff --git a/src/Captcha/Exceptions/CaptchaException.php b/src/Captcha/Exceptions/CaptchaException.php index a4c4d5be4..52b0e0e79 100644 --- a/src/Captcha/Exceptions/CaptchaException.php +++ b/src/Captcha/Exceptions/CaptchaException.php @@ -19,8 +19,9 @@ use Quantum\App\Exceptions\BaseException; /** - * Class CacheException + * Class CaptchaException * @package Quantum\Captcha + * @codeCoverageIgnore */ class CaptchaException extends BaseException { diff --git a/src/Cron/Enums/ExceptionMessages.php b/src/Cron/Enums/ExceptionMessages.php index ddb430b17..3c4e69a4b 100644 --- a/src/Cron/Enums/ExceptionMessages.php +++ b/src/Cron/Enums/ExceptionMessages.php @@ -19,6 +19,7 @@ /** * Enum ExceptionMessages * @package Quantum\Cron + * @codeCoverageIgnore */ final class ExceptionMessages { @@ -29,4 +30,8 @@ final class ExceptionMessages public const INVALID_TASK_FILE = 'Invalid task file "%s": must return array or CronTask instance'; public const CRON_DIRECTORY_NOT_FOUND = 'Cron directory not found: %s'; public const LOCK_DIRECTORY_NOT_WRITABLE = 'Lock directory is not writable: %s'; + + private function __construct() + { + } } diff --git a/src/Database/Enums/Key.php b/src/Database/Enums/Key.php index c947c6e3a..8d3d9c236 100644 --- a/src/Database/Enums/Key.php +++ b/src/Database/Enums/Key.php @@ -19,8 +19,9 @@ /** * Class Key * @package Quantum\Database + * @codeCoverageIgnore */ -class Key +final class Key { /** * Primary key definition @@ -47,4 +48,7 @@ class Key */ public const SPATIAL = 'spatial'; + private function __construct() + { + } } diff --git a/src/Database/Enums/Relation.php b/src/Database/Enums/Relation.php index 278e65175..77c7e978d 100644 --- a/src/Database/Enums/Relation.php +++ b/src/Database/Enums/Relation.php @@ -19,11 +19,16 @@ /** * Class Relation * @package Quantum\Database + * @codeCoverageIgnore */ -class Relation +final class Relation { public const HAS_ONE = 'hasOne'; public const HAS_MANY = 'hasMany'; public const BELONGS_TO = 'belongsTo'; public const BELONGS_TO_MANY = 'belongsToMany'; + + private function __construct() + { + } } diff --git a/src/Database/Enums/Type.php b/src/Database/Enums/Type.php index 824412be8..be1b2b0f9 100644 --- a/src/Database/Enums/Type.php +++ b/src/Database/Enums/Type.php @@ -19,8 +19,9 @@ /** * Class Type * @package Quantum\Database + * @codeCoverageIgnore */ -class Type +final class Type { /** * Type integer @@ -107,4 +108,7 @@ class Type */ public const GEOMETRY = 'geometry'; + private function __construct() + { + } } diff --git a/src/Environment/Enums/Env.php b/src/Environment/Enums/Env.php index 27ea62e16..9d926ff22 100644 --- a/src/Environment/Enums/Env.php +++ b/src/Environment/Enums/Env.php @@ -19,6 +19,7 @@ /** * Class Env * @package Quantum\Environment + * @codeCoverageIgnore */ final class Env { @@ -46,4 +47,8 @@ final class Env * Local environment - developer's local machine environment. */ public const LOCAL = 'local'; + + private function __construct() + { + } } diff --git a/src/Http/Enums/ContentType.php b/src/Http/Enums/ContentType.php index 193b5d781..3c0677c40 100644 --- a/src/Http/Enums/ContentType.php +++ b/src/Http/Enums/ContentType.php @@ -19,6 +19,7 @@ /** * Class ContentType * @package Quantum\Http + * @codeCoverageIgnore */ final class ContentType { @@ -56,4 +57,8 @@ final class ContentType * Default content type for binary streams */ public const OCTET_STREAM = 'application/octet-stream'; + + private function __construct() + { + } } diff --git a/src/Http/Enums/StatusCode.php b/src/Http/Enums/StatusCode.php index bd679159a..b33c9d695 100644 --- a/src/Http/Enums/StatusCode.php +++ b/src/Http/Enums/StatusCode.php @@ -19,6 +19,7 @@ /** * Class StatusCode * @package Quantum\Http + * @codeCoverageIgnore */ final class StatusCode { @@ -88,4 +89,8 @@ final class StatusCode public const LOOP_DETECTED = 508; public const NOT_EXTENDED = 510; public const NETWORK_AUTHENTICATION_REQUIRED = 511; + + private function __construct() + { + } } diff --git a/src/Http/Exceptions/HttpException.php b/src/Http/Exceptions/HttpException.php index 284e41a36..e6e786b65 100644 --- a/src/Http/Exceptions/HttpException.php +++ b/src/Http/Exceptions/HttpException.php @@ -21,6 +21,7 @@ /** * Class HttpException * @package Quantum\Http + * @codeCoverageIgnore */ class HttpException extends BaseException { diff --git a/src/Loader/Exceptions/LoaderException.php b/src/Loader/Exceptions/LoaderException.php index cf5cdf06a..8c4e5298d 100644 --- a/src/Loader/Exceptions/LoaderException.php +++ b/src/Loader/Exceptions/LoaderException.php @@ -23,6 +23,7 @@ * * @package Quantum * @category Exceptions + * @codeCoverageIgnore */ class LoaderException extends BaseException { diff --git a/src/Mailer/Exceptions/MailerException.php b/src/Mailer/Exceptions/MailerException.php index ba1aa54c9..841783d5b 100644 --- a/src/Mailer/Exceptions/MailerException.php +++ b/src/Mailer/Exceptions/MailerException.php @@ -21,6 +21,7 @@ /** * Class MailerException * @package Quantum\Mailer + * @codeCoverageIgnore */ class MailerException extends BaseException { diff --git a/src/Paginator/Enums/Pagination.php b/src/Paginator/Enums/Pagination.php index f6c2b1695..cade4d5e4 100644 --- a/src/Paginator/Enums/Pagination.php +++ b/src/Paginator/Enums/Pagination.php @@ -19,8 +19,9 @@ /** * Class Pagination * @package Quantum\Paginator + * @codeCoverageIgnore */ -class Pagination +final class Pagination { /** * Pagination class name @@ -56,4 +57,8 @@ class Pagination * Edge padding */ public const EDGE_PADDING = 3; + + private function __construct() + { + } } diff --git a/src/Renderer/Exceptions/RendererException.php b/src/Renderer/Exceptions/RendererException.php index 49f2cc9f1..96198225f 100644 --- a/src/Renderer/Exceptions/RendererException.php +++ b/src/Renderer/Exceptions/RendererException.php @@ -21,6 +21,7 @@ /** * Class RendererException * @package Quantum\Renderer + * @codeCoverageIgnore */ class RendererException extends BaseException { diff --git a/src/ResourceCache/Exceptions/ResourceCacheException.php b/src/ResourceCache/Exceptions/ResourceCacheException.php index 946bb9460..45943b508 100644 --- a/src/ResourceCache/Exceptions/ResourceCacheException.php +++ b/src/ResourceCache/Exceptions/ResourceCacheException.php @@ -21,6 +21,7 @@ /** * Class ResourceCacheException * @package Quantum\ResourceCache + * @codeCoverageIgnore */ class ResourceCacheException extends BaseException { diff --git a/src/Service/Exceptions/ServiceException.php b/src/Service/Exceptions/ServiceException.php index ffc5b2cbf..cb6dcc1bc 100644 --- a/src/Service/Exceptions/ServiceException.php +++ b/src/Service/Exceptions/ServiceException.php @@ -21,6 +21,7 @@ /** * Class ServiceException * @package Quantum\Service + * @codeCoverageIgnore */ class ServiceException extends BaseException { diff --git a/tests/Unit/App/Exceptions/AppExceptionTest.php b/tests/Unit/App/Exceptions/AppExceptionTest.php new file mode 100644 index 000000000..f5c78f5d3 --- /dev/null +++ b/tests/Unit/App/Exceptions/AppExceptionTest.php @@ -0,0 +1,18 @@ +assertInstanceOf(AppException::class, $exception); + $this->assertSame('APP KEY is missing.', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } +} diff --git a/tests/Unit/App/Exceptions/BaseExceptionTest.php b/tests/Unit/App/Exceptions/BaseExceptionTest.php new file mode 100644 index 000000000..d627b37a7 --- /dev/null +++ b/tests/Unit/App/Exceptions/BaseExceptionTest.php @@ -0,0 +1,61 @@ +assertInstanceOf(BaseExceptionStub::class, $exception); + $this->assertSame('The method `foo` is not supported for `Bar`.', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } + + public function testAdapterAndDriverFactories(): void + { + $adapterException = BaseExceptionStub::adapterNotSupported('x'); + $driverException = BaseExceptionStub::driverNotSupported('y'); + + $this->assertSame('The adapter `x` is not supported.', $adapterException->getMessage()); + $this->assertSame(E_ERROR, $adapterException->getCode()); + $this->assertSame('The driver `y` is not supported.', $driverException->getMessage()); + $this->assertSame(E_ERROR, $driverException->getCode()); + } + + public function testLookupAndConnectionFactories(): void + { + $fileException = BaseExceptionStub::fileNotFound('a.php'); + $notFoundException = BaseExceptionStub::notFound('Route', 'home'); + $instanceException = BaseExceptionStub::notInstanceOf('Foo', 'Bar'); + $connectException = BaseExceptionStub::cantConnect('redis'); + + $this->assertSame('The file `a.php` not found.', $fileException->getMessage()); + $this->assertSame(E_ERROR, $fileException->getCode()); + $this->assertSame('Route `home` not found.', $notFoundException->getMessage()); + $this->assertSame(E_ERROR, $notFoundException->getCode()); + $this->assertSame('The `Foo` is not instance of `Bar`.', $instanceException->getMessage()); + $this->assertSame(E_ERROR, $instanceException->getCode()); + $this->assertSame('Can not connect to `redis`.', $connectException->getMessage()); + $this->assertSame(E_ERROR, $connectException->getCode()); + } + + public function testConfigAndRequestMethodFactories(): void + { + $configException = BaseExceptionStub::missingConfig('database'); + $methodException = BaseExceptionStub::requestMethodNotAvailable('PATCH'); + + $this->assertSame('Could not load config `database` properly.', $configException->getMessage()); + $this->assertSame(E_ERROR, $configException->getCode()); + $this->assertSame('Provided request method `PATCH` is not available.', $methodException->getMessage()); + $this->assertSame(E_WARNING, $methodException->getCode()); + } +} diff --git a/tests/Unit/Archive/Exceptions/ArchiveExceptionTest.php b/tests/Unit/Archive/Exceptions/ArchiveExceptionTest.php new file mode 100644 index 000000000..a954e54fc --- /dev/null +++ b/tests/Unit/Archive/Exceptions/ArchiveExceptionTest.php @@ -0,0 +1,27 @@ +assertInstanceOf(ArchiveException::class, $exception); + $this->assertSame('The archive `demo.zip` can not be opened', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } + + public function testMissingArchiveName(): void + { + $exception = ArchiveException::missingArchiveName(); + + $this->assertInstanceOf(ArchiveException::class, $exception); + $this->assertSame('Archive name is not set', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } +} diff --git a/tests/Unit/Asset/Exceptions/AssetExceptionTest.php b/tests/Unit/Asset/Exceptions/AssetExceptionTest.php new file mode 100644 index 000000000..b311778aa --- /dev/null +++ b/tests/Unit/Asset/Exceptions/AssetExceptionTest.php @@ -0,0 +1,27 @@ +assertInstanceOf(AssetException::class, $exception); + $this->assertSame('Position `7` for asset `styles.css` is in use', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } + + public function testNameInUse(): void + { + $exception = AssetException::nameInUse('main-style'); + + $this->assertInstanceOf(AssetException::class, $exception); + $this->assertSame('The name main-style is in use', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } +} diff --git a/tests/Unit/Auth/Exceptions/AuthExceptionTest.php b/tests/Unit/Auth/Exceptions/AuthExceptionTest.php new file mode 100644 index 000000000..fc073e981 --- /dev/null +++ b/tests/Unit/Auth/Exceptions/AuthExceptionTest.php @@ -0,0 +1,44 @@ +assertSame('Incorrect credentials.', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } + + public function testInactiveAccount(): void + { + $exception = AuthException::inactiveAccount(); + $this->assertSame('The account is not activated.', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } + + public function testIncorrectVerificationCode(): void + { + $exception = AuthException::incorrectVerificationCode(); + $this->assertSame('Incorrect verification code.', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } + + public function testVerificationCodeExpired(): void + { + $exception = AuthException::verificationCodeExpired(); + $this->assertSame('Verification code expired.', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } + + public function testIncorrectUserSchema(): void + { + $exception = AuthException::incorrectUserSchema(); + $this->assertSame('User schema does not contains all key fields.', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } +} diff --git a/tests/Unit/Config/Exceptions/ConfigExceptionTest.php b/tests/Unit/Config/Exceptions/ConfigExceptionTest.php new file mode 100644 index 000000000..fd7e89f32 --- /dev/null +++ b/tests/Unit/Config/Exceptions/ConfigExceptionTest.php @@ -0,0 +1,18 @@ +assertInstanceOf(ConfigException::class, $exception); + $this->assertSame('Config key `database` is already in use', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } +} diff --git a/tests/Unit/Csrf/Exceptions/CsrfExceptionTest.php b/tests/Unit/Csrf/Exceptions/CsrfExceptionTest.php new file mode 100644 index 000000000..b8fa24d66 --- /dev/null +++ b/tests/Unit/Csrf/Exceptions/CsrfExceptionTest.php @@ -0,0 +1,27 @@ +assertInstanceOf(CsrfException::class, $exception); + $this->assertSame('CSRF Token is missing', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } + + public function testTokenNotMatched(): void + { + $exception = CsrfException::tokenNotMatched(); + + $this->assertInstanceOf(CsrfException::class, $exception); + $this->assertSame('CSRF Token does not matched', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } +} diff --git a/tests/Unit/Database/Exceptions/DatabaseExceptionTest.php b/tests/Unit/Database/Exceptions/DatabaseExceptionTest.php new file mode 100644 index 000000000..af7dc5d99 --- /dev/null +++ b/tests/Unit/Database/Exceptions/DatabaseExceptionTest.php @@ -0,0 +1,45 @@ +assertInstanceOf(DatabaseException::class, $exception); + $this->assertSame('The structure of config is not correct', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } + + public function testOperatorNotSupported(): void + { + $exception = DatabaseException::operatorNotSupported('foo'); + + $this->assertInstanceOf(DatabaseException::class, $exception); + $this->assertSame('The operator `foo` is not supported', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } + + public function testTableAlreadyExists(): void + { + $exception = DatabaseException::tableAlreadyExists('users'); + + $this->assertInstanceOf(DatabaseException::class, $exception); + $this->assertSame('The table `users` is already exists', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } + + public function testTableDoesNotExists(): void + { + $exception = DatabaseException::tableDoesNotExists('users'); + + $this->assertInstanceOf(DatabaseException::class, $exception); + $this->assertSame('The table `users` does not exists', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } +} diff --git a/tests/Unit/Di/Exceptions/DiExceptionTest.php b/tests/Unit/Di/Exceptions/DiExceptionTest.php new file mode 100644 index 000000000..e2533d881 --- /dev/null +++ b/tests/Unit/Di/Exceptions/DiExceptionTest.php @@ -0,0 +1,51 @@ +assertSame('The dependency `Foo` is not registered.', $notRegistered->getMessage()); + $this->assertSame('The dependency `Bar` is already registered.', $alreadyRegistered->getMessage()); + $this->assertSame('The dependency `Baz` is not instantiable.', $notInstantiable->getMessage()); + $this->assertSame(E_ERROR, $notRegistered->getCode()); + $this->assertSame(E_ERROR, $alreadyRegistered->getCode()); + $this->assertSame(E_ERROR, $notInstantiable->getCode()); + } + + public function testAbstractAndCircularFactories(): void + { + $invalidAbstract = DiException::invalidAbstractDependency('Qux'); + $circular = DiException::circularDependency('A -> B -> A'); + + $this->assertSame('The dependency `Qux` is not valid abstract class.', $invalidAbstract->getMessage()); + $this->assertSame('Circular dependency detected: `A -> B -> A`', $circular->getMessage()); + $this->assertSame(E_ERROR, $invalidAbstract->getCode()); + $this->assertSame(E_ERROR, $circular->getCode()); + } + + public function testInvalidCallableFactory(): void + { + $withEntry = DiException::invalidCallable('foo'); + $withoutEntry = DiException::invalidCallable(); + + $this->assertSame( + 'Invalid callable provided: expected Closure or array-style callable `foo`', + $withEntry->getMessage() + ); + $this->assertSame( + 'Invalid callable provided: expected Closure or array-style callable ``', + $withoutEntry->getMessage() + ); + $this->assertSame(E_ERROR, $withEntry->getCode()); + $this->assertSame(E_ERROR, $withoutEntry->getCode()); + } +} diff --git a/tests/Unit/Encryption/Exceptions/CryptorExceptionTest.php b/tests/Unit/Encryption/Exceptions/CryptorExceptionTest.php new file mode 100644 index 000000000..af5d46a59 --- /dev/null +++ b/tests/Unit/Encryption/Exceptions/CryptorExceptionTest.php @@ -0,0 +1,36 @@ +assertInstanceOf(CryptorException::class, $exception); + $this->assertSame('Public key is not provided', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } + + public function testPrivateKeyNotProvided(): void + { + $exception = CryptorException::privateKeyNotProvided(); + + $this->assertInstanceOf(CryptorException::class, $exception); + $this->assertSame('Private key is not provided', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } + + public function testInvalidCipher(): void + { + $exception = CryptorException::invalidCipher(); + + $this->assertInstanceOf(CryptorException::class, $exception); + $this->assertSame('The cipher is invalid', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } +} diff --git a/tests/Unit/Environment/Exceptions/EnvExceptionTest.php b/tests/Unit/Environment/Exceptions/EnvExceptionTest.php new file mode 100644 index 000000000..e1b044c42 --- /dev/null +++ b/tests/Unit/Environment/Exceptions/EnvExceptionTest.php @@ -0,0 +1,27 @@ +assertInstanceOf(EnvException::class, $exception); + $this->assertSame('The environment is immutable. Modifications are not allowed.', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } + + public function testEnvironmentNotLoaded(): void + { + $exception = EnvException::environmentNotLoaded(); + + $this->assertInstanceOf(EnvException::class, $exception); + $this->assertSame('Environment not loaded. Call `load()` method first.', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } +} diff --git a/tests/Unit/Hasher/Exceptions/HasherExceptionTest.php b/tests/Unit/Hasher/Exceptions/HasherExceptionTest.php new file mode 100644 index 000000000..180d0a58e --- /dev/null +++ b/tests/Unit/Hasher/Exceptions/HasherExceptionTest.php @@ -0,0 +1,25 @@ +assertSame('The algorithm foo not supported.', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } + + public function testInvalidBcryptCost(): void + { + $exception = HasherException::invalidBcryptCost(); + + $this->assertSame('Provided bcrypt cost is invalid.', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } +} diff --git a/tests/Unit/Hook/Exceptions/HookExceptionTest.php b/tests/Unit/Hook/Exceptions/HookExceptionTest.php new file mode 100644 index 000000000..2df1e632b --- /dev/null +++ b/tests/Unit/Hook/Exceptions/HookExceptionTest.php @@ -0,0 +1,27 @@ +assertInstanceOf(HookException::class, $exception); + $this->assertSame('The Hook `boot` already registered.', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } + + public function testUnregisteredHookName(): void + { + $exception = HookException::unregisteredHookName('shutdown'); + + $this->assertInstanceOf(HookException::class, $exception); + $this->assertSame('The Hook `shutdown` was not registered.', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } +} diff --git a/tests/Unit/HttpClient/Exceptions/HttpClientExceptionTest.php b/tests/Unit/HttpClient/Exceptions/HttpClientExceptionTest.php new file mode 100644 index 000000000..77fa41e53 --- /dev/null +++ b/tests/Unit/HttpClient/Exceptions/HttpClientExceptionTest.php @@ -0,0 +1,18 @@ +assertInstanceOf(HttpClientException::class, $exception); + $this->assertSame('Request is not created.', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } +} diff --git a/tests/Unit/Jwt/Exceptions/JwtExceptionTest.php b/tests/Unit/Jwt/Exceptions/JwtExceptionTest.php new file mode 100644 index 000000000..d2659b4f9 --- /dev/null +++ b/tests/Unit/Jwt/Exceptions/JwtExceptionTest.php @@ -0,0 +1,18 @@ +assertInstanceOf(JwtException::class, $exception); + $this->assertSame('JWT payload is missing.', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } +} diff --git a/tests/Unit/Lang/Exceptions/LangExceptionTest.php b/tests/Unit/Lang/Exceptions/LangExceptionTest.php new file mode 100644 index 000000000..62113ac5b --- /dev/null +++ b/tests/Unit/Lang/Exceptions/LangExceptionTest.php @@ -0,0 +1,27 @@ +assertInstanceOf(LangException::class, $exception); + $this->assertSame('Translation files not found.', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } + + public function testMisconfiguredDefaultConfig(): void + { + $exception = LangException::misconfiguredDefaultConfig(); + + $this->assertInstanceOf(LangException::class, $exception); + $this->assertSame('Misconfigured lang default config.', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } +} diff --git a/tests/Unit/Logger/Exceptions/LoggerExceptionTest.php b/tests/Unit/Logger/Exceptions/LoggerExceptionTest.php new file mode 100644 index 000000000..98e98f766 --- /dev/null +++ b/tests/Unit/Logger/Exceptions/LoggerExceptionTest.php @@ -0,0 +1,27 @@ +assertInstanceOf(LoggerException::class, $exception); + $this->assertSame('Log path is not point to a directory.', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } + + public function testLogPathIsNotFile(): void + { + $exception = LoggerException::logPathIsNotFile('/tmp/logs'); + + $this->assertInstanceOf(LoggerException::class, $exception); + $this->assertSame('Log path is not point to a file.', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } +} diff --git a/tests/Unit/Middleware/Exceptions/MiddlewareExceptionTest.php b/tests/Unit/Middleware/Exceptions/MiddlewareExceptionTest.php new file mode 100644 index 000000000..cfe007408 --- /dev/null +++ b/tests/Unit/Middleware/Exceptions/MiddlewareExceptionTest.php @@ -0,0 +1,18 @@ +assertInstanceOf(MiddlewareException::class, $exception); + $this->assertSame('Middleware class `App\\Middlewares\\Auth` not found.', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } +} diff --git a/tests/Unit/Migration/Exceptions/MigrationExceptionTest.php b/tests/Unit/Migration/Exceptions/MigrationExceptionTest.php new file mode 100644 index 000000000..7ee61163e --- /dev/null +++ b/tests/Unit/Migration/Exceptions/MigrationExceptionTest.php @@ -0,0 +1,45 @@ +assertInstanceOf(MigrationException::class, $exception); + $this->assertSame('Migration direction can only be [up] or [down]', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } + + public function testUnsupportedAction(): void + { + $exception = MigrationException::unsupportedAction('sync'); + + $this->assertInstanceOf(MigrationException::class, $exception); + $this->assertSame('The action `sync`, is not supported', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } + + public function testNothingToMigrate(): void + { + $exception = MigrationException::nothingToMigrate(); + + $this->assertInstanceOf(MigrationException::class, $exception); + $this->assertSame('Nothing to migrate', $exception->getMessage()); + $this->assertSame(E_NOTICE, $exception->getCode()); + } + + public function testInvalidMigrationClass(): void + { + $exception = MigrationException::invalidMigrationClass('FooMigration'); + + $this->assertInstanceOf(MigrationException::class, $exception); + $this->assertSame('Migration class `FooMigration` must extend QtMigration', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } +} diff --git a/tests/Unit/Model/Exceptions/ModelExceptionTest.php b/tests/Unit/Model/Exceptions/ModelExceptionTest.php new file mode 100644 index 000000000..834b1caf1 --- /dev/null +++ b/tests/Unit/Model/Exceptions/ModelExceptionTest.php @@ -0,0 +1,58 @@ +assertSame('Inappropriate property `foo` for fillable object', $e->getMessage()); + $this->assertSame(E_WARNING, $e->getCode()); + } + + public function testWrongRelation(): void + { + $e = ModelException::wrongRelation('User', 'posts'); + $this->assertSame('The model `User` does not define relation with `posts`', $e->getMessage()); + $this->assertSame(E_ERROR, $e->getCode()); + } + + public function testRelationTypeMissing(): void + { + $e = ModelException::relationTypeMissing('User', 'Post'); + $this->assertSame('Relation type is missing for model `User` with related model `Post`', $e->getMessage()); + $this->assertSame(E_ERROR, $e->getCode()); + } + + public function testMissingRelationKeys(): void + { + $e = ModelException::missingRelationKeys('User', 'Post'); + $this->assertSame('Relation keys `foreign_key` or `local_key` are missing for model `User` with related model `Post`', $e->getMessage()); + $this->assertSame(E_ERROR, $e->getCode()); + } + + public function testMissingForeignKeyValue(): void + { + $e = ModelException::missingForeignKeyValue('User', 'profile_id'); + $this->assertSame('Foreign key `profile_id` is missing in model `User`', $e->getMessage()); + $this->assertSame(E_ERROR, $e->getCode()); + } + + public function testUnsupportedRelationType(): void + { + $e = ModelException::unsupportedRelationType('foo'); + $this->assertSame('Relation type `foo` is not supported', $e->getMessage()); + $this->assertSame(E_ERROR, $e->getCode()); + } + + public function testOrmIsNotSet(): void + { + $e = ModelException::ormIsNotSet(); + $this->assertSame('ORM instance not initialized', $e->getMessage()); + $this->assertSame(E_ERROR, $e->getCode()); + } +} diff --git a/tests/Unit/Module/Exceptions/ModuleExceptionTest.php b/tests/Unit/Module/Exceptions/ModuleExceptionTest.php new file mode 100644 index 000000000..15906bc02 --- /dev/null +++ b/tests/Unit/Module/Exceptions/ModuleExceptionTest.php @@ -0,0 +1,58 @@ +assertSame('Routes not found for module `Blog`', $e->getMessage()); + $this->assertSame(E_ERROR, $e->getCode()); + } + + public function testModuleConfigNotFound(): void + { + $e = ModuleException::moduleConfigNotFound(); + $this->assertSame('Config not found for a module', $e->getMessage()); + $this->assertSame(E_ERROR, $e->getCode()); + } + + public function testModuleCreationIncomplete(): void + { + $e = ModuleException::moduleCreationIncomplete(); + $this->assertSame('Module creation incomplete: missing files.', $e->getMessage()); + $this->assertSame(E_ERROR, $e->getCode()); + } + + public function testMissingModuleTemplate(): void + { + $e = ModuleException::missingModuleTemplate('demo'); + $this->assertSame('Template `demo` does not exist', $e->getMessage()); + $this->assertSame(E_ERROR, $e->getCode()); + } + + public function testMissingModuleDirectory(): void + { + $e = ModuleException::missingModuleDirectory(); + $this->assertSame('Module directory does not exist, skipping config update.', $e->getMessage()); + $this->assertSame(E_ERROR, $e->getCode()); + } + + public function testModuleAlreadyExists(): void + { + $e = ModuleException::moduleAlreadyExists('Admin'); + $this->assertSame('A module or prefix named `Admin` already exists', $e->getMessage()); + $this->assertSame(E_ERROR, $e->getCode()); + } + + public function testDirectoryListingFailed(): void + { + $e = ModuleException::directoryListingFailed('/tmp/src'); + $this->assertSame('Failed to list directory `/tmp/src`', $e->getMessage()); + $this->assertSame(E_ERROR, $e->getCode()); + } +} diff --git a/tests/Unit/Paginator/Exceptions/PaginatorExceptionTest.php b/tests/Unit/Paginator/Exceptions/PaginatorExceptionTest.php new file mode 100644 index 000000000..e676f989a --- /dev/null +++ b/tests/Unit/Paginator/Exceptions/PaginatorExceptionTest.php @@ -0,0 +1,18 @@ +assertInstanceOf(PaginatorException::class, $exception); + $this->assertSame('Missing required parameter `items` missing for adapter Array', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } +} diff --git a/tests/Unit/Router/Exceptions/RouteExceptionTest.php b/tests/Unit/Router/Exceptions/RouteExceptionTest.php new file mode 100644 index 000000000..c4e9cc56f --- /dev/null +++ b/tests/Unit/Router/Exceptions/RouteExceptionTest.php @@ -0,0 +1,49 @@ +assertSame('Route must define at least one HTTP method', RouteException::noHttpMethods()->getMessage()); + $this->assertSame(E_ERROR, RouteException::noHttpMethods()->getCode()); + $this->assertSame('Closure route cannot define controller or action', RouteException::closureWithController()->getMessage()); + $this->assertSame(E_WARNING, RouteException::closureWithController()->getCode()); + $this->assertSame('Controller route must define non-empty controller and action', RouteException::incompleteControllerRoute()->getMessage()); + $this->assertSame(E_ERROR, RouteException::incompleteControllerRoute()->getCode()); + $this->assertSame('Nested route groups are not supported', RouteException::nestedGroups()->getMessage()); + $this->assertSame(E_WARNING, RouteException::nestedGroups()->getCode()); + $this->assertSame('middlewares() must be called inside a group or after a route definition', RouteException::middlewaresOutsideRoute()->getMessage()); + $this->assertSame(E_WARNING, RouteException::middlewaresOutsideRoute()->getCode()); + $this->assertSame('Cannot resolve controller without module context', RouteException::controllerWithoutModule()->getMessage()); + $this->assertSame(E_ERROR, RouteException::controllerWithoutModule()->getCode()); + $this->assertSame('cacheable() must be called inside a group or after a route definition', RouteException::cacheableOutsideRoute()->getMessage()); + $this->assertSame(E_WARNING, RouteException::cacheableOutsideRoute()->getCode()); + $this->assertSame('Closure route is missing its closure handler', RouteException::closureHandlerMissing()->getMessage()); + $this->assertSame(E_ERROR, RouteException::closureHandlerMissing()->getCode()); + $this->assertSame('Route is not a closure', RouteException::notClosure()->getMessage()); + $this->assertSame(E_WARNING, RouteException::notClosure()->getCode()); + $this->assertSame('Names can not be set before route definition', RouteException::nameBeforeDefinition()->getMessage()); + $this->assertSame(E_WARNING, RouteException::nameBeforeDefinition()->getCode()); + $this->assertSame('Route param names can only contain letters', RouteException::paramNameNotValid()->getMessage()); + $this->assertSame(E_WARNING, RouteException::paramNameNotValid()->getCode()); + } + + public function testParameterizedFactories(): void + { + $this->assertSame('Routes for module `Blog` must return a Closure', RouteException::moduleRoutesNotClosure('Blog')->getMessage()); + $this->assertSame(E_ERROR, RouteException::moduleRoutesNotClosure('Blog')->getCode()); + $this->assertSame('Route name `home` must be unique within module', RouteException::nonUniqueNameInModule('home')->getMessage()); + $this->assertSame(E_WARNING, RouteException::nonUniqueNameInModule('home')->getCode()); + $this->assertSame('Action `index` not found on controller `PostController`', RouteException::actionNotFound('index', 'PostController')->getMessage()); + $this->assertSame(E_ERROR, RouteException::actionNotFound('index', 'PostController')->getCode()); + $this->assertSame('Route handler `handler` must return `Quantum\\Http\\Response`', RouteException::invalidHandlerResponse('handler', 'Quantum\\Http\\Response')->getMessage()); + $this->assertSame(E_ERROR, RouteException::invalidHandlerResponse('handler', 'Quantum\\Http\\Response')->getCode()); + $this->assertSame('Route param name `id` already in use', RouteException::paramNameNotAvailable('id')->getMessage()); + $this->assertSame(E_WARNING, RouteException::paramNameNotAvailable('id')->getCode()); + } +} diff --git a/tests/Unit/Session/Exceptions/SessionExceptionTest.php b/tests/Unit/Session/Exceptions/SessionExceptionTest.php new file mode 100644 index 000000000..f3e21f873 --- /dev/null +++ b/tests/Unit/Session/Exceptions/SessionExceptionTest.php @@ -0,0 +1,27 @@ +assertInstanceOf(SessionException::class, $exception); + $this->assertSame('Can not start the session.', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } + + public function testSessionNotDestroyed(): void + { + $exception = SessionException::sessionNotDestroyed(); + + $this->assertInstanceOf(SessionException::class, $exception); + $this->assertSame('Can not destroy the session.', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } +} diff --git a/tests/Unit/Storage/Exceptions/FileSystemExceptionTest.php b/tests/Unit/Storage/Exceptions/FileSystemExceptionTest.php new file mode 100644 index 000000000..eaaf70f08 --- /dev/null +++ b/tests/Unit/Storage/Exceptions/FileSystemExceptionTest.php @@ -0,0 +1,30 @@ +assertSame('The directory /tmp/a does not exists.', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } + + public function testDirectoryNotWritable(): void + { + $exception = FileSystemException::directoryNotWritable('/tmp/b'); + $this->assertSame('The directory /tmp/b is not writable.', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } + + public function testFileAlreadyExists(): void + { + $exception = FileSystemException::fileAlreadyExists('/tmp/c.txt'); + $this->assertSame('The file /tmp/c.txt already exists.', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } +} diff --git a/tests/Unit/Storage/Exceptions/FileUploadExceptionTest.php b/tests/Unit/Storage/Exceptions/FileUploadExceptionTest.php new file mode 100644 index 000000000..0de11bce0 --- /dev/null +++ b/tests/Unit/Storage/Exceptions/FileUploadExceptionTest.php @@ -0,0 +1,23 @@ +assertSame('The file type `exe` is not allowed.', $exception->getMessage()); + $this->assertSame(E_WARNING, $exception->getCode()); + } + + public function testIncorrectMimeTypesConfig(): void + { + $exception = FileUploadException::incorrectMimeTypesConfig('uploads'); + $this->assertSame('Could not load config `uploads` properly.', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } +} diff --git a/tests/Unit/View/Exceptions/ViewExceptionTest.php b/tests/Unit/View/Exceptions/ViewExceptionTest.php new file mode 100644 index 000000000..1a779c579 --- /dev/null +++ b/tests/Unit/View/Exceptions/ViewExceptionTest.php @@ -0,0 +1,27 @@ +assertInstanceOf(ViewException::class, $exception); + $this->assertSame('Layout is not set.', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } + + public function testViewNotRendered(): void + { + $exception = ViewException::viewNotRendered(); + + $this->assertInstanceOf(ViewException::class, $exception); + $this->assertSame('View not rendered yet.', $exception->getMessage()); + $this->assertSame(E_ERROR, $exception->getCode()); + } +}