diff --git a/src/App/Adapters/ConsoleAppAdapter.php b/src/App/Adapters/ConsoleAppAdapter.php index c566ebf2c..0a3a9f375 100644 --- a/src/App/Adapters/ConsoleAppAdapter.php +++ b/src/App/Adapters/ConsoleAppAdapter.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\App\Adapters; @@ -64,7 +64,7 @@ public function __construct() if ($commandName !== 'core:env') { $this->loadEnvironment(); - $this->loadConfig(); + $this->loadAppConfig(); } } @@ -81,8 +81,8 @@ public function start(): ?int { try { $this->application = $this->createApplication( - config()->get('app_name', 'UNKNOWN'), - config()->get('app_version', 'UNKNOWN') + config()->get('app.name', 'UNKNOWN'), + config()->get('app.version', 'UNKNOWN') ); $this->registerCoreCommands(); diff --git a/src/App/Adapters/WebAppAdapter.php b/src/App/Adapters/WebAppAdapter.php index 83d8c4b14..dfdb396e0 100644 --- a/src/App/Adapters/WebAppAdapter.php +++ b/src/App/Adapters/WebAppAdapter.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace Quantum\App\Adapters; @@ -69,7 +69,7 @@ public function __construct() parent::__construct(); $this->loadEnvironment(); - $this->loadConfig(); + $this->loadAppConfig(); $this->request = Di::get(Request::class); $this->response = Di::get(Response::class); diff --git a/src/App/Helpers/misc.php b/src/App/Helpers/misc.php index 88820d56c..c3ae3a0f0 100644 --- a/src/App/Helpers/misc.php +++ b/src/App/Helpers/misc.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ use Symfony\Component\VarExporter\Exception\ExceptionInterface; @@ -88,7 +88,7 @@ function slugify(string $text): string */ function is_debug_mode(): bool { - return filter_var(config()->get('debug'), FILTER_VALIDATE_BOOLEAN); + return filter_var(config()->get('app.debug'), FILTER_VALIDATE_BOOLEAN); } /** diff --git a/src/App/Traits/AppTrait.php b/src/App/Traits/AppTrait.php index 37f7f8d9f..6fdeaabbd 100644 --- a/src/App/Traits/AppTrait.php +++ b/src/App/Traits/AppTrait.php @@ -143,9 +143,9 @@ protected function loadEnvironment() * @throws ReflectionException * @throws ConfigException */ - protected function loadConfig() + protected function loadAppConfig() { - Config::getInstance()->load(new Setup('config', 'config')); + Config::getInstance()->import(new Setup('config', 'app')); } /** diff --git a/src/Debugger/Debugger.php b/src/Debugger/Debugger.php index 2da976e10..07b7c34f5 100644 --- a/src/Debugger/Debugger.php +++ b/src/Debugger/Debugger.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.5 + * @since 2.9.9 */ namespace Quantum\Debugger; @@ -128,7 +128,7 @@ public static function getInstance(DebuggerStore $store = null, DebugBar $debugB */ public function isEnabled(): bool { - return filter_var(config()->get('debug'), FILTER_VALIDATE_BOOLEAN); + return filter_var(config()->get('app.debug'), FILTER_VALIDATE_BOOLEAN); } /** diff --git a/src/Http/Request/HttpRequest.php b/src/Http/Request/HttpRequest.php index 6c47e9840..64672caaa 100644 --- a/src/Http/Request/HttpRequest.php +++ b/src/Http/Request/HttpRequest.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace Quantum\Http\Request; @@ -210,7 +210,7 @@ public static function getCsrfToken(): ?string */ public static function getBaseUrl(bool $withModulePrefix = false): string { - $baseUrl = config()->get('base_url'); + $baseUrl = config()->get('app.base_url'); $prefix = route_prefix(); $modulePrefix = ($withModulePrefix && !empty($prefix)) ? '/' . $prefix : ''; diff --git a/src/Libraries/Auth/Traits/AuthTrait.php b/src/Libraries/Auth/Traits/AuthTrait.php index f544d2b9e..1afc90723 100644 --- a/src/Libraries/Auth/Traits/AuthTrait.php +++ b/src/Libraries/Auth/Traits/AuthTrait.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Auth\Traits; @@ -249,7 +249,7 @@ protected function twoStepVerification(User $user): string $time = new DateTime(); - $time->add(new DateInterval('PT' . config()->get('otp_expires') . 'M')); + $time->add(new DateInterval('PT' . config()->get('auth.otp_expires') . 'M')); $this->authService->update( $this->keyFields[AuthKeys::USERNAME], @@ -344,7 +344,7 @@ protected function isActivated(User $user): bool */ protected function generateToken(string $val = null): string { - return base64_encode($this->hasher->hash($val ?: config()->get('app_key'))); + return base64_encode($this->hasher->hash($val ?: config()->get('app.key'))); } /** @@ -356,8 +356,8 @@ protected function sendMail(User $user, array $body) { $fullName = ($user->hasField('firstname') && $user->hasField('lastname')) ? $user->getFieldValue('firstname') . ' ' . $user->getFieldValue('lastname') : ''; - $appEmail = config()->get('app_email') ?: ''; - $appName = config()->get('app_name') ?: ''; + $appEmail = config()->get('app.email') ?: ''; + $appName = config()->get('app.name') ?: ''; $this->mailer->setFrom($appEmail, $appName) ->setAddress($user->getFieldValue($this->keyFields[AuthKeys::USERNAME]), $fullName) @@ -394,6 +394,6 @@ protected function verifySchema(array $schema) */ protected function isTwoFactorEnabled(): bool { - return filter_var(config()->get('TWO_FA'), FILTER_VALIDATE_BOOLEAN); + return filter_var(config()->get('auth.two_fa'), FILTER_VALIDATE_BOOLEAN); } } \ No newline at end of file diff --git a/src/Libraries/Database/Adapters/Idiorm/IdiormDbal.php b/src/Libraries/Database/Adapters/Idiorm/IdiormDbal.php index 8de828f62..fbbb1c202 100644 --- a/src/Libraries/Database/Adapters/Idiorm/IdiormDbal.php +++ b/src/Libraries/Database/Adapters/Idiorm/IdiormDbal.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace Quantum\Libraries\Database\Adapters\Idiorm; @@ -252,7 +252,7 @@ protected static function getBaseConfig(string $driver, array $config): array { return [ 'connection_string' => self::buildConnectionString($driver, $config), - 'logging' => config()->get('debug', false), + 'logging' => config()->get('app.debug', false), 'error_mode' => PDO::ERRMODE_EXCEPTION, ]; } diff --git a/src/Libraries/Encryption/Adapters/SymmetricEncryptionAdapter.php b/src/Libraries/Encryption/Adapters/SymmetricEncryptionAdapter.php index f925aae13..f7f21eed2 100644 --- a/src/Libraries/Encryption/Adapters/SymmetricEncryptionAdapter.php +++ b/src/Libraries/Encryption/Adapters/SymmetricEncryptionAdapter.php @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.7 + * @since 2.9.9 */ namespace Quantum\Libraries\Encryption\Adapters; @@ -41,7 +41,7 @@ class SymmetricEncryptionAdapter implements EncryptionInterface */ public function __construct() { - $appKey = config()->get('app_key'); + $appKey = config()->get('app.key'); if (!$appKey) { throw AppException::missingAppKey(); diff --git a/src/Module/Templates/DefaultWeb/src/Controllers/MainController.php.tpl b/src/Module/Templates/DefaultWeb/src/Controllers/MainController.php.tpl index 8f9e229e6..ba0b38992 100644 --- a/src/Module/Templates/DefaultWeb/src/Controllers/MainController.php.tpl +++ b/src/Module/Templates/DefaultWeb/src/Controllers/MainController.php.tpl @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace {{MODULE_NAMESPACE}}\Controllers; @@ -51,7 +51,7 @@ class MainController extends RouteController public function index(Response $response, ViewFactory $view) { $view->setParams([ - 'title' => config()->get('app_name'), + 'title' => config()->get('app.name'), ]); $response->html($view->render('index')); diff --git a/src/Module/Templates/DefaultWeb/src/Views/index.php.tpl b/src/Module/Templates/DefaultWeb/src/Views/index.php.tpl index d7640ce0f..559bc171e 100644 --- a/src/Module/Templates/DefaultWeb/src/Views/index.php.tpl +++ b/src/Module/Templates/DefaultWeb/src/Views/index.php.tpl @@ -2,7 +2,7 @@
- <?php echo config()->get('app_name') ?> + <?php echo config()->get('app.name') ?>

HOME PAGE

diff --git a/src/Module/Templates/DemoApi/src/Controllers/AuthController.php.tpl b/src/Module/Templates/DemoApi/src/Controllers/AuthController.php.tpl index ba7c97a4b..b34c5dffa 100644 --- a/src/Module/Templates/DemoApi/src/Controllers/AuthController.php.tpl +++ b/src/Module/Templates/DemoApi/src/Controllers/AuthController.php.tpl @@ -9,7 +9,7 @@ * @author Arman Ag. * @copyright Copyright (c) 2018 Softberg LLC (https://softberg.org) * @link http://quantum.softberg.org/ - * @since 2.9.8 + * @since 2.9.9 */ namespace {{MODULE_NAMESPACE}}\Controllers; @@ -36,7 +36,7 @@ class AuthController extends BaseController try { $code = auth()->signin($request->get('email'), $request->get('password')); - if (filter_var(config()->get('TWO_FA'), FILTER_VALIDATE_BOOLEAN)) { + if (filter_var(config()->get('auth.two_fa'), FILTER_VALIDATE_BOOLEAN)) { $response->set('code', $code); } diff --git a/src/Module/Templates/DemoApi/src/config/auth.php.tpl b/src/Module/Templates/DemoApi/src/config/auth.php.tpl index 6895e3738..9bdb0f865 100644 --- a/src/Module/Templates/DemoApi/src/config/auth.php.tpl +++ b/src/Module/Templates/DemoApi/src/config/auth.php.tpl @@ -22,5 +22,23 @@ return [ 'nbf' => time() + 1, 'exp' => time() + 3600, ] - ] + ], + + /** + * --------------------------------------------------------- + * Two-factor authentication + * --------------------------------------------------------- + * + * Enables or disables 2-factor authentication + */ + 'two_fa' => env('TWO_FA', true), + + /** + * --------------------------------------------------------- + * OTP expiration + * --------------------------------------------------------- + * + * OTP expires after minutes defined + */ + 'otp_expires' => 2, ]; \ No newline at end of file diff --git a/src/Module/Templates/DemoWeb/src/Controllers/AccountController.php.tpl b/src/Module/Templates/DemoWeb/src/Controllers/AccountController.php.tpl index c459fa614..f0f27d16a 100644 --- a/src/Module/Templates/DemoWeb/src/Controllers/AccountController.php.tpl +++ b/src/Module/Templates/DemoWeb/src/Controllers/AccountController.php.tpl @@ -55,7 +55,7 @@ class AccountController extends BaseController public function form(Response $response) { $this->view->setParams([ - 'title' => t('common.account_settings') . ' | ' . config()->get('app_name'), + 'title' => t('common.account_settings') . ' | ' . config()->get('app.name'), ]); $response->html($this->view->render('account/form')); diff --git a/src/Module/Templates/DemoWeb/src/Controllers/AuthController.php.tpl b/src/Module/Templates/DemoWeb/src/Controllers/AuthController.php.tpl index a0e11331f..1cc15d712 100644 --- a/src/Module/Templates/DemoWeb/src/Controllers/AuthController.php.tpl +++ b/src/Module/Templates/DemoWeb/src/Controllers/AuthController.php.tpl @@ -66,7 +66,7 @@ class AuthController extends BaseController try { $code = auth()->signin($request->get('email'), $request->get('password'), !!$request->get('remember')); - if (filter_var(config()->get('TWO_FA'), FILTER_VALIDATE_BOOLEAN)) { + if (filter_var(config()->get('auth.two_fa'), FILTER_VALIDATE_BOOLEAN)) { redirect(base_url(true) . '/' . current_lang() . '/verify/' . $code); } else { redirect(base_url(true) . '/' . current_lang()); @@ -77,7 +77,7 @@ class AuthController extends BaseController } } else { $this->view->setParams([ - 'title' => t('common.signin') . ' | ' . config()->get('app_name'), + 'title' => t('common.signin') . ' | ' . config()->get('app.name'), ]); $response->html($this->view->render(self::VIEW_SIGNIN)); @@ -107,7 +107,7 @@ class AuthController extends BaseController } else { $this->view->setParams([ // 'captcha' => captcha(), - 'title' => t('common.signup') . ' | ' . config()->get('app_name'), + 'title' => t('common.signup') . ' | ' . config()->get('app.name'), ]); $response->html($this->view->render(self::VIEW_SIGNUP)); @@ -137,7 +137,7 @@ class AuthController extends BaseController redirect(base_url(true) . '/' . current_lang() . '/forget'); } else { $this->view->setParams([ - 'title' => t('common.forget_password') . ' | ' . config()->get('app_name'), + 'title' => t('common.forget_password') . ' | ' . config()->get('app.name'), ]); $response->html($this->view->render(self::VIEW_FORGET)); @@ -156,7 +156,7 @@ class AuthController extends BaseController redirect(base_url(true) . '/' . current_lang() . '/signin'); } else { $this->view->setParams([ - 'title' => t('common.reset_password') . ' | ' . config()->get('app_name'), + 'title' => t('common.reset_password') . ' | ' . config()->get('app.name'), 'reset_token' => $request->get('reset_token') ]); @@ -181,7 +181,7 @@ class AuthController extends BaseController } } else { $this->view->setParams([ - 'title' => t('common.two_fa') . ' | ' . config()->get('app_name'), + 'title' => t('common.two_fa') . ' | ' . config()->get('app.name'), 'code' => route_param('code') ]); diff --git a/src/Module/Templates/DemoWeb/src/Controllers/PageController.php.tpl b/src/Module/Templates/DemoWeb/src/Controllers/PageController.php.tpl index f45aa3377..51a622511 100644 --- a/src/Module/Templates/DemoWeb/src/Controllers/PageController.php.tpl +++ b/src/Module/Templates/DemoWeb/src/Controllers/PageController.php.tpl @@ -35,7 +35,7 @@ class PageController extends BaseController public function home(Response $response) { $this->view->setParams([ - 'title' => config()->get('app_name'), + 'title' => config()->get('app.name'), ]); $response->html($this->view->render('pages/index')); @@ -48,7 +48,7 @@ class PageController extends BaseController public function about(Response $response) { $this->view->setParams([ - 'title' => t('common.about') . ' | ' . config()->get('app_name'), + 'title' => t('common.about') . ' | ' . config()->get('app.name'), ]); $response->html($this->view->render('pages/about')); diff --git a/src/Module/Templates/DemoWeb/src/Controllers/PostController.php.tpl b/src/Module/Templates/DemoWeb/src/Controllers/PostController.php.tpl index 6cc87c72b..3c2843c89 100644 --- a/src/Module/Templates/DemoWeb/src/Controllers/PostController.php.tpl +++ b/src/Module/Templates/DemoWeb/src/Controllers/PostController.php.tpl @@ -69,7 +69,7 @@ class PostController extends BaseController $paginatedPosts = $this->postService->getPosts($perPage, $currentPage, $search); $this->view->setParams([ - 'title' => t('common.posts') . ' | ' . config()->get('app_name'), + 'title' => t('common.posts') . ' | ' . config()->get('app.name'), 'posts' => $this->postService->transformData($paginatedPosts->data()->all()), 'pagination' => $paginatedPosts ]); @@ -96,7 +96,7 @@ class PostController extends BaseController } $this->view->setParams([ - 'title' => $post->title . ' | ' . config()->get('app_name'), + 'title' => $post->title . ' | ' . config()->get('app.name'), 'post' => new RawParam(current($this->postService->transformData([$post]))), 'referer' => $ref, ]); @@ -114,7 +114,7 @@ class PostController extends BaseController $myPosts = $this->postService->getMyPosts(auth()->user()->uuid); $this->view->setParams([ - 'title' => t('common.my_posts') . ' | ' . config()->get('app_name'), + 'title' => t('common.my_posts') . ' | ' . config()->get('app.name'), 'posts' => $this->postService->transformData($myPosts->all()) ]); @@ -131,7 +131,7 @@ class PostController extends BaseController $ref = $request->get('ref', 'posts'); $this->view->setParams([ - 'title' => t('common.new_post') . ' | ' . config()->get('app_name'), + 'title' => t('common.new_post') . ' | ' . config()->get('app.name'), 'referer' => $ref ]); @@ -181,7 +181,7 @@ class PostController extends BaseController $post = $this->postService->getPost($postUuid); $this->view->setParams([ - 'title' => $post->title . ' | ' . config()->get('app_name'), + 'title' => $post->title . ' | ' . config()->get('app.name'), 'post' => $post->asArray(), 'referer' => $ref ]); diff --git a/src/Module/Templates/DemoWeb/src/config/auth.php.tpl b/src/Module/Templates/DemoWeb/src/config/auth.php.tpl index 3f4036da8..29446681a 100644 --- a/src/Module/Templates/DemoWeb/src/config/auth.php.tpl +++ b/src/Module/Templates/DemoWeb/src/config/auth.php.tpl @@ -22,5 +22,23 @@ return [ 'nbf' => time() + 1, 'exp' => time() + 3600, ] - ] + ], + + /** + * --------------------------------------------------------- + * Two-factor authentication + * --------------------------------------------------------- + * + * Enables or disables 2-factor authentication + */ + 'two_fa' => env('TWO_FA', true), + + /** + * --------------------------------------------------------- + * OTP expiration + * --------------------------------------------------------- + * + * OTP expires after minutes defined + */ + 'otp_expires' => 2, ]; \ No newline at end of file diff --git a/tests/Unit/App/Adapters/ConsoleAppAdapterTest.php b/tests/Unit/App/Adapters/ConsoleAppAdapterTest.php index 31b8a4f3c..df8178ac3 100644 --- a/tests/Unit/App/Adapters/ConsoleAppAdapterTest.php +++ b/tests/Unit/App/Adapters/ConsoleAppAdapterTest.php @@ -26,6 +26,11 @@ public function setUp(): void $this->consoleAppAdapter->shouldReceive('createApplication')->andReturn($applicationMock); } + public function tearDown(): void + { + config()->flush(); + } + public function testConsoleAppAdapterStartSuccessfully() { $_SERVER['argv'] = ['qt', 'list', '--quiet']; diff --git a/tests/Unit/App/Adapters/WebAppAdapterTest.php b/tests/Unit/App/Adapters/WebAppAdapterTest.php index 896ec1894..cb18fa8c9 100644 --- a/tests/Unit/App/Adapters/WebAppAdapterTest.php +++ b/tests/Unit/App/Adapters/WebAppAdapterTest.php @@ -21,6 +21,11 @@ public function setUp(): void $this->webAppAdapter = new WebAppAdapter(); } + public function tearDown(): void + { + config()->flush(); + } + public function testWebAppAdapterStartSuccessfully() { $request = Di::get(Request::class); diff --git a/tests/Unit/App/AppTest.php b/tests/Unit/App/AppTest.php index 97885a7f1..705423220 100644 --- a/tests/Unit/App/AppTest.php +++ b/tests/Unit/App/AppTest.php @@ -25,6 +25,11 @@ public function setUp(): void App::setBaseDir(PROJECT_ROOT); } + public function tearDown(): void + { + config()->flush(); + } + public function testAppGetAdapter() { $app = new App(new WebAppAdapter()); @@ -33,6 +38,8 @@ public function testAppGetAdapter() $this->assertInstanceOf(AppInterface::class, $app->getAdapter()); + config()->flush(); + $app = new App(new ConsoleAppAdapter()); $this->assertInstanceOf(ConsoleAppAdapter::class, $app->getAdapter()); diff --git a/tests/Unit/App/Factories/AppFactoryTest.php b/tests/Unit/App/Factories/AppFactoryTest.php index 9d9c2aae3..448e8c512 100644 --- a/tests/Unit/App/Factories/AppFactoryTest.php +++ b/tests/Unit/App/Factories/AppFactoryTest.php @@ -26,6 +26,11 @@ public function testAppFactoryInstance() $this->assertInstanceOf(App::class, $app); } + public function tearDown(): void + { + config()->flush(); + } + public function testAppFactoryConsoleAdapter() { $app = AppFactory::create(App::CONSOLE, PROJECT_ROOT); diff --git a/tests/Unit/AppTestCase.php b/tests/Unit/AppTestCase.php index 0ced015c1..6f3856794 100644 --- a/tests/Unit/AppTestCase.php +++ b/tests/Unit/AppTestCase.php @@ -6,7 +6,6 @@ use Quantum\App\Factories\AppFactory; use Quantum\Environment\Environment; use PHPUnit\Framework\TestCase; -use Quantum\Config\Config; use Quantum\Loader\Setup; use ReflectionClass; use Quantum\App\App; @@ -25,22 +24,13 @@ public function setUp(): void AppFactory::create(App::WEB, PROJECT_ROOT); - Config::getInstance()->flush(); + config()->flush(); Environment::getInstance() ->setMutable(true) ->load(new Setup('config', 'env')); - Config::getInstance() - ->load(new Setup('config', 'config')); - - $coreDependencies = [ - \Quantum\Loader\Loader::class => \Quantum\Loader\Loader::class, - \Quantum\Http\Request::class => \Quantum\Http\Request::class, - \Quantum\Http\Response::class => \Quantum\Http\Response::class, - ]; - - Di::registerDependencies($coreDependencies); + config()->import(new Setup('config', 'app')); $this->fs = FileSystemFactory::get(); } @@ -48,6 +38,7 @@ public function setUp(): void public function tearDown(): void { AppFactory::destroy(App::WEB); + config()->flush(); Di::reset(); } diff --git a/tests/Unit/Config/ConfigTest.php b/tests/Unit/Config/ConfigTest.php index 05d620762..b61bcd5a3 100644 --- a/tests/Unit/Config/ConfigTest.php +++ b/tests/Unit/Config/ConfigTest.php @@ -25,27 +25,18 @@ public function testConfigLoad() $this->assertEmpty($config->all()); - $config->load(new Setup('config', 'config')); + $config->load(new Setup('config', 'app')); $this->assertNotEmpty($config->all()); $this->assertInstanceOf(Data::class, $config->all()); } - public function testLoadingNonExistingConfigFile() - { - $this->expectException(LoaderException::class); - - $this->expectExceptionMessage('File `config' . DS . 'somefile` not found!'); - - Config::getInstance()->load(new Setup('config', 'somefile')); - } - public function testConfigImport() { $config = Config::getInstance(); - $config->load(new Setup('config', 'config')); + $config->load(new Setup('config', 'app')); $this->assertNull($config->get('database.default')); @@ -69,37 +60,35 @@ public function testCollisionAtImporting() { $config = Config::getInstance(); - $config->import(new Setup('config', 'config')); + $config->import(new Setup('config', 'app')); $this->expectException(ConfigException::class); - $this->expectExceptionMessage('Config key `config` is already in use'); + $this->expectExceptionMessage('Config key `app` is already in use'); - $config->import(new Setup('config', 'config')); + $config->import(new Setup('config', 'app')); } public function testConfigHas() { $config = Config::getInstance(); - $config->load(new Setup('config', 'config')); + $config->import(new Setup('config', 'app')); - $this->assertTrue($config->has('debug')); + $this->assertTrue($config->has('app.debug')); - $this->assertTrue($config->has('test')); + $this->assertTrue($config->has('app.test')); - $this->assertFalse($config->has('none')); + $this->assertFalse($config->has('app.none')); } public function testConfigGet() { $config = Config::getInstance(); - $config->load(new Setup('config', 'config')); - - $this->assertIsArray($config->get('langs')); + $config->import(new Setup('config', 'lang')); - $this->assertEquals('Testing', $config->get('test')); + $this->assertIsArray($config->get('lang.supported')); $this->assertEquals('Default Value', $config->get('not-exists', 'Default Value')); @@ -129,22 +118,22 @@ public function testConfigDelete() { $config = Config::getInstance(); - $config->load(new Setup('config', 'config')); + $config->import(new Setup('config', 'app')); - $this->assertNotNull($config->get('test')); + $this->assertNotNull($config->get('app.test')); - $config->delete('test'); + $config->delete('app.test'); - $this->assertFalse($config->has('test')); + $this->assertFalse($config->has('app.test')); - $this->assertNull($config->get('test')); + $this->assertNull($config->get('app.test')); } public function testConfigFlush() { $config = Config::getInstance(); - $config->load(new Setup('config', 'config')); + $config->import(new Setup('config', 'app')); $this->assertNotEmpty($config->all()); diff --git a/tests/Unit/Debugger/DebuggerTest.php b/tests/Unit/Debugger/DebuggerTest.php index a0c49ba0c..2ed8d5d8a 100644 --- a/tests/Unit/Debugger/DebuggerTest.php +++ b/tests/Unit/Debugger/DebuggerTest.php @@ -48,10 +48,10 @@ public function setUp(): void public function testDebuggerIsEnabled() { - config()->set('debug', true); + config()->set('app.debug', true); $this->assertTrue($this->debugger->isEnabled()); - config()->set('debug', false); + config()->set('app.debug', false); $this->assertFalse($this->debugger->isEnabled()); } diff --git a/tests/Unit/Http/Helpers/HttpHelperTest.php b/tests/Unit/Http/Helpers/HttpHelperTest.php index 2ef0cea27..23d371d47 100644 --- a/tests/Unit/Http/Helpers/HttpHelperTest.php +++ b/tests/Unit/Http/Helpers/HttpHelperTest.php @@ -33,6 +33,8 @@ public function tearDown(): void public function testBaseUrlWithoutModulePrefix() { + config()->set('app.base_url', null); + $this->request->create('GET', 'https://example.com'); $this->assertEquals('https://example.com', base_url()); @@ -40,6 +42,8 @@ public function testBaseUrlWithoutModulePrefix() public function testBaseUrlWithModulePrefix() { + config()->set('app.base_url', null); + $router = new Router($this->request); Router::setRoutes([ diff --git a/tests/Unit/Libraries/Archive/Adapters/PharAdapterTest.php b/tests/Unit/Libraries/Archive/Adapters/PharAdapterTest.php index 7da3a4a71..d7f1a0305 100644 --- a/tests/Unit/Libraries/Archive/Adapters/PharAdapterTest.php +++ b/tests/Unit/Libraries/Archive/Adapters/PharAdapterTest.php @@ -43,7 +43,7 @@ public function testAddFileToPhar() $this->assertTrue( $this->pharArchive->addFile( - base_dir() . DS . 'shared' . DS . 'config' . DS . 'config.php', + base_dir() . DS . 'shared' . DS . 'config' . DS . 'app.php', 'app.conf') ); @@ -64,7 +64,7 @@ public function testAddFromStringToPhar() public function testAddMultipleFilesToPhar() { $this->assertTrue($this->pharArchive->addMultipleFiles([ - 'app.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'config.php', + 'app.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'app.php', 'session.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'session.php' ])); @@ -76,7 +76,7 @@ public function testAddMultipleFilesToPhar() public function testPharCount() { $this->assertTrue($this->pharArchive->addMultipleFiles([ - 'app.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'config.php', + 'app.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'app.php', 'session.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'session.php' ])); @@ -102,7 +102,7 @@ public function testExtractToFromPhar() public function testDeleteFileFromPhar() { $this->pharArchive->addMultipleFiles([ - 'app.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'config.php', + 'app.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'app.php', 'session.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'session.php' ]); @@ -122,7 +122,7 @@ public function testDeleteFileFromPhar() public function testDeleteMultipleFilesUsingNameFromPhar() { $this->pharArchive->addMultipleFiles([ - 'app.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'config.php', + 'app.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'app.php', 'directoryOne/session.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'session.php' ]); diff --git a/tests/Unit/Libraries/Archive/Adapters/ZipAdapterTest.php b/tests/Unit/Libraries/Archive/Adapters/ZipAdapterTest.php index fcdeb2bac..94e305720 100644 --- a/tests/Unit/Libraries/Archive/Adapters/ZipAdapterTest.php +++ b/tests/Unit/Libraries/Archive/Adapters/ZipAdapterTest.php @@ -44,7 +44,7 @@ public function testAddFileToZip() $this->assertTrue( $this->zipArchive->addFile( - base_dir() . DS . 'shared' . DS . 'config' . DS . 'config.php', + base_dir() . DS . 'shared' . DS . 'config' . DS . 'app.php', 'app.conf') ); @@ -61,7 +61,7 @@ public function testAddFromStringToZip() public function testAddMultipleFilesToZip() { $this->assertTrue($this->zipArchive->addMultipleFiles([ - 'app.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'config.php', + 'app.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'app.php', 'session.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'session.php' ])); @@ -73,7 +73,7 @@ public function testAddMultipleFilesToZip() public function testZipCount() { $this->assertTrue($this->zipArchive->addMultipleFiles([ - 'app.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'config.php', + 'app.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'app.php', 'session.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'session.php' ])); @@ -98,7 +98,7 @@ public function testExtractToFromZip() public function testDeleteFileFromZip() { $this->zipArchive->addMultipleFiles([ - 'app.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'config.php', + 'app.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'app.php', 'session.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'session.php' ]); @@ -118,7 +118,7 @@ public function testDeleteFileFromZip() public function testDeleteMultipleFilesFromZip() { $this->zipArchive->addMultipleFiles([ - 'app.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'config.php', + 'app.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'app.php', 'directoryOne/session.conf' => base_dir() . DS . 'shared' . DS . 'config' . DS . 'session.php' ]); diff --git a/tests/Unit/Libraries/Asset/AssetManagerTest.php b/tests/Unit/Libraries/Asset/AssetManagerTest.php index 964305228..45697661a 100644 --- a/tests/Unit/Libraries/Asset/AssetManagerTest.php +++ b/tests/Unit/Libraries/Asset/AssetManagerTest.php @@ -15,7 +15,7 @@ public function setUp(): void { parent::setUp(); - config()->set('base_url', 'http://mydomain.com'); + config()->set('app.base_url', 'http://mydomain.com'); $this->assetManager = AssetManager::getInstance(); } diff --git a/tests/Unit/Libraries/Asset/AssetTest.php b/tests/Unit/Libraries/Asset/AssetTest.php index a9fb160dd..7ac90ce3b 100644 --- a/tests/Unit/Libraries/Asset/AssetTest.php +++ b/tests/Unit/Libraries/Asset/AssetTest.php @@ -14,7 +14,7 @@ public function setUp(): void { parent::setUp(); - config()->set('base_url', 'http://mydomain.com'); + config()->set('app.base_url', 'http://mydomain.com'); $this->asset = new Asset(Asset::JS, 'scripts/jquery.js', 'jQuery'); diff --git a/tests/Unit/Libraries/Asset/Helpers/AssetHelperFunctionsTest.php b/tests/Unit/Libraries/Asset/Helpers/AssetHelperFunctionsTest.php index 4a1055b3d..a9587d63c 100644 --- a/tests/Unit/Libraries/Asset/Helpers/AssetHelperFunctionsTest.php +++ b/tests/Unit/Libraries/Asset/Helpers/AssetHelperFunctionsTest.php @@ -23,7 +23,7 @@ public function testAssetHelper() public function testAssetUrl() { - config()->set('base_url', 'http://mydomain.com'); + config()->set('app.base_url', 'http://mydomain.com'); $this->assertEquals('http://mydomain.com/assets/css/style.css', asset()->url('css/style.css')); diff --git a/tests/Unit/Libraries/Auth/Adapters/JwtAuthAdapterTest.php b/tests/Unit/Libraries/Auth/Adapters/JwtAuthAdapterTest.php index 98aedf7eb..ea3e3614f 100644 --- a/tests/Unit/Libraries/Auth/Adapters/JwtAuthAdapterTest.php +++ b/tests/Unit/Libraries/Auth/Adapters/JwtAuthAdapterTest.php @@ -146,11 +146,11 @@ public function testApiForgetReset() $this->assertArrayHasKey('refresh_token', $this->jwtAuth->signin('admin@qt.com', '123456789')); } - public function testApiVerify() + public function testApiVerifyOtp() { - config()->set('TWO_FA', true); + config()->set('auth.two_fa', true); - config()->set('otp_expires', 2); + config()->set('auth.otp_expires', 2); $otp_token = $this->jwtAuth->signin('admin@qt.com', 'qwerty'); @@ -163,9 +163,9 @@ public function testApiVerify() public function testApiSigninWithoutVerification() { - config()->set('TWO_FA', false); + config()->set('auth.two_fa', false); - config()->set('otp_expires', 2); + config()->set('auth.otp_expires', 2); $this->assertArrayHasKey('access_token', $this->jwtAuth->signin('admin@qt.com', 'qwerty')); @@ -174,18 +174,18 @@ public function testApiSigninWithoutVerification() public function testApiSigninWithVerification() { - config()->set('TWO_FA', true); + config()->set('auth.two_fa', true); - config()->set('otp_expires', 2); + config()->set('auth.otp_expires', 2); $this->assertIsString($this->jwtAuth->signin('admin@qt.com', 'qwerty')); } public function testApiResendOtp() { - config()->set('TWO_FA', true); + config()->set('auth.two_fa', true); - config()->set('otp_expires', 2); + config()->set('auth.otp_expires', 2); $otp_token = $this->jwtAuth->signin('admin@qt.com', 'qwerty'); diff --git a/tests/Unit/Libraries/Auth/Adapters/SessionAuthAdapterTest.php b/tests/Unit/Libraries/Auth/Adapters/SessionAuthAdapterTest.php index 06b19eaa0..8088a4701 100644 --- a/tests/Unit/Libraries/Auth/Adapters/SessionAuthAdapterTest.php +++ b/tests/Unit/Libraries/Auth/Adapters/SessionAuthAdapterTest.php @@ -124,40 +124,40 @@ public function testWebForgetReset() $this->assertTrue($this->sessionAuth->signin('admin@qt.com', '123456789')); } - public function testWebWithoutVerification() + public function testWebVerifyOtp() { - config()->set('TWO_FA', false); + config()->set('auth.two_fa', true); - config()->set('otp_expiry_time', 2); + config()->set('auth.otp_expires', 2); - $this->assertTrue($this->sessionAuth->signin('admin@qt.com', 'qwerty')); + $otp_token = $this->sessionAuth->signin('admin@qt.com', 'qwerty'); + + $this->assertTrue($this->sessionAuth->verifyOtp(123456789, $otp_token)); } - public function testWebWithVerification() + public function testWebSigninWithoutVerification() { - config()->set('TWO_FA', true); + config()->set('auth.two_fa', false); - config()->set('otp_expires', 2); + config()->set('auth.otp_expires', 2); - $this->assertIsString($this->sessionAuth->signin('admin@qt.com', 'qwerty')); + $this->assertTrue($this->sessionAuth->signin('admin@qt.com', 'qwerty')); } - public function testWebVerify() + public function testWebSigninWithVerification() { - config()->set('TWO_FA', true); - - config()->set('otp_expires', 2); + config()->set('auth.two_fa', true); - $otp_token = $this->sessionAuth->signin('admin@qt.com', 'qwerty'); + config()->set('auth.otp_expires', 2); - $this->assertTrue($this->sessionAuth->verifyOtp(123456789, $otp_token)); + $this->assertIsString($this->sessionAuth->signin('admin@qt.com', 'qwerty')); } public function testWebResendOtp() { - config()->set('TWO_FA', true); + config()->set('auth.two_fa', true); - config()->set('otp_expires', 2); + config()->set('auth.otp_expires', 2); $otp_token = $this->sessionAuth->signin('admin@qt.com', 'qwerty'); diff --git a/tests/Unit/Libraries/Database/Adapters/Idiorm/IdiormDbalTestCase.php b/tests/Unit/Libraries/Database/Adapters/Idiorm/IdiormDbalTestCase.php index b82dcceb9..2a6dae7f8 100644 --- a/tests/Unit/Libraries/Database/Adapters/Idiorm/IdiormDbalTestCase.php +++ b/tests/Unit/Libraries/Database/Adapters/Idiorm/IdiormDbalTestCase.php @@ -26,7 +26,7 @@ public function setUp(): void $this->setPrivateProperty(Database::class, 'instance', null); - config()->set('debug', true); + config()->set('app.debug', true); IdiormDbal::connect(['driver' => 'sqlite', 'database' => ':memory:']); diff --git a/tests/Unit/Libraries/Logger/Factories/LoggerFactoryTest.php b/tests/Unit/Libraries/Logger/Factories/LoggerFactoryTest.php index 2cc85d5bf..4973cdbbe 100644 --- a/tests/Unit/Libraries/Logger/Factories/LoggerFactoryTest.php +++ b/tests/Unit/Libraries/Logger/Factories/LoggerFactoryTest.php @@ -18,7 +18,7 @@ public function setUp(): void { parent::setUp(); - config()->set('debug', false); + config()->set('app.debug', false); $this->setPrivateProperty(LoggerFactory::class, 'instances', []); } @@ -59,7 +59,7 @@ public function testLoggerFactoryGetDailyAdapter() public function testLoggerFactoryGetMessageAdapter() { - config()->set('debug', true); + config()->set('app.debug', true); $logger = LoggerFactory::get(); diff --git a/tests/Unit/Libraries/Logger/Helpers/LoggerHelperFunctionsTest.php b/tests/Unit/Libraries/Logger/Helpers/LoggerHelperFunctionsTest.php index 53f1e7916..8dd53a647 100644 --- a/tests/Unit/Libraries/Logger/Helpers/LoggerHelperFunctionsTest.php +++ b/tests/Unit/Libraries/Logger/Helpers/LoggerHelperFunctionsTest.php @@ -20,7 +20,7 @@ public function setUp(): void { parent::setUp(); - config()->set('debug', true); + config()->set('app.debug', true); $store = new DebuggerStore(); @@ -36,7 +36,7 @@ public function tearDown(): void public function testLoggerHelperGetDefaultLoggerAdapter() { - config()->set('debug', false); + config()->set('app.debug', false); $logger = logger(); @@ -47,7 +47,7 @@ public function testLoggerHelperGetDefaultLoggerAdapter() public function testLoggerHelperGetSingleLoggerAdapter() { - config()->set('debug', false); + config()->set('app.debug', false); $logger = logger(Logger::SINGLE); @@ -58,7 +58,7 @@ public function testLoggerHelperGetSingleLoggerAdapter() public function testLoggerHelperGetDailyLoggerAdapter() { - config()->set('debug', false); + config()->set('app.debug', false); $logger = logger(Logger::DAILY); @@ -78,7 +78,7 @@ public function testLoggerHelperGetMessageLoggerAdapter() public function testLoggerHelperTryToGetMessageLoggerAdapterInNonDebugMode() { - config()->set('debug', false); + config()->set('app.debug', false); $this->expectException(LoggerException::class); diff --git a/tests/Unit/Libraries/Mailer/Adapters/MailgunAdapterTest.php b/tests/Unit/Libraries/Mailer/Adapters/MailgunAdapterTest.php index bc282b30a..a8afd36dc 100644 --- a/tests/Unit/Libraries/Mailer/Adapters/MailgunAdapterTest.php +++ b/tests/Unit/Libraries/Mailer/Adapters/MailgunAdapterTest.php @@ -2,15 +2,14 @@ namespace Quantum\Tests\Unit\Libraries\Mailer\Adapters; -use Quantum\Libraries\Storage\Factories\FileSystemFactory; +use Quantum\Tests\Unit\Libraries\Mailer\MailerTestCase; use Quantum\Libraries\Mailer\Contracts\MailerInterface; use Quantum\Libraries\Mailer\Adapters\MailgunAdapter; -use Quantum\Tests\Unit\AppTestCase; -class MailgunAdapterTest extends AppTestCase +class MailgunAdapterTest extends MailerTestCase { - private $adapter; + protected $adapter; public function setUp(): void { @@ -24,19 +23,6 @@ public function setUp(): void $this->adapter = new MailgunAdapter($config); } - public function tearDown(): void - { - parent::tearDown(); - - $fs = FileSystemFactory::get(); - - $emailFile = base_dir() . DS . 'shared' . DS . 'emails' . DS . $this->adapter->getMessageId() . '.eml'; - - if($fs->exists($emailFile)) { - $fs->remove($emailFile); - } - } - public function testMailgunAdapterInstance() { $this->assertInstanceOf(MailgunAdapter::class, $this->adapter); diff --git a/tests/Unit/Libraries/Mailer/Adapters/MandrillAdapterTest.php b/tests/Unit/Libraries/Mailer/Adapters/MandrillAdapterTest.php index 683869e5f..e69ee078e 100644 --- a/tests/Unit/Libraries/Mailer/Adapters/MandrillAdapterTest.php +++ b/tests/Unit/Libraries/Mailer/Adapters/MandrillAdapterTest.php @@ -2,15 +2,14 @@ namespace Quantum\Tests\Unit\Libraries\Mailer\Adapters; -use Quantum\Libraries\Storage\Factories\FileSystemFactory; +use Quantum\Tests\Unit\Libraries\Mailer\MailerTestCase; use Quantum\Libraries\Mailer\Contracts\MailerInterface; use Quantum\Libraries\Mailer\Adapters\MandrillAdapter; -use Quantum\Tests\Unit\AppTestCase; -class MandrillAdapterTest extends AppTestCase +class MandrillAdapterTest extends MailerTestCase { - private $adapter; + protected $adapter; public function setUp(): void { @@ -19,19 +18,6 @@ public function setUp(): void $this->adapter = new MandrillAdapter(['api_key' => 'xxx111222333']); } - public function tearDown(): void - { - parent::tearDown(); - - $fs = FileSystemFactory::get(); - - $emailFile = base_dir() . DS . 'shared' . DS . 'emails' . DS . $this->adapter->getMessageId() . '.eml'; - - if($fs->exists($emailFile)) { - $fs->remove($emailFile); - } - } - public function testMandrillAdapterInstance() { $this->assertInstanceOf(MandrillAdapter::class, $this->adapter); diff --git a/tests/Unit/Libraries/Mailer/Adapters/SendgridAdapterTest.php b/tests/Unit/Libraries/Mailer/Adapters/SendgridAdapterTest.php index 280ba9bd8..6eddc4f07 100644 --- a/tests/Unit/Libraries/Mailer/Adapters/SendgridAdapterTest.php +++ b/tests/Unit/Libraries/Mailer/Adapters/SendgridAdapterTest.php @@ -2,15 +2,14 @@ namespace Quantum\Tests\Unit\Libraries\Mailer\Adapters; -use Quantum\Libraries\Storage\Factories\FileSystemFactory; +use Quantum\Tests\Unit\Libraries\Mailer\MailerTestCase; use Quantum\Libraries\Mailer\Contracts\MailerInterface; use Quantum\Libraries\Mailer\Adapters\SendgridAdapter; -use Quantum\Tests\Unit\AppTestCase; -class SendgridAdapterTest extends AppTestCase +class SendgridAdapterTest extends MailerTestCase { - private $adapter; + protected $adapter; public function setUp(): void { @@ -19,19 +18,6 @@ public function setUp(): void $this->adapter = new SendgridAdapter(['api_key' => 'xxx111222333']); } - public function tearDown(): void - { - parent::tearDown(); - - $fs = FileSystemFactory::get(); - - $emailFile = base_dir() . DS . 'shared' . DS . 'emails' . DS . $this->adapter->getMessageId() . '.eml'; - - if($fs->exists($emailFile)) { - $fs->remove($emailFile); - } - } - public function testSendgridAdapterInstance() { $this->assertInstanceOf(SendgridAdapter::class, $this->adapter); diff --git a/tests/Unit/Libraries/Mailer/Adapters/SendinblueAdapterTest.php b/tests/Unit/Libraries/Mailer/Adapters/SendinblueAdapterTest.php index 7b273cd9a..751b0f424 100644 --- a/tests/Unit/Libraries/Mailer/Adapters/SendinblueAdapterTest.php +++ b/tests/Unit/Libraries/Mailer/Adapters/SendinblueAdapterTest.php @@ -2,15 +2,14 @@ namespace Quantum\Tests\Unit\Libraries\Mailer\Adapters; -use Quantum\Libraries\Storage\Factories\FileSystemFactory; use Quantum\Libraries\Mailer\Adapters\SendinblueAdapter; +use Quantum\Tests\Unit\Libraries\Mailer\MailerTestCase; use Quantum\Libraries\Mailer\Contracts\MailerInterface; -use Quantum\Tests\Unit\AppTestCase; -class SendinblueAdapterTest extends AppTestCase +class SendinblueAdapterTest extends MailerTestCase { - private $adapter; + protected $adapter; public function setUp(): void { @@ -19,19 +18,6 @@ public function setUp(): void $this->adapter = new SendinblueAdapter(['api_key' => 'xxx111222333']); } - public function tearDown(): void - { - parent::tearDown(); - - $fs = FileSystemFactory::get(); - - $emailFile = base_dir() . DS . 'shared' . DS . 'emails' . DS . $this->adapter->getMessageId() . '.eml'; - - if($fs->exists($emailFile)) { - $fs->remove($emailFile); - } - } - public function testSendinblueAdapterInstance() { $this->assertInstanceOf(SendinblueAdapter::class, $this->adapter); diff --git a/tests/Unit/Libraries/Mailer/Adapters/SmtpAdapterTest.php b/tests/Unit/Libraries/Mailer/Adapters/SmtpAdapterTest.php index 23fd371fd..cd9814477 100644 --- a/tests/Unit/Libraries/Mailer/Adapters/SmtpAdapterTest.php +++ b/tests/Unit/Libraries/Mailer/Adapters/SmtpAdapterTest.php @@ -2,16 +2,15 @@ namespace Quantum\Tests\Unit\Libraries\Mailer\Adapters; -use Quantum\Libraries\Storage\Factories\FileSystemFactory; +use Quantum\Tests\Unit\Libraries\Mailer\MailerTestCase; use Quantum\Libraries\Mailer\Contracts\MailerInterface; use Quantum\Libraries\Mailer\Adapters\SmtpAdapter; -use Quantum\Tests\Unit\AppTestCase; use Quantum\Loader\Setup; -class SmtpAdapterTest extends AppTestCase +class SmtpAdapterTest extends MailerTestCase { - private $adapter; + protected $adapter; public function setUp(): void { @@ -24,19 +23,6 @@ public function setUp(): void $this->adapter = new SmtpAdapter(config()->get('mailer.smtp')); } - public function tearDown(): void - { - parent::tearDown(); - - $fs = FileSystemFactory::get(); - - $emailFile = base_dir() . DS . 'shared' . DS . 'emails' . DS . $this->adapter->getMessageId() . '.eml'; - - if($fs->exists($emailFile)) { - $fs->remove($emailFile); - } - } - public function testSmtpAdapterInstance() { $this->assertInstanceOf(SmtpAdapter::class, $this->adapter); diff --git a/tests/Unit/Libraries/Mailer/MailerTestCase.php b/tests/Unit/Libraries/Mailer/MailerTestCase.php new file mode 100644 index 000000000..776a9b761 --- /dev/null +++ b/tests/Unit/Libraries/Mailer/MailerTestCase.php @@ -0,0 +1,30 @@ + \Quantum\Loader\Loader::class, + \Quantum\Http\Request::class => \Quantum\Http\Request::class, + \Quantum\Http\Response::class => \Quantum\Http\Response::class, + ]; + + Di::registerDependencies($coreDependencies); + + $emailFile = base_dir() . DS . 'shared' . DS . 'emails' . DS . $this->adapter->getMessageId() . '.eml'; + + if($this->fs->exists($emailFile)) { + $this->fs->remove($emailFile); + } + + Di::reset(); + } +} \ No newline at end of file diff --git a/tests/Unit/Loader/LoaderTest.php b/tests/Unit/Loader/LoaderTest.php index fb8679686..1af46eb36 100644 --- a/tests/Unit/Loader/LoaderTest.php +++ b/tests/Unit/Loader/LoaderTest.php @@ -20,11 +20,11 @@ public function setUp(): void public function testSetupAndLoad() { - $this->loader->setup(new Setup('config', 'config')); + $this->loader->setup(new Setup('config', 'app')); $content = $this->loader->load(); - $this->assertEquals(base_dir() . DS . 'shared' . DS . 'config' . DS . 'config.php', $this->loader->getFilePath()); + $this->assertEquals(base_dir() . DS . 'shared' . DS . 'config' . DS . 'app.php', $this->loader->getFilePath()); $this->assertIsArray($content); } diff --git a/tests/Unit/Model/ModelSoftDeletesIdiOrm.php b/tests/Unit/Model/ModelSoftDeletesIdiOrm.php index 4b5f37346..3c6a65753 100644 --- a/tests/Unit/Model/ModelSoftDeletesIdiOrm.php +++ b/tests/Unit/Model/ModelSoftDeletesIdiOrm.php @@ -18,7 +18,7 @@ public function setUp(): void { parent::setUp(); - config()->set('debug', true); + config()->set('app.debug', true); IdiormDbal::connect(['driver' => 'sqlite', 'database' => ':memory:']); diff --git a/tests/Unit/Model/QtModelTest.php b/tests/Unit/Model/QtModelTest.php index 5d3533c41..bb1df3740 100644 --- a/tests/Unit/Model/QtModelTest.php +++ b/tests/Unit/Model/QtModelTest.php @@ -21,7 +21,7 @@ public function setUp(): void { parent::setUp(); - config()->set('debug', true); + config()->set('app.debug', true); IdiormDbal::connect(['driver' => 'sqlite', 'database' => ':memory:']); diff --git a/tests/_root/shared/config/app.php b/tests/_root/shared/config/app.php new file mode 100644 index 000000000..b9359e04f --- /dev/null +++ b/tests/_root/shared/config/app.php @@ -0,0 +1,10 @@ + 'Quantum PHP Framework', + 'version' => '2.9.5', + 'key' => env('APP_KEY'), + 'base_url' => 'http://localhost', + 'debug' => true, + 'test' => 'Testing', +]; \ No newline at end of file diff --git a/tests/_root/shared/config/auth.php b/tests/_root/shared/config/auth.php index 4e6743548..a7b879e78 100644 --- a/tests/_root/shared/config/auth.php +++ b/tests/_root/shared/config/auth.php @@ -17,5 +17,8 @@ 'nbf' => time() + 1, 'exp' => time() + 3600 // 1 hour ] - ] + ], + + 'two_fa' => env('TWO_FA', true), + 'otp_expires' => 2, ]; diff --git a/tests/_root/shared/config/config.php b/tests/_root/shared/config/config.php deleted file mode 100644 index ac79d3d3e..000000000 --- a/tests/_root/shared/config/config.php +++ /dev/null @@ -1,12 +0,0 @@ - 'Quantum PHP Framework', - 'app_version' => '2.9.5', - 'app_key' => env('APP_KEY'), - 'langs' => ['en', 'es', 'fr'], - 'lang_default' => 'en', - 'lang_segment' => 1, - 'debug' => true, - 'test' => 'Testing', -]; \ No newline at end of file