From 6545df1de834f02cb1723ca0f4ec4dcf7df352bb Mon Sep 17 00:00:00 2001 From: Vahram Date: Thu, 31 Oct 2024 13:10:25 +0400 Subject: [PATCH 01/10] creating feature tests --- composer.json | 5 + phpunit.xml | 22 +- tests/Feature/Api/AuthControllerTest.php | 222 ++++++++++++++++ tests/Feature/BaseTestCase.php | 71 +++++ tests/Feature/_root/.env.testing | 30 +++ .../modules/test/Resources/lang/en/custom.php | 7 + .../_root/modules/test/Views/index.php | 1 + .../_root/modules/test/Views/layout.php | 6 + .../_root/modules/test/Views/partial.php | 1 + tests/Feature/_root/public/uploads/.gitkeep | 1 + tests/Feature/_root/shared/config/captcha.php | 17 ++ tests/Feature/_root/shared/config/config.php | 9 + .../Feature/_root/shared/config/database.php | 34 +++ .../_root/shared/config/dependencies.php | 5 + tests/Feature/_root/shared/config/env.php | 5 + tests/Feature/_root/shared/config/hooks.php | 5 + tests/Feature/_root/shared/config/mailer.php | 32 +++ tests/Feature/_root/shared/config/modules.php | 17 ++ tests/Feature/_root/shared/config/session.php | 7 + tests/Feature/_root/shared/store/.gitkeep | 1 + tests/Feature/_root/tmp/php8fe1.tmp | Bin 0 -> 9113 bytes tests/Unit/AuthServiceTest.php | 137 ++++++++++ tests/Unit/PostServiceTest.php | 249 ++++++++++++++++++ tests/Unit/_root/public/uploads/.gitkeep | 1 + tests/Unit/_root/shared/config/database.php | 57 ++++ .../Unit/_root/shared/config/dependencies.php | 5 + tests/Unit/_root/shared/store/.gitkeep | 1 + tests/Unit/_root/tmp/php8fe1.tmp | Bin 0 -> 9113 bytes tests/bootstrap.php | 7 - 29 files changed, 941 insertions(+), 14 deletions(-) create mode 100644 tests/Feature/Api/AuthControllerTest.php create mode 100644 tests/Feature/BaseTestCase.php create mode 100644 tests/Feature/_root/.env.testing create mode 100644 tests/Feature/_root/modules/test/Resources/lang/en/custom.php create mode 100644 tests/Feature/_root/modules/test/Views/index.php create mode 100644 tests/Feature/_root/modules/test/Views/layout.php create mode 100644 tests/Feature/_root/modules/test/Views/partial.php create mode 100644 tests/Feature/_root/public/uploads/.gitkeep create mode 100644 tests/Feature/_root/shared/config/captcha.php create mode 100644 tests/Feature/_root/shared/config/config.php create mode 100644 tests/Feature/_root/shared/config/database.php create mode 100644 tests/Feature/_root/shared/config/dependencies.php create mode 100644 tests/Feature/_root/shared/config/env.php create mode 100644 tests/Feature/_root/shared/config/hooks.php create mode 100644 tests/Feature/_root/shared/config/mailer.php create mode 100644 tests/Feature/_root/shared/config/modules.php create mode 100644 tests/Feature/_root/shared/config/session.php create mode 100644 tests/Feature/_root/shared/store/.gitkeep create mode 100644 tests/Feature/_root/tmp/php8fe1.tmp create mode 100644 tests/Unit/AuthServiceTest.php create mode 100644 tests/Unit/PostServiceTest.php create mode 100644 tests/Unit/_root/public/uploads/.gitkeep create mode 100644 tests/Unit/_root/shared/config/database.php create mode 100644 tests/Unit/_root/shared/config/dependencies.php create mode 100644 tests/Unit/_root/shared/store/.gitkeep create mode 100644 tests/Unit/_root/tmp/php8fe1.tmp delete mode 100644 tests/bootstrap.php diff --git a/composer.json b/composer.json index 2f0ffbc..01cfdb9 100644 --- a/composer.json +++ b/composer.json @@ -20,6 +20,11 @@ "Shared\\": "shared" } }, + "autoload-dev": { + "psr-4": { + "Tests\\": "tests/" + } + }, "scripts": { "post-create-project-cmd": [ "php qt core:env", diff --git a/phpunit.xml b/phpunit.xml index 798dbe0..570e937 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -1,11 +1,19 @@ - + - - ./tests - + + ./tests/Feature + + + + \ No newline at end of file diff --git a/tests/Feature/Api/AuthControllerTest.php b/tests/Feature/Api/AuthControllerTest.php new file mode 100644 index 0000000..e4de84b --- /dev/null +++ b/tests/Feature/Api/AuthControllerTest.php @@ -0,0 +1,222 @@ +request('post', '/api/en/signin', [ + 'email' => $this->email, + 'password' => $this->password + ]); + + $this->assertIsObject($response); + $this->assertEquals('success', $response->get('status')); + $this->assertArrayHasKey('tokens', $response->all()); + } + + public function testSignInWithIncorrectRequestApi() + { + $response = $this->request('post', '/api/en/signin', [ + 'email' => 'test@email.com', + 'password' => 'password' + ]); + + $this->assertIsObject($response); + $this->assertEquals('error', $response->get('status')); + $this->assertEquals('Incorrect credentials', $response->get('message')); + } + + public function testMeApi() + { + $this->loadAppFunctionality(); + Router::setCurrentRoute([ + 'route' => '/api/en/signin', + 'prefix' => 'api', + 'method' => 'POST', + 'module' => 'Api', + ]); + $tokens = auth()->signin($this->email, $this->password); + + $response = $this->request('get', '/api/en/me', [], ['Authorization' => 'Bearer ' . $tokens['access_token']]); + + $this->assertIsObject($response); + $this->assertEquals('success', $response->get('status')); + $this->assertIsArray($response->all()); + $this->assertArrayHasKey('data', $response->all()); + $this->assertIsArray($response->get('data')); + $this->assertArrayHasKey('firstname', $response->get('data')); + $this->assertArrayHasKey('lastname', $response->get('data')); + $this->assertArrayHasKey('email', $response->get('data')); + } + + public function testMeIncorrectApi() + { + $response = $this->request('get', '/api/en/me'); + + $this->assertIsObject($response); + $this->assertEquals('error', $response->get('status')); + $this->assertEquals('Unauthorized request', $response->get('message')); + } + + public function testSignoutApi() + { + $this->loadAppFunctionality(); + Router::setCurrentRoute([ + 'route' => '/api/en/signin', + 'prefix' => 'api', + 'method' => 'POST', + 'module' => 'Api', + ]); + $tokens = auth()->signin($this->email, $this->password); + + $response = $this->request('get', '/api/en/signout', [], [ + 'Authorization' => 'Bearer ' . $tokens['access_token'], + 'refresh_token' => $tokens['refresh_token'] + ]); + + $this->assertEquals('success', $response->get('status')); + } + + public function testForgetApi() + { + $response = $this->request('post', '/api/en/forget', ['email' => $this->email]); + + $this->assertEquals('success', $response->get('status')); + $this->assertEquals('Check your email to reset your password', $response->get('message')); + } + + public function testSignupApi() + { + $response = $this->request('post', '/api/en/signup', [ + 'email' => 'test@email.com', + 'password' => $this->password, + 'firstname' => 'firstname', + 'lastname' => 'lastname' + ]); + + $this->assertEquals('success', $response->get('status')); + $this->assertEquals('Successfully signed up', $response->get('message')); + + ModelFactory::get(User::class)->findOneBy('email', 'test@email.com')->delete(); + } + + public function testSignupIncorrectApi() + { + $response = $this->request('post', '/api/en/signup', [ + 'email' => $this->email, + 'password' => $this->password, + 'firstname' => 'firstname', + 'lastname' => 'lastname' + ]); + + $this->assertEquals('error', $response->get('status')); + $this->assertEquals('The value of Email field is already exists in our database', $response->get('message')['email'][0]); + } + + public function testActivateApi() + { + $this->loadAppFunctionality(); + $userModel = ModelFactory::get(User::class)->create(); + $activationToken = base64_encode((new Hasher())->hash('password')); + $userModel->fillObjectProps([ + 'email' => $this->email, + 'password' => (new Hasher())->hash($this->password), + 'firstname' => 'firstname', + 'lastname' => 'lastname', + 'activation_token' => $activationToken + ]); + $userModel->save(); + + $response = $this->request('get', '/api/en/activate/'. $activationToken); + + $this->assertEquals('success', $response->get('status')); + $this->assertEquals('Account is activated', $response->get('message')); + } + + public function testActivateIncorrectApi() + { + $response = $this->request('get', '/api/en/activate/incorrect-activation-token'); + + $this->assertEquals('error', $response->get('status')); + $this->assertEquals('There is no record matched to token', $response->get('message')[0]); + } + + public function testResetApi() + { + $this->loadAppFunctionality(); + $userModel = ModelFactory::get(User::class)->create(); + $resetToken = base64_encode((new Hasher())->hash('password')); + $userModel->fillObjectProps([ + 'email' => $this->email, + 'password' => (new Hasher())->hash($this->password), + 'firstname' => 'firstname', + 'lastname' => 'lastname', + 'reset_token' => $resetToken + ]); + $userModel->save(); + + $response = $this->request('post', '/api/en/reset/'. $resetToken, [ + 'password' => $this->password, + 'repeat_password' => $this->password, + ]); + + $this->assertEquals('success', $response->get('status')); + } + + public function testResetIncorrectApi() + { + $response = $this->request('post', '/api/en/reset/incorrect-activation-token'); + + $this->assertEquals('error', $response->get('status')); + $this->assertEquals('There is no record matched to token', $response->get('message')[0]); + } + + public function testResendApi() + { + $this->loadAppFunctionality(); + $userModel = ModelFactory::get(User::class)->create(); + $otpToken = base64_encode((new Hasher())->hash($this->email)); + $userModel->fillObjectProps([ + 'email' => $this->email, + 'password' => (new Hasher())->hash($this->password), + 'firstname' => 'firstname', + 'lastname' => 'lastname', + 'otp_token' => $otpToken + ]); + $userModel->save(); + $response = $this->request('get', '/api/en/resend/'. $otpToken); + + $this->assertEquals('success', $response->get('status')); + $this->assertArrayHasKey('code', $response->all()); + $this->assertIsString($response->get('code')); + } + + public function testResendIncorrectApi() + { + $response = $this->request('get', '/api/en/resend/incorrect-otp-token'); + + $this->assertEquals('error', $response->get('status')); + $this->assertEquals('Incorrect credentials', $response->get('message')); + } + + public function tearDown(): void + { + parent::tearDown(); + } +} \ No newline at end of file diff --git a/tests/Feature/BaseTestCase.php b/tests/Feature/BaseTestCase.php new file mode 100644 index 0000000..bbe5bad --- /dev/null +++ b/tests/Feature/BaseTestCase.php @@ -0,0 +1,71 @@ + $value) { + $_SERVER['HTTP_' . strtoupper($name)] = $value; + Request::setHeader($name, $value); + } + } + + Request::create(strtoupper($method), $url, $options); + + Config::getInstance()->flush(); + App::start(dirname(__DIR__, 2)); + + return new Response(); + } + + public function tearDown(): void + { + parent::tearDown(); + ob_end_clean(); + } + + protected function loadAppFunctionality() + { + App::setBaseDir(dirname(__DIR__, 2)); + App::loadCoreFunctions(dirname(__DIR__, 2) . DS . 'vendor' . DS . 'quantum' . DS . 'framework' . DS . 'src' . DS . 'Helpers'); + Di::loadDefinitions(); + Environment::getInstance()->load(new Setup('config', 'env')); + } +} + diff --git a/tests/Feature/_root/.env.testing b/tests/Feature/_root/.env.testing new file mode 100644 index 0000000..a11d766 --- /dev/null +++ b/tests/Feature/_root/.env.testing @@ -0,0 +1,30 @@ +APP_KEY=d88d33ea128f578776c6342731c72e8e486b3b59f5fdaac60ff4b527ff4071c4 +APP_NAME="Quantum PHP Framework" +APP_VERSION=2.9 +DB_DRIVER=mysql +DB_HOST=localhost +DB_NAME=quantum +DB_USERNAME=root +DB_PASSWORD= +2FA=false +DEBUG=true +APP_URL= + +MAIL_HOST= +MAIL_SMTP_SECURE= +MAIL_PORT= +MAIL_USERNAME= +MAIL_PASSWORD= + +#Sendinblue +SENDINBLUE_APIKEY= + +#Sendgrid +SENDGRID_APIKEY= + +#Mailgun +MAILGUN_APIKEY= +MAILGUN_DOMAIN= + +#Mandrill +MANDRILL_APIKEY= \ No newline at end of file diff --git a/tests/Feature/_root/modules/test/Resources/lang/en/custom.php b/tests/Feature/_root/modules/test/Resources/lang/en/custom.php new file mode 100644 index 0000000..4ce07e6 --- /dev/null +++ b/tests/Feature/_root/modules/test/Resources/lang/en/custom.php @@ -0,0 +1,7 @@ + 'Learn more', + 'info' => 'Information about the {%1} feature', + 'test' => 'Testing' +]; \ No newline at end of file diff --git a/tests/Feature/_root/modules/test/Views/index.php b/tests/Feature/_root/modules/test/Views/index.php new file mode 100644 index 0000000..d2b6b20 --- /dev/null +++ b/tests/Feature/_root/modules/test/Views/index.php @@ -0,0 +1 @@ +

Hello , this is rendered view

\ No newline at end of file diff --git a/tests/Feature/_root/modules/test/Views/layout.php b/tests/Feature/_root/modules/test/Views/layout.php new file mode 100644 index 0000000..e119b46 --- /dev/null +++ b/tests/Feature/_root/modules/test/Views/layout.php @@ -0,0 +1,6 @@ + + + + + + diff --git a/tests/Feature/_root/modules/test/Views/partial.php b/tests/Feature/_root/modules/test/Views/partial.php new file mode 100644 index 0000000..12adce2 --- /dev/null +++ b/tests/Feature/_root/modules/test/Views/partial.php @@ -0,0 +1 @@ +

Hello , this is rendered partial view

\ No newline at end of file diff --git a/tests/Feature/_root/public/uploads/.gitkeep b/tests/Feature/_root/public/uploads/.gitkeep new file mode 100644 index 0000000..256c7f2 --- /dev/null +++ b/tests/Feature/_root/public/uploads/.gitkeep @@ -0,0 +1 @@ +#qt diff --git a/tests/Feature/_root/shared/config/captcha.php b/tests/Feature/_root/shared/config/captcha.php new file mode 100644 index 0000000..d088f37 --- /dev/null +++ b/tests/Feature/_root/shared/config/captcha.php @@ -0,0 +1,17 @@ + 'recaptcha', + + 'recaptcha' => [ + 'type' => 'visible', + 'secret_key' => '10000000-ffff-ffff-ffff-000000000001', + 'site_key' => '0x0000000000000000000000000000000000000000' + ], + + 'hcaptcha' => [ + 'type' => 'visible', + 'secret_key' => '0xE1a02fB374Bf228678E613645295A2d0fD0Dc5Fa', + 'site_key' => '07737dfc-abfa-44e3-a695-66ac44365d0c' + ] +]; diff --git a/tests/Feature/_root/shared/config/config.php b/tests/Feature/_root/shared/config/config.php new file mode 100644 index 0000000..7c20fa1 --- /dev/null +++ b/tests/Feature/_root/shared/config/config.php @@ -0,0 +1,9 @@ + ['en', 'es', 'fr'], + 'lang_default' => 'en', + 'lang_segment' => 1, + 'debug' => 'DEBUG', + 'test' => 'Testing' +]; \ No newline at end of file diff --git a/tests/Feature/_root/shared/config/database.php b/tests/Feature/_root/shared/config/database.php new file mode 100644 index 0000000..a6cd325 --- /dev/null +++ b/tests/Feature/_root/shared/config/database.php @@ -0,0 +1,34 @@ + 'mysql', + 'mysql' => [ + 'driver' => 'mysql', + 'host' => 'localhost', + 'dbname' => 'database', + 'username' => 'username', + 'password' => 'password', + 'charset' => 'charset', + 'orm' => \Quantum\Libraries\Database\Idiorm\IdiormDbal::class + ], + 'sqlite' => [ + 'driver' => 'sqlite', + 'database' => ':memory:', + 'orm' => \Quantum\Libraries\Database\Idiorm\IdiormDbal::class + ], + 'sleekdb' => [ + 'config' => [ + 'auto_cache' => true, + 'cache_lifetime' => null, + 'timeout' => false, + 'search' => [ + 'min_length' => 2, + 'mode' => 'or', + 'score_key' => 'scoreKey', + 'algorithm' => 1 + ], + ], + 'database_dir' => base_dir() . DS . 'shared' . DS . 'store', + 'orm' => \Quantum\Libraries\Database\Sleekdb\SleekDbal::class + ] +]; \ No newline at end of file diff --git a/tests/Feature/_root/shared/config/dependencies.php b/tests/Feature/_root/shared/config/dependencies.php new file mode 100644 index 0000000..c29cc1c --- /dev/null +++ b/tests/Feature/_root/shared/config/dependencies.php @@ -0,0 +1,5 @@ + 'testing' +]; \ No newline at end of file diff --git a/tests/Feature/_root/shared/config/hooks.php b/tests/Feature/_root/shared/config/hooks.php new file mode 100644 index 0000000..293a655 --- /dev/null +++ b/tests/Feature/_root/shared/config/hooks.php @@ -0,0 +1,5 @@ + 'smtp', + + 'mail_trap' => true, + + 'smtp' => [ + 'host' => '127.0.0.1', + 'secure' => 'ssl', + 'port' => '80', + 'username' => 'test', + 'password' => 'test' + ], + + 'sendinblue' => [ + 'api_key' => 'sendinblue_api_key', + ], + + 'sendgrid' => [ + 'api_key' => 'sendgrid_api_key', + ], + + 'mandrill' => [ + 'api_key' => 'mandrill_api_key' + ], + + 'mailgun' => [ + 'api_key' => 'mailgun_api_key', + 'domain' => 'mailgun_domain', + ], +]; diff --git a/tests/Feature/_root/shared/config/modules.php b/tests/Feature/_root/shared/config/modules.php new file mode 100644 index 0000000..21943ab --- /dev/null +++ b/tests/Feature/_root/shared/config/modules.php @@ -0,0 +1,17 @@ + [ + 'Api' => [ + 'prefix' => 'api', + 'enabled' => true, + ], + ] +]; diff --git a/tests/Feature/_root/shared/config/session.php b/tests/Feature/_root/shared/config/session.php new file mode 100644 index 0000000..9fd9b59 --- /dev/null +++ b/tests/Feature/_root/shared/config/session.php @@ -0,0 +1,7 @@ + 'sessions', + 'driver' => 'file', + 'timeout' => 300, +]; \ No newline at end of file diff --git a/tests/Feature/_root/shared/store/.gitkeep b/tests/Feature/_root/shared/store/.gitkeep new file mode 100644 index 0000000..256c7f2 --- /dev/null +++ b/tests/Feature/_root/shared/store/.gitkeep @@ -0,0 +1 @@ +#qt diff --git a/tests/Feature/_root/tmp/php8fe1.tmp b/tests/Feature/_root/tmp/php8fe1.tmp new file mode 100644 index 0000000000000000000000000000000000000000..e134ce2d6ce4ab2c8b6e73f5a829a06344a22025 GIT binary patch literal 9113 zcmd6M2UL^I*6vG3kt$tk=$Oz!q)H3Dgx-~sP^1?X5Kt)sp@x=#QbR9FF9H@okRl%t zdQrMGkuIQegZ}q^|2h9Tcdfhrb=SRjK^3!2K(U`h{u0j$Q}RSp|KN+g za5=g9dE)1I;4!bKM<9L;zuU!5uE4#_Oz2@S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iceTest.php new file mode 100644 index 0000000..ad6e1cb --- /dev/null +++ b/tests/Unit/AuthServiceTest.php @@ -0,0 +1,137 @@ + 'anonymous@qt.com', + 'password' => '$2y$12$4Y4/1a4308KEiGX/xo6vgO41szJuDHC7KhpG5nknx/xxnLZmvMyGi', + 'firstname' => 'Tom', + 'lastname' => 'Hunter', + 'role' => 'admin', + 'activation_token' => '', + 'remember_token' => '', + 'reset_token' => '', + 'access_token' => '', + 'refresh_token' => '', + 'otp' => '', + 'otp_expires' => '', + 'otp_token' => '', + ]; + + public function setUp(): void + { + App::loadCoreFunctions(dirname(__DIR__, 2) . DS . 'vendor' . DS . 'quantum' . DS . 'framework' . DS . 'src' . DS . 'Helpers'); + + App::setBaseDir(__DIR__ . DS . '_root'); + + Di::loadDefinitions(); + + $this->authService = ServiceFactory::get(AuthService::class, ['shared' . DS . 'store', 'users']); + + $this->authService->add($this->initialUser); + } + + public function tearDown(): void + { + $this->authService->deleteTable(); + $this->removeFolders(); + } + + public function testUserGet() + { + $user = $this->authService->get('email', 'anonymous@qt.com'); + + $this->assertInstanceOf(\Quantum\Libraries\Auth\User::class, $user); + $this->assertArrayHasKey('password', $user->getData()); + $this->assertArrayHasKey('firstname', $user->getData()); + $this->assertArrayHasKey('lastname', $user->getData()); + $this->assertArrayHasKey('role', $user->getData()); + $this->assertArrayHasKey('remember_token', $user->getData()); + $this->assertArrayHasKey('reset_token', $user->getData()); + $this->assertEquals('admin', $user->getFieldValue('role')); + } + + public function testUserGetById() + { + $user = $this->authService->get('id', 1); + + $this->assertInstanceOf(\Quantum\Libraries\Auth\User::class, $user); + + $userData = $user->getData(); + + $this->assertIsArray($userData); + } + + public function testUserAdd() + { + $user = $this->authService->add([ + 'email' => 'guest@qt.com', + 'password' => '$2y$12$0M78WcmUZYQq85vHZLoNW.CyDUezRxh9Ye8/Z8oWCwJmBrz8p.j7C', + 'firstname' => 'Guest', + 'lastname' => 'User', + ]); + + $this->assertInstanceOf(\Quantum\Libraries\Auth\User::class, $user); + $this->assertArrayHasKey('email', $user->getData()); + $this->assertEquals('guest@qt.com', $user->getFieldValue('email')); + } + + public function testUserUpdate() + { + $user = $this->authService->get('email', 'anonymous@qt.com'); + + $this->assertEmpty($user->getFieldValue('remember_token')); + + $rememberToken = base64_encode(time()); + + $this->authService->update( + 'email', + $user->getFieldValue('email'), + ['remember_token' => $rememberToken] + ); + + $user = $this->authService->get('email', 'anonymous@qt.com'); + + $this->assertNotEmpty($user->getFieldValue('remember_token')); + $this->assertEquals($user->getFieldValue('remember_token'), $rememberToken); + } + + public function testUserSchema() + { + $this->assertIsArray($this->authService->userSchema()); + $this->assertArrayHasKey('username', $this->authService->userSchema()); + $this->assertArrayHasKey('password', $this->authService->userSchema()); + $this->assertArrayHasKey('activationToken', $this->authService->userSchema()); + $this->assertArrayHasKey('rememberToken', $this->authService->userSchema()); + $this->assertArrayHasKey('resetToken', $this->authService->userSchema()); + $this->assertArrayHasKey('accessToken', $this->authService->userSchema()); + $this->assertArrayHasKey('refreshToken', $this->authService->userSchema()); + $this->assertArrayHasKey('otp', $this->authService->userSchema()); + $this->assertArrayHasKey('otpExpiry', $this->authService->userSchema()); + $this->assertArrayHasKey('otpToken', $this->authService->userSchema()); + $this->assertIsArray($this->authService->userSchema()['username']); + $this->assertArrayHasKey('name', $this->authService->userSchema()['username']); + $this->assertArrayHasKey('visible', $this->authService->userSchema()['username']); + } + + private function removeFolders() + { + $fs = Di::get(FileSystem::class); + + $uploadsFolder = $fs->glob(uploads_dir() . DS . '*'); + + foreach ($uploadsFolder as $folder) { + $fs->removeDirectory($folder); + } + } +} diff --git a/tests/Unit/PostServiceTest.php b/tests/Unit/PostServiceTest.php new file mode 100644 index 0000000..1596466 --- /dev/null +++ b/tests/Unit/PostServiceTest.php @@ -0,0 +1,249 @@ + 'anonymous@qt.com', + 'password' => '$2y$12$4Y4/1a4308KEiGX/xo6vgO41szJuDHC7KhpG5nknx/xxnLZmvMyGi', + 'firstname' => 'Tom', + 'lastname' => 'Hunter', + 'role' => 'admin', + 'activation_token' => '', + 'remember_token' => '', + 'reset_token' => '', + 'access_token' => '', + 'refresh_token' => '', + 'otp' => '', + 'otp_expires' => '', + 'otp_token' => '', + ]; + private $initialPosts = [ + [ + 'user_id' => 1, + 'title' => 'Walt Disney', + 'content' => 'The way to get started is to quit talking and begin doing.', + 'image' => '', + 'updated_at' => '2021-05-08 23:11:00', + ], + [ + 'user_id' => 1, + 'title' => 'Lorem ipsum dolor sit amet', + 'content' => 'Praesent hendrerit lobortis malesuada. Proin bibendum lacinia nunc ac aliquet.', + 'image' => '', + 'updated_at' => '2021-05-08 23:12:00', + ], + [ + 'user_id' => 1, + 'title' => 'Aenean dui turpis', + 'content' => 'Etiam aliquet urna luctus, venenatis justo aliquam, hendrerit arcu.', + 'image' => '', + 'updated_at' => '2021-05-08 23:13:00', + ], + [ + 'user_id' => 1, + 'title' => 'James Cameron', + 'content' => 'If you set your goals ridiculously high and it is a failure, you will fail above everyone else success.', + 'image' => '', + 'updated_at' => '2021-05-08 23:14:00', + ] + ]; + private $fs; + private $user; + + /** + * @var Request + */ + private $request; + + public function setUp(): void + { + App::loadCoreFunctions(dirname(__DIR__, 2) . DS . 'vendor' . DS . 'quantum' . DS . 'framework' . DS . 'src' . DS . 'Helpers'); + + App::setBaseDir(__DIR__ . DS . '_root'); + + Di::loadDefinitions(); + + $this->request = new Request(); + + $this->fs = Di::get(FileSystem::class); + + $this->authService = ServiceFactory::get(AuthService::class, ['shared' . DS . 'store', 'users']); + + $this->user = $this->authService->add($this->initialUser); + + $this->postService = ServiceFactory::get(PostService::class, ['shared' . DS . 'store', 'posts']); + + $this->request->set('per_page', 5); + + foreach ($this->initialPosts as $post) { + $this->postService->addPost($post); + } + } + + public function tearDown(): void + { + $this->authService->deleteTable(); + $this->postService->deleteTable(); + $this->removeFolders(); + } + + public function testGetPosts() + { + $this->assertIsObject($this->postService); + + $posts = $this->postService->getPosts($this->request); + + $this->assertInstanceOf(PaginatorInterface::class, $posts); + $this->assertIsArray($posts->data); + + $this->assertCount(4, $posts->data); + + $post = $posts->data[0]; + + $this->assertIsArray($post); + + $this->assertArrayHasKey('author', $post); + + $this->assertEquals('Tom Hunter', $post['author']); + } + + public function testGetSinglePost() + { + $posts = $this->postService->getPosts($this->request); + + $uuid = $posts->data[0]['id']; + + $post = $this->postService->getPost($uuid); + + $this->assertIsArray($post); + + $this->assertArrayHasKey('id', $post); + + $this->assertArrayHasKey('title', $post); + + $this->assertArrayHasKey('content', $post); + + $this->assertArrayHasKey('date', $post); + + $this->assertArrayHasKey('author', $post); + } + + public function testAddNewPost() + { + $date = date('Y-m-d H:i:s'); + + $newPost = $this->postService->addPost([ + 'user_id' => 1, + 'title' => 'Just another post', + 'content' => 'Content of just another post', + 'image' => '', + 'updated_at' => $date + ]); + + $uuid = $newPost['uuid']; + + $post = $this->postService->getPost($uuid); + + $this->assertEquals('Just another post', $post['title']); + + $this->assertEquals('Content of just another post', $post['content']); + + $this->assertEquals(date('Y/m/d H:i', strtotime($date)), $post['date']); + + $this->assertEquals('Tom Hunter', $post['author']); + } + + public function testUpdatePost() + { + $date = date('Y-m-d H:i:s'); + + $posts = $this->postService->getPosts($this->request); + + $uuid = $posts->data[0]['id']; + + $this->postService->updatePost($uuid, [ + 'title' => 'Walt Disney Jr.', + 'content' => 'The best way to get started is to quit talking and begin doing.', + 'image' => 'image.jpg', + 'updated_at' => $date + ]); + + $post = $this->postService->getPost($uuid); + + $this->assertNotEquals('Lorem ipsum dolor sit amet', $post['title']); + + $this->assertEquals('Walt Disney Jr.', $post['title']); + + $this->assertEquals('The best way to get started is to quit talking and begin doing.', $post['content']); + + $this->assertEquals($this->user->uuid . '/image.jpg', $post['image']); + + $this->assertEquals(date('Y/m/d H:i', strtotime($date)), $post['date']); + + $this->assertEquals('Tom Hunter', $post['author']); + } + + public function testDeletePost() + { + $this->assertCount(4, $this->postService->getPosts($this->request)->data); + + $post = $this->postService->addPost([ + 'user_id' => 1, + 'title' => 'Just another post', + 'content' => 'Content of just another post', + 'image' => '', + 'updated_at' => date('Y-m-d H:i:s') + ]); + + $this->assertCount(5, $this->postService->getPosts($this->request)->data); + + $this->postService->deletePost($post['uuid']); + + $this->assertCount(4, $this->postService->getPosts($this->request)->data); + } + + public function testSaveDeleteImage() + { + + $this->fileMeta = [ + 'size' => 500, + 'name' => 'foo.jpg', + 'tmp_name' => base_dir() . DS . 'tmp' . DS . 'php8fe1.tmp', + 'type' => 'image/jpg', + 'error' => 0, + ]; + + $uploadedFile = new UploadedFile($this->fileMeta); + + $image = $this->postService->saveImage($uploadedFile, $this->user->uuid, 'poster'); + + $this->assertFileExists(uploads_dir() . DS . $this->user->uuid . DS . $image); + + $this->postService->deleteImage($this->user->uuid . DS . $image); + + $this->assertFileDoesNotExist(uploads_dir() . DS . $this->user->uuid . DS . $image); + } + + private function removeFolders() + { + $uploadsFolder = $this->fs->glob(uploads_dir() . DS . '*'); + + foreach ($uploadsFolder as $user_uuid) { + $this->fs->removeDirectory($user_uuid); + } + } +} diff --git a/tests/Unit/_root/public/uploads/.gitkeep b/tests/Unit/_root/public/uploads/.gitkeep new file mode 100644 index 0000000..256c7f2 --- /dev/null +++ b/tests/Unit/_root/public/uploads/.gitkeep @@ -0,0 +1 @@ +#qt diff --git a/tests/Unit/_root/shared/config/database.php b/tests/Unit/_root/shared/config/database.php new file mode 100644 index 0000000..bd9fab7 --- /dev/null +++ b/tests/Unit/_root/shared/config/database.php @@ -0,0 +1,57 @@ + 'sleekdb', + + /** + * --------------------------------------------------------- + * Database Connections + * --------------------------------------------------------- + * + * You can define as many database configurations as you want. + * + * driver : mysql, pgsql, sqlite, sleekdb + * host : The database server (localhost) + * dbname : The database name + * username : Username of the database server + * password : Password of the database server + * charset : Default charset + */ + 'mysql' => [ + 'driver' => env("DB_DRIVER", "mysql"), + 'host' => env("DB_HOST", "localhost"), + 'dbname' => env("DB_NAME"), + 'username' => env("DB_USERNAME", "root"), + 'password' => env("DB_PASSWORD"), + 'charset' => env("DB_CHARSET", 'utf8'), + 'orm' => \Quantum\Libraries\Database\Idiorm\IdiormDbal::class + ], + 'sqlite' => [ + 'driver' => 'sqlite', + 'database' => 'database.sqlite', + 'prefix' => '', + ], + 'sleekdb' => [ + 'config' => [ + 'auto_cache' => true, + 'cache_lifetime' => null, + 'timeout' => false, + 'search' => [ + 'min_length' => 2, + 'mode' => 'or', + 'score_key' => 'scoreKey', + 'algorithm' => 1 + ], + ], + 'database_dir' => base_dir() . DS . 'shared' . DS . 'store', + 'orm' => \Quantum\Libraries\Database\Sleekdb\SleekDbal::class + ] +]; + diff --git a/tests/Unit/_root/shared/config/dependencies.php b/tests/Unit/_root/shared/config/dependencies.php new file mode 100644 index 0000000..c29cc1c --- /dev/null +++ b/tests/Unit/_root/shared/config/dependencies.php @@ -0,0 +1,5 @@ +jK^3!2K(U`h{u0j$Q}RSp|KN+g za5=g9dE)1I;4!bKM<9L;zuU!5uE4#_Oz2@S_(# zXaCwx;+k2q}kdTm)T_GpKH);xsOIK*A z>F8*wX=$%AvN2tyXJw$JW#(pPWoPH)cV4$l8<x8)X1oaK?o&GY_;0h6b zp|nJ_fHHu&^GEvsSub~T7_6_@)gV`P8HBU`pu1C4C$R>Sm_KG+O@kTC7^ zdGI9GB7vjG?QH@`%2fwGc2fv~5uC_bnwK)Pj+VL)A{!ATxbv$O^7^4v61(>fwH@Q9 z4pz;?rsKHLuJ}t`9!gDApIh=Y90~1op^e3So#W=)kqYxH4nGHD8rB3e>L|6cX82E0 zOUqO4w977-<2Tk%tC8NHD0zBp&fdfPW-5%0<9-V1z?M;Z?*|4>kghMn8m_p0Rj0-p z$=m2^%-$}sqsQ#6iy3zXCCDwLtB^XURmLCPe`Kkek%q+;g0vYCF3mB4n*KA+LF{j} zdDhXN=9L;2rDjrlkJB_2IvH4(@2}ZXL~-67>XXUlF;{mt-h;I76L{wQt34eX#L0fd zqT*7Bc)t8XybM_jov3N z-#XPG@^wvl+#LH9o!7cOY#7&dHFAl!c%`UwT%mT--iYpCAf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!~a8y;Ew%&o>O7J@5^+w?t~^ zdRQN_RwBx}W)gc;1W{G~3Q4YiiGQPJ&IyE+P;U|=f)Mq5ymtGN*N$I=oCCMcf#z_* zA2*9Pqazl#=r`eY)_Fled9vTB3+!O6UBRn-!jdpcm~5Ph!QHA+NYQ)2M!H}Mh4;fF zuUOYDL)?_zXZBd^x*>_&jTi}u$l(m@zJA}8mob`mk99qCnhRU#l4BTWs2HK8vC{3C zYH@R)x$^`D(&bEQi?#2m?Ff!B8L+#a3CHOMvyxl0RaVlX+Qk}KlU%`)Kv zUq3}juA(E$=5K^0Om1%}8dhjr4=A56ZG9@;T7txl@qn8+?#S3@SvrN!O}3foy5q{s zxC4pwcZX+q3~F33-mLPIoXpCd)1L-1=Xo!!ziQee``L4%x%ndC=jZU|b3l;%WQ#hU zb79+iRdC;UR$ literal 0 HcmV?d00001 diff --git a/tests/bootstrap.php b/tests/bootstrap.php deleted file mode 100644 index c83ec36..0000000 --- a/tests/bootstrap.php +++ /dev/null @@ -1,7 +0,0 @@ - Date: Thu, 31 Oct 2024 13:19:12 +0400 Subject: [PATCH 02/10] Renaming unit tests folder --- composer.json | 2 +- tests/Feature/Api/AuthControllerTest.php | 2 +- tests/Unit/AuthServiceTest.php | 9 +- tests/Unit/PostServiceTest.php | 75 +++--- tests/Unit/_root/public/uploads/.gitkeep | 1 - tests/Unit/_root/shared/store/.gitkeep | 1 - tests/unit/AuthServiceTest.php | 140 ----------- tests/unit/PostServiceTest.php | 236 ------------------ tests/unit/_root/public/uploads/.gitkeep | 0 tests/unit/_root/shared/config/database.php | 57 ----- .../unit/_root/shared/config/dependencies.php | 5 - tests/unit/_root/shared/store/.gitkeep | 0 tests/unit/_root/tmp/php8fe1.tmp | Bin 9113 -> 0 bytes 13 files changed, 39 insertions(+), 489 deletions(-) delete mode 100644 tests/unit/AuthServiceTest.php delete mode 100644 tests/unit/PostServiceTest.php delete mode 100644 tests/unit/_root/public/uploads/.gitkeep delete mode 100644 tests/unit/_root/shared/config/database.php delete mode 100644 tests/unit/_root/shared/config/dependencies.php delete mode 100644 tests/unit/_root/shared/store/.gitkeep delete mode 100644 tests/unit/_root/tmp/php8fe1.tmp diff --git a/composer.json b/composer.json index f54fb3a..d0031ea 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ }, "autoload-dev": { "psr-4": { - "Quantum\\Tests\\": "tests/unit/" + "Quantum\\Tests\\": "tests/" } }, "scripts": { diff --git a/tests/Feature/Api/AuthControllerTest.php b/tests/Feature/Api/AuthControllerTest.php index e4de84b..b20087b 100644 --- a/tests/Feature/Api/AuthControllerTest.php +++ b/tests/Feature/Api/AuthControllerTest.php @@ -1,6 +1,6 @@ authService->get('email', 'anonymous@qt.com'); - $this->assertInstanceOf(\Quantum\Libraries\Auth\User::class, $user); + $this->assertInstanceOf(User::class, $user); $this->assertArrayHasKey('password', $user->getData()); $this->assertArrayHasKey('firstname', $user->getData()); $this->assertArrayHasKey('lastname', $user->getData()); @@ -65,7 +68,7 @@ public function testUserGetById() { $user = $this->authService->get('id', 1); - $this->assertInstanceOf(\Quantum\Libraries\Auth\User::class, $user); + $this->assertInstanceOf(User::class, $user); $userData = $user->getData(); @@ -81,7 +84,7 @@ public function testUserAdd() 'lastname' => 'User', ]); - $this->assertInstanceOf(\Quantum\Libraries\Auth\User::class, $user); + $this->assertInstanceOf(User::class, $user); $this->assertArrayHasKey('email', $user->getData()); $this->assertEquals('guest@qt.com', $user->getFieldValue('email')); } diff --git a/tests/Unit/PostServiceTest.php b/tests/Unit/PostServiceTest.php index 1596466..4bc47c8 100644 --- a/tests/Unit/PostServiceTest.php +++ b/tests/Unit/PostServiceTest.php @@ -1,5 +1,7 @@ request = new Request(); - $this->fs = Di::get(FileSystem::class); $this->authService = ServiceFactory::get(AuthService::class, ['shared' . DS . 'store', 'users']); @@ -87,8 +84,6 @@ public function setUp(): void $this->postService = ServiceFactory::get(PostService::class, ['shared' . DS . 'store', 'posts']); - $this->request->set('per_page', 5); - foreach ($this->initialPosts as $post) { $this->postService->addPost($post); } @@ -105,41 +100,37 @@ public function testGetPosts() { $this->assertIsObject($this->postService); - $posts = $this->postService->getPosts($this->request); + $posts = $this->postService->getPosts(self::PER_PAGE, self::CURRENT_PAGE); - $this->assertInstanceOf(PaginatorInterface::class, $posts); - $this->assertIsArray($posts->data); + $this->assertInstanceOf(PaginatorInterface::class, $posts); - $this->assertCount(4, $posts->data); + $this->assertIsArray($posts->data()); - $post = $posts->data[0]; + $this->assertCount(4, $posts->data()); - $this->assertIsArray($post); + $post = $posts->data()[0]; - $this->assertArrayHasKey('author', $post); - - $this->assertEquals('Tom Hunter', $post['author']); + $this->assertIsObject($post); } public function testGetSinglePost() { - $posts = $this->postService->getPosts($this->request); + $posts = $this->postService->getPosts(self::PER_PAGE, self::CURRENT_PAGE); - $uuid = $posts->data[0]['id']; + $uuid = $posts->data()[0]->uuid; $post = $this->postService->getPost($uuid); - $this->assertIsArray($post); + $this->assertInstanceOf(Post::class, $post); - $this->assertArrayHasKey('id', $post); + $postData = $post->asArray(); - $this->assertArrayHasKey('title', $post); + $this->assertArrayHasKey('title', $postData); - $this->assertArrayHasKey('content', $post); + $this->assertArrayHasKey('content', $postData); - $this->assertArrayHasKey('date', $post); + $this->assertArrayHasKey('updated_at', $postData); - $this->assertArrayHasKey('author', $post); } public function testAddNewPost() @@ -158,22 +149,20 @@ public function testAddNewPost() $post = $this->postService->getPost($uuid); - $this->assertEquals('Just another post', $post['title']); - - $this->assertEquals('Content of just another post', $post['content']); + $this->assertEquals('Just another post', $post->title); - $this->assertEquals(date('Y/m/d H:i', strtotime($date)), $post['date']); + $this->assertEquals('Content of just another post', $post->content); - $this->assertEquals('Tom Hunter', $post['author']); + $this->assertEquals($date, $post->updated_at); } public function testUpdatePost() { $date = date('Y-m-d H:i:s'); - $posts = $this->postService->getPosts($this->request); + $posts = $this->postService->getPosts(self::PER_PAGE, self::CURRENT_PAGE); - $uuid = $posts->data[0]['id']; + $uuid = $posts->data()[0]->uuid; $this->postService->updatePost($uuid, [ 'title' => 'Walt Disney Jr.', @@ -184,22 +173,20 @@ public function testUpdatePost() $post = $this->postService->getPost($uuid); - $this->assertNotEquals('Lorem ipsum dolor sit amet', $post['title']); - - $this->assertEquals('Walt Disney Jr.', $post['title']); + $this->assertNotEquals('Lorem ipsum dolor sit amet', $post->title); - $this->assertEquals('The best way to get started is to quit talking and begin doing.', $post['content']); + $this->assertEquals('Walt Disney Jr.', $post->title); - $this->assertEquals($this->user->uuid . '/image.jpg', $post['image']); + $this->assertEquals('The best way to get started is to quit talking and begin doing.', $post->content); - $this->assertEquals(date('Y/m/d H:i', strtotime($date)), $post['date']); + $this->assertEquals('image.jpg', $post->image); - $this->assertEquals('Tom Hunter', $post['author']); + $this->assertEquals($date, $post->updated_at); } public function testDeletePost() { - $this->assertCount(4, $this->postService->getPosts($this->request)->data); + $this->assertCount(4, $this->postService->getPosts(self::PER_PAGE, self::CURRENT_PAGE)->data()); $post = $this->postService->addPost([ 'user_id' => 1, @@ -209,11 +196,11 @@ public function testDeletePost() 'updated_at' => date('Y-m-d H:i:s') ]); - $this->assertCount(5, $this->postService->getPosts($this->request)->data); + $this->assertCount(5, $this->postService->getPosts(self::PER_PAGE, self::CURRENT_PAGE)->data()); $this->postService->deletePost($post['uuid']); - $this->assertCount(4, $this->postService->getPosts($this->request)->data); + $this->assertCount(4, $this->postService->getPosts(self::PER_PAGE, self::CURRENT_PAGE)->data()); } public function testSaveDeleteImage() diff --git a/tests/Unit/_root/public/uploads/.gitkeep b/tests/Unit/_root/public/uploads/.gitkeep index 256c7f2..e69de29 100644 --- a/tests/Unit/_root/public/uploads/.gitkeep +++ b/tests/Unit/_root/public/uploads/.gitkeep @@ -1 +0,0 @@ -#qt diff --git a/tests/Unit/_root/shared/store/.gitkeep b/tests/Unit/_root/shared/store/.gitkeep index 256c7f2..e69de29 100644 --- a/tests/Unit/_root/shared/store/.gitkeep +++ b/tests/Unit/_root/shared/store/.gitkeep @@ -1 +0,0 @@ -#qt diff --git a/tests/unit/AuthServiceTest.php b/tests/unit/AuthServiceTest.php deleted file mode 100644 index 176d94a..0000000 --- a/tests/unit/AuthServiceTest.php +++ /dev/null @@ -1,140 +0,0 @@ - 'anonymous@qt.com', - 'password' => '$2y$12$4Y4/1a4308KEiGX/xo6vgO41szJuDHC7KhpG5nknx/xxnLZmvMyGi', - 'firstname' => 'Tom', - 'lastname' => 'Hunter', - 'role' => 'admin', - 'activation_token' => '', - 'remember_token' => '', - 'reset_token' => '', - 'access_token' => '', - 'refresh_token' => '', - 'otp' => '', - 'otp_expires' => '', - 'otp_token' => '', - ]; - - public function setUp(): void - { - App::loadCoreFunctions(dirname(__DIR__, 2) . DS . 'vendor' . DS . 'quantum' . DS . 'framework' . DS . 'src' . DS . 'Helpers'); - - App::setBaseDir(__DIR__ . DS . '_root'); - - Di::loadDefinitions(); - - $this->authService = ServiceFactory::get(AuthService::class, ['shared' . DS . 'store', 'users']); - - $this->authService->add($this->initialUser); - } - - public function tearDown(): void - { - $this->authService->deleteTable(); - $this->removeFolders(); - } - - public function testUserGet() - { - $user = $this->authService->get('email', 'anonymous@qt.com'); - - $this->assertInstanceOf(User::class, $user); - $this->assertArrayHasKey('password', $user->getData()); - $this->assertArrayHasKey('firstname', $user->getData()); - $this->assertArrayHasKey('lastname', $user->getData()); - $this->assertArrayHasKey('role', $user->getData()); - $this->assertArrayHasKey('remember_token', $user->getData()); - $this->assertArrayHasKey('reset_token', $user->getData()); - $this->assertEquals('admin', $user->getFieldValue('role')); - } - - public function testUserGetById() - { - $user = $this->authService->get('id', 1); - - $this->assertInstanceOf(User::class, $user); - - $userData = $user->getData(); - - $this->assertIsArray($userData); - } - - public function testUserAdd() - { - $user = $this->authService->add([ - 'email' => 'guest@qt.com', - 'password' => '$2y$12$0M78WcmUZYQq85vHZLoNW.CyDUezRxh9Ye8/Z8oWCwJmBrz8p.j7C', - 'firstname' => 'Guest', - 'lastname' => 'User', - ]); - - $this->assertInstanceOf(User::class, $user); - $this->assertArrayHasKey('email', $user->getData()); - $this->assertEquals('guest@qt.com', $user->getFieldValue('email')); - } - - public function testUserUpdate() - { - $user = $this->authService->get('email', 'anonymous@qt.com'); - - $this->assertEmpty($user->getFieldValue('remember_token')); - - $rememberToken = base64_encode(time()); - - $this->authService->update( - 'email', - $user->getFieldValue('email'), - ['remember_token' => $rememberToken] - ); - - $user = $this->authService->get('email', 'anonymous@qt.com'); - - $this->assertNotEmpty($user->getFieldValue('remember_token')); - $this->assertEquals($user->getFieldValue('remember_token'), $rememberToken); - } - - public function testUserSchema() - { - $this->assertIsArray($this->authService->userSchema()); - $this->assertArrayHasKey('username', $this->authService->userSchema()); - $this->assertArrayHasKey('password', $this->authService->userSchema()); - $this->assertArrayHasKey('activationToken', $this->authService->userSchema()); - $this->assertArrayHasKey('rememberToken', $this->authService->userSchema()); - $this->assertArrayHasKey('resetToken', $this->authService->userSchema()); - $this->assertArrayHasKey('accessToken', $this->authService->userSchema()); - $this->assertArrayHasKey('refreshToken', $this->authService->userSchema()); - $this->assertArrayHasKey('otp', $this->authService->userSchema()); - $this->assertArrayHasKey('otpExpiry', $this->authService->userSchema()); - $this->assertArrayHasKey('otpToken', $this->authService->userSchema()); - $this->assertIsArray($this->authService->userSchema()['username']); - $this->assertArrayHasKey('name', $this->authService->userSchema()['username']); - $this->assertArrayHasKey('visible', $this->authService->userSchema()['username']); - } - - private function removeFolders() - { - $fs = Di::get(FileSystem::class); - - $uploadsFolder = $fs->glob(uploads_dir() . DS . '*'); - - foreach ($uploadsFolder as $folder) { - $fs->removeDirectory($folder); - } - } -} diff --git a/tests/unit/PostServiceTest.php b/tests/unit/PostServiceTest.php deleted file mode 100644 index ce6f64c..0000000 --- a/tests/unit/PostServiceTest.php +++ /dev/null @@ -1,236 +0,0 @@ - 'anonymous@qt.com', - 'password' => '$2y$12$4Y4/1a4308KEiGX/xo6vgO41szJuDHC7KhpG5nknx/xxnLZmvMyGi', - 'firstname' => 'Tom', - 'lastname' => 'Hunter', - 'role' => 'admin', - 'activation_token' => '', - 'remember_token' => '', - 'reset_token' => '', - 'access_token' => '', - 'refresh_token' => '', - 'otp' => '', - 'otp_expires' => '', - 'otp_token' => '', - ]; - private $initialPosts = [ - [ - 'user_id' => 1, - 'title' => 'Walt Disney', - 'content' => 'The way to get started is to quit talking and begin doing.', - 'image' => '', - 'updated_at' => '2021-05-08 23:11:00', - ], - [ - 'user_id' => 1, - 'title' => 'Lorem ipsum dolor sit amet', - 'content' => 'Praesent hendrerit lobortis malesuada. Proin bibendum lacinia nunc ac aliquet.', - 'image' => '', - 'updated_at' => '2021-05-08 23:12:00', - ], - [ - 'user_id' => 1, - 'title' => 'Aenean dui turpis', - 'content' => 'Etiam aliquet urna luctus, venenatis justo aliquam, hendrerit arcu.', - 'image' => '', - 'updated_at' => '2021-05-08 23:13:00', - ], - [ - 'user_id' => 1, - 'title' => 'James Cameron', - 'content' => 'If you set your goals ridiculously high and it is a failure, you will fail above everyone else success.', - 'image' => '', - 'updated_at' => '2021-05-08 23:14:00', - ] - ]; - private $fs; - private $user; - - public function setUp(): void - { - App::loadCoreFunctions(dirname(__DIR__, 2) . DS . 'vendor' . DS . 'quantum' . DS . 'framework' . DS . 'src' . DS . 'Helpers'); - - App::setBaseDir(__DIR__ . DS . '_root'); - - Di::loadDefinitions(); - - $this->fs = Di::get(FileSystem::class); - - $this->authService = ServiceFactory::get(AuthService::class, ['shared' . DS . 'store', 'users']); - - $this->user = $this->authService->add($this->initialUser); - - $this->postService = ServiceFactory::get(PostService::class, ['shared' . DS . 'store', 'posts']); - - foreach ($this->initialPosts as $post) { - $this->postService->addPost($post); - } - } - - public function tearDown(): void - { - $this->authService->deleteTable(); - $this->postService->deleteTable(); - $this->removeFolders(); - } - - public function testGetPosts() - { - $this->assertIsObject($this->postService); - - $posts = $this->postService->getPosts(self::PER_PAGE, self::CURRENT_PAGE); - - $this->assertInstanceOf(PaginatorInterface::class, $posts); - - $this->assertIsArray($posts->data()); - - $this->assertCount(4, $posts->data()); - - $post = $posts->data()[0]; - - $this->assertIsObject($post); - } - - public function testGetSinglePost() - { - $posts = $this->postService->getPosts(self::PER_PAGE, self::CURRENT_PAGE); - - $uuid = $posts->data()[0]->uuid; - - $post = $this->postService->getPost($uuid); - - $this->assertInstanceOf(Post::class, $post); - - $postData = $post->asArray(); - - $this->assertArrayHasKey('title', $postData); - - $this->assertArrayHasKey('content', $postData); - - $this->assertArrayHasKey('updated_at', $postData); - - } - - public function testAddNewPost() - { - $date = date('Y-m-d H:i:s'); - - $newPost = $this->postService->addPost([ - 'user_id' => 1, - 'title' => 'Just another post', - 'content' => 'Content of just another post', - 'image' => '', - 'updated_at' => $date - ]); - - $uuid = $newPost['uuid']; - - $post = $this->postService->getPost($uuid); - - $this->assertEquals('Just another post', $post->title); - - $this->assertEquals('Content of just another post', $post->content); - - $this->assertEquals($date, $post->updated_at); - } - - public function testUpdatePost() - { - $date = date('Y-m-d H:i:s'); - - $posts = $this->postService->getPosts(self::PER_PAGE, self::CURRENT_PAGE); - - $uuid = $posts->data()[0]->uuid; - - $this->postService->updatePost($uuid, [ - 'title' => 'Walt Disney Jr.', - 'content' => 'The best way to get started is to quit talking and begin doing.', - 'image' => 'image.jpg', - 'updated_at' => $date - ]); - - $post = $this->postService->getPost($uuid); - - $this->assertNotEquals('Lorem ipsum dolor sit amet', $post->title); - - $this->assertEquals('Walt Disney Jr.', $post->title); - - $this->assertEquals('The best way to get started is to quit talking and begin doing.', $post->content); - - $this->assertEquals('image.jpg', $post->image); - - $this->assertEquals($date, $post->updated_at); - } - - public function testDeletePost() - { - $this->assertCount(4, $this->postService->getPosts(self::PER_PAGE, self::CURRENT_PAGE)->data()); - - $post = $this->postService->addPost([ - 'user_id' => 1, - 'title' => 'Just another post', - 'content' => 'Content of just another post', - 'image' => '', - 'updated_at' => date('Y-m-d H:i:s') - ]); - - $this->assertCount(5, $this->postService->getPosts(self::PER_PAGE, self::CURRENT_PAGE)->data()); - - $this->postService->deletePost($post['uuid']); - - $this->assertCount(4, $this->postService->getPosts(self::PER_PAGE, self::CURRENT_PAGE)->data()); - } - - public function testSaveDeleteImage() - { - - $this->fileMeta = [ - 'size' => 500, - 'name' => 'foo.jpg', - 'tmp_name' => base_dir() . DS . 'tmp' . DS . 'php8fe1.tmp', - 'type' => 'image/jpg', - 'error' => 0, - ]; - - $uploadedFile = new UploadedFile($this->fileMeta); - - $image = $this->postService->saveImage($uploadedFile, $this->user->uuid, 'poster'); - - $this->assertFileExists(uploads_dir() . DS . $this->user->uuid . DS . $image); - - $this->postService->deleteImage($this->user->uuid . DS . $image); - - $this->assertFileDoesNotExist(uploads_dir() . DS . $this->user->uuid . DS . $image); - } - - private function removeFolders() - { - $uploadsFolder = $this->fs->glob(uploads_dir() . DS . '*'); - - foreach ($uploadsFolder as $user_uuid) { - $this->fs->removeDirectory($user_uuid); - } - } -} diff --git a/tests/unit/_root/public/uploads/.gitkeep b/tests/unit/_root/public/uploads/.gitkeep deleted file mode 100644 index e69de29..0000000 diff --git a/tests/unit/_root/shared/config/database.php b/tests/unit/_root/shared/config/database.php deleted file mode 100644 index bd9fab7..0000000 --- a/tests/unit/_root/shared/config/database.php +++ /dev/null @@ -1,57 +0,0 @@ - 'sleekdb', - - /** - * --------------------------------------------------------- - * Database Connections - * --------------------------------------------------------- - * - * You can define as many database configurations as you want. - * - * driver : mysql, pgsql, sqlite, sleekdb - * host : The database server (localhost) - * dbname : The database name - * username : Username of the database server - * password : Password of the database server - * charset : Default charset - */ - 'mysql' => [ - 'driver' => env("DB_DRIVER", "mysql"), - 'host' => env("DB_HOST", "localhost"), - 'dbname' => env("DB_NAME"), - 'username' => env("DB_USERNAME", "root"), - 'password' => env("DB_PASSWORD"), - 'charset' => env("DB_CHARSET", 'utf8'), - 'orm' => \Quantum\Libraries\Database\Idiorm\IdiormDbal::class - ], - 'sqlite' => [ - 'driver' => 'sqlite', - 'database' => 'database.sqlite', - 'prefix' => '', - ], - 'sleekdb' => [ - 'config' => [ - 'auto_cache' => true, - 'cache_lifetime' => null, - 'timeout' => false, - 'search' => [ - 'min_length' => 2, - 'mode' => 'or', - 'score_key' => 'scoreKey', - 'algorithm' => 1 - ], - ], - 'database_dir' => base_dir() . DS . 'shared' . DS . 'store', - 'orm' => \Quantum\Libraries\Database\Sleekdb\SleekDbal::class - ] -]; - diff --git a/tests/unit/_root/shared/config/dependencies.php b/tests/unit/_root/shared/config/dependencies.php deleted file mode 100644 index c29cc1c..0000000 --- a/tests/unit/_root/shared/config/dependencies.php +++ /dev/null @@ -1,5 +0,0 @@ -jK^3!2K(U`h{u0j$Q}RSp|KN+g za5=g9dE)1I;4!bKM<9L;zuU!5uE4#_Oz2@S_(# zXaCwx;+k2q}kdTm)T_GpKH);xsOIK*A z>F8*wX=$%AvN2tyXJw$JW#(pPWoPH)cV4$l8<x8)X1oaK?o&GY_;0h6b zp|nJ_fHHu&^GEvsSub~T7_6_@)gV`P8HBU`pu1C4C$R>Sm_KG+O@kTC7^ zdGI9GB7vjG?QH@`%2fwGc2fv~5uC_bnwK)Pj+VL)A{!ATxbv$O^7^4v61(>fwH@Q9 z4pz;?rsKHLuJ}t`9!gDApIh=Y90~1op^e3So#W=)kqYxH4nGHD8rB3e>L|6cX82E0 zOUqO4w977-<2Tk%tC8NHD0zBp&fdfPW-5%0<9-V1z?M;Z?*|4>kghMn8m_p0Rj0-p z$=m2^%-$}sqsQ#6iy3zXCCDwLtB^XURmLCPe`Kkek%q+;g0vYCF3mB4n*KA+LF{j} zdDhXN=9L;2rDjrlkJB_2IvH4(@2}ZXL~-67>XXUlF;{mt-h;I76L{wQt34eX#L0fd zqT*7Bc)t8XybM_jov3N z-#XPG@^wvl+#LH9o!7cOY#7&dHFAl!c%`UwT%mT--iYpCAf`?{0!Fhiwn4KV&?3#U z)5HNrBuqTFTGqmE#<8R39MGC6|5>RBZQ#?v+AP<(6)y>n{Ah2X%YZj|gS3b@suw8} zR0F0e=5Uq<8Ao&IC$I;S1HMA&vgkvBShPhq!5V!KosK*Czz=?|s?36U;W?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HA+NYQ)2M!H}Mh4;fF zuUOYDL)?_zXZBd^x*>_&jTi}u$l(m@zJA}8mob`mk99qCnhRU#l4BTWs2HK8vC{3C zYH@R)x$^`D(&bEQi?#2m?Ff!B8L+#a3CHOMvyxl0RaVlX+Qk}KlU%`)Kv zUq3}juA(E$=5K^0Om1%}8dhjr4=A56ZG9@;T7txl@qn8+?#S3@SvrN!O}3foy5q{s zxC4pwcZX+q3~F33-mLPIoXpCd)1L-1=Xo!!ziQee``L4%x%ndC=jZU|b3l;%WQ#hU zb79+iRdC;UR$ From 78683271613fb4807f8a3cd3821b1d8415ff55cc Mon Sep 17 00:00:00 2001 From: Vahram Date: Thu, 31 Oct 2024 17:44:07 +0400 Subject: [PATCH 03/10] Creating feature tests for "Api/PostController" --- .github/workflows/php.yml | 3 + phpunit.xml | 8 +- tests/Feature/Api/AuthControllerTest.php | 44 ++++- tests/Feature/Api/PostControllerTest.php | 175 ++++++++++++++++++ tests/Feature/BaseTestCase.php | 29 ++- tests/Feature/TestData.php | 66 +++++++ tests/Feature/_root/.env.testing | 30 --- .../modules/test/Resources/lang/en/custom.php | 7 - .../_root/modules/test/Views/index.php | 1 - .../_root/modules/test/Views/layout.php | 6 - .../_root/modules/test/Views/partial.php | 1 - tests/Feature/_root/public/uploads/.gitkeep | 1 - tests/Feature/_root/shared/config/captcha.php | 17 -- tests/Feature/_root/shared/config/config.php | 9 - .../Feature/_root/shared/config/database.php | 34 ---- .../_root/shared/config/dependencies.php | 5 - tests/Feature/_root/shared/config/env.php | 5 - tests/Feature/_root/shared/config/hooks.php | 5 - tests/Feature/_root/shared/config/mailer.php | 32 ---- tests/Feature/_root/shared/config/modules.php | 17 -- tests/Feature/_root/shared/config/session.php | 7 - tests/Feature/_root/shared/store/.gitkeep | 1 - tests/Feature/_root/tmp/php8fe1.tmp | Bin 9113 -> 0 bytes 23 files changed, 308 insertions(+), 195 deletions(-) create mode 100644 tests/Feature/Api/PostControllerTest.php create mode 100644 tests/Feature/TestData.php delete mode 100644 tests/Feature/_root/.env.testing delete mode 100644 tests/Feature/_root/modules/test/Resources/lang/en/custom.php delete mode 100644 tests/Feature/_root/modules/test/Views/index.php delete mode 100644 tests/Feature/_root/modules/test/Views/layout.php delete mode 100644 tests/Feature/_root/modules/test/Views/partial.php delete mode 100644 tests/Feature/_root/public/uploads/.gitkeep delete mode 100644 tests/Feature/_root/shared/config/captcha.php delete mode 100644 tests/Feature/_root/shared/config/config.php delete mode 100644 tests/Feature/_root/shared/config/database.php delete mode 100644 tests/Feature/_root/shared/config/dependencies.php delete mode 100644 tests/Feature/_root/shared/config/env.php delete mode 100644 tests/Feature/_root/shared/config/hooks.php delete mode 100644 tests/Feature/_root/shared/config/mailer.php delete mode 100644 tests/Feature/_root/shared/config/modules.php delete mode 100644 tests/Feature/_root/shared/config/session.php delete mode 100644 tests/Feature/_root/shared/store/.gitkeep delete mode 100644 tests/Feature/_root/tmp/php8fe1.tmp diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 39c78c9..4c969d0 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -42,5 +42,8 @@ jobs: - name: Install dependencies run: composer install --prefer-dist --no-progress + - name: Install demo + run: php qt install:demo + - name: Run tests run: composer test diff --git a/phpunit.xml b/phpunit.xml index 570e937..c018cd2 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -11,9 +11,9 @@ ./tests/Feature - - - - + + + ./tests/Unit +
\ No newline at end of file diff --git a/tests/Feature/Api/AuthControllerTest.php b/tests/Feature/Api/AuthControllerTest.php index b20087b..ca1d4d8 100644 --- a/tests/Feature/Api/AuthControllerTest.php +++ b/tests/Feature/Api/AuthControllerTest.php @@ -2,9 +2,9 @@ namespace Quantum\Tests\Feature\Api; +use Quantum\Tests\Feature\BaseTestCase; use Quantum\Libraries\Hasher\Hasher; use Quantum\Factory\ModelFactory; -use Tests\Feature\BaseTestCase; use Quantum\Router\Router; use Shared\Models\User; @@ -44,7 +44,6 @@ public function testSignInWithIncorrectRequestApi() public function testMeApi() { - $this->loadAppFunctionality(); Router::setCurrentRoute([ 'route' => '/api/en/signin', 'prefix' => 'api', @@ -76,7 +75,6 @@ public function testMeIncorrectApi() public function testSignoutApi() { - $this->loadAppFunctionality(); Router::setCurrentRoute([ 'route' => '/api/en/signin', 'prefix' => 'api', @@ -131,7 +129,6 @@ public function testSignupIncorrectApi() public function testActivateApi() { - $this->loadAppFunctionality(); $userModel = ModelFactory::get(User::class)->create(); $activationToken = base64_encode((new Hasher())->hash('password')); $userModel->fillObjectProps([ @@ -159,7 +156,6 @@ public function testActivateIncorrectApi() public function testResetApi() { - $this->loadAppFunctionality(); $userModel = ModelFactory::get(User::class)->create(); $resetToken = base64_encode((new Hasher())->hash('password')); $userModel->fillObjectProps([ @@ -189,7 +185,7 @@ public function testResetIncorrectApi() public function testResendApi() { - $this->loadAppFunctionality(); + $userModel = ModelFactory::get(User::class)->create(); $otpToken = base64_encode((new Hasher())->hash($this->email)); $userModel->fillObjectProps([ @@ -215,6 +211,42 @@ public function testResendIncorrectApi() $this->assertEquals('Incorrect credentials', $response->get('message')); } + public function testVerifyApi() + { + $userModel = ModelFactory::get(User::class)->create(); + $otpToken = base64_encode((new Hasher())->hash($this->email)); + $userModel->fillObjectProps([ + 'email' => $this->email, + 'password' => (new Hasher())->hash($this->password), + 'firstname' => 'firstname', + 'lastname' => 'lastname', + 'otp_token' => $otpToken, + 'otp' => $otpToken + ]); + $userModel->save(); + + $response = $this->request('post', '/api/en/verify', [ + 'otp' => $otpToken, + 'code' => $otpToken, + ]); + + $this->assertEquals('success', $response->get('status')); + $this->assertArrayHasKey('tokens', $response->all()); + $this->assertArrayHasKey('refresh_token', $response->get('tokens')); + $this->assertArrayHasKey('access_token', $response->get('tokens')); + } + + public function testVerifyIncorrectApi() + { + $response = $this->request('post', '/api/en/verify', [ + 'otp' => 'incorrect-otp', + 'code' => 'incorrect-code', + ]); + + $this->assertEquals('error', $response->get('status')); + $this->assertEquals('Incorrect verification code.', $response->get('message')); + } + public function tearDown(): void { parent::tearDown(); diff --git a/tests/Feature/Api/PostControllerTest.php b/tests/Feature/Api/PostControllerTest.php new file mode 100644 index 0000000..7efac66 --- /dev/null +++ b/tests/Feature/Api/PostControllerTest.php @@ -0,0 +1,175 @@ +request('get', '/api/en/posts'); + + $this->assertIsObject($response); + $this->assertEquals('success', $response->get('status')); + $this->assertArrayHasKey('data', $response->all()); + $this->assertArrayHasKey('id', $response->get('data')[0]); + $this->assertArrayHasKey('title', $response->get('data')[0]); + $this->assertArrayHasKey('content', $response->get('data')[0]); + $this->assertArrayHasKey('image', $response->get('data')[0]); + $this->assertArrayHasKey('date', $response->get('data')[0]); + $this->assertArrayHasKey('author', $response->get('data')[0]); + $this->assertCount(8, $response->get('data')); + $this->assertArrayHasKey('pagination', $response->all()); + $this->assertArrayHasKey('total_records', $response->get('pagination')); + $this->assertArrayHasKey('current_page', $response->get('pagination')); + $this->assertArrayHasKey('next_page', $response->get('pagination')); + $this->assertArrayHasKey('prev_page', $response->get('pagination')); + $this->assertEquals(10, $response->get('pagination')['total_records']); + $this->assertEquals(1, $response->get('pagination')['current_page']); + $this->assertEquals(2, $response->get('pagination')['next_page']); + $this->assertEquals(1, $response->get('pagination')['prev_page']); + } + + public function testSinglePostApi() + { + $post = ModelFactory::get(Post::class)->first(); + + $response = $this->request('get', '/api/en/post/' . $post->uuid); + + $this->assertIsObject($response); + $this->assertEquals('success', $response->get('status')); + $this->assertArrayHasKey('data', $response->all()); + $this->assertArrayHasKey('id', $response->get('data')); + $this->assertArrayHasKey('title', $response->get('data')); + $this->assertArrayHasKey('content', $response->get('data')); + $this->assertArrayHasKey('image', $response->get('data')); + $this->assertArrayHasKey('date', $response->get('data')); + $this->assertArrayHasKey('author', $response->get('data')); + } + + public function testMyPostsApi() + { + Router::setCurrentRoute([ + 'module' => 'Api', + ]); + $tokens = auth()->signin($this->email, $this->password); + + $response = $this->request('get', '/api/en/my-posts', [], [ + 'Authorization' => 'Bearer ' . $tokens['access_token'], + 'refresh_token' => $tokens['refresh_token'] + ]); + + $this->assertIsObject($response); + $this->assertEquals('success', $response->get('status')); + $this->assertArrayHasKey('data', $response->all()); + $this->assertCount(10, $response->get('data')); + $this->assertArrayHasKey('id', $response->get('data')[0]); + $this->assertArrayHasKey('title', $response->get('data')[0]); + $this->assertArrayHasKey('content', $response->get('data')[0]); + $this->assertArrayHasKey('image', $response->get('data')[0]); + $this->assertArrayHasKey('date', $response->get('data')[0]); + $this->assertArrayHasKey('author', $response->get('data')[0]); + } + + public function testPostCreateApi() + { + Router::setCurrentRoute([ + 'module' => 'Api', + ]); + $tokens = auth()->signin($this->email, $this->password); + + $response = $this->request('post', '/api/en/my-posts/create', + [ + 'title' => 'test title', + 'content' => 'test content', + 'image' => '', + 'updated_at' => date('Y-m-d H:i:s'), + ], + ['Authorization' => 'Bearer ' . $tokens['access_token']] + ); + + $this->assertIsObject($response); + $this->assertEquals('success', $response->get('status')); + $this->assertEquals('Created successfully', $response->get('message')); + } + + public function testAmendPostApi() + { + $post = ModelFactory::get(Post::class)->first(); + + Router::setCurrentRoute([ + 'module' => 'Api', + ]); + + $tokens = auth()->signin($this->email, $this->password); + + $response = $this->request('put', '/api/en/my-posts/amend/' . $post->uuid, + [ + 'title' => 'test title123', + 'content' => 'test content123', + ], + ['Authorization' => 'Bearer ' . $tokens['access_token']] + ); + + $this->assertIsObject($response); + $this->assertEquals('success', $response->get('status')); + $this->assertEquals('Updated successfully', $response->get('message')); + } + + public function testDeletePostApi() + { + $post = ModelFactory::get(Post::class)->first(); + + Router::setCurrentRoute([ + 'module' => 'Api', + ]); + + $tokens = auth()->signin($this->email, $this->password); + + $response = $this->request('delete', '/api/en/my-posts/delete/' . $post->uuid, [], [ + 'Authorization' => 'Bearer ' . $tokens['access_token'] + ]); + + $this->assertIsObject($response); + $this->assertEquals('success', $response->get('status')); + $this->assertEquals('Deleted successfully', $response->get('message')); + } + + public function testDeleteImagePostApi() + { + $post = ModelFactory::get(Post::class)->first(); + Router::setCurrentRoute([ + 'module' => 'Api', + ]); + + $tokens = auth()->signin($this->email, $this->password); + + $response = $this->request('delete', '/api/en/my-posts/delete-image/' . $post->uuid, [], [ + 'Authorization' => 'Bearer ' . $tokens['access_token'] + ]); + + $this->assertIsObject($response); + $this->assertEquals('success', $response->get('status')); + $this->assertEquals('Deleted successfully', $response->get('message')); + } + + public function tearDown(): void + { + parent::tearDown(); + } +} \ No newline at end of file diff --git a/tests/Feature/BaseTestCase.php b/tests/Feature/BaseTestCase.php index bbe5bad..4dea60c 100644 --- a/tests/Feature/BaseTestCase.php +++ b/tests/Feature/BaseTestCase.php @@ -1,6 +1,6 @@ loadAppFunctionality(); + TestData::createUserData(); + TestData::createPostData(); } public function request(string $method, string $url, array $options = [], array $headers = [], string $contentType = 'application/x-www-form-urlencoded'): Response @@ -58,13 +57,29 @@ public function tearDown(): void { parent::tearDown(); ob_end_clean(); + TestData::deleteUserData(); + TestData::deletePostData(); + + foreach (array_diff(scandir(uploads_dir()), array('.', '..', '.gitkeep')) as $item){ + if (is_dir(uploads_dir() . DS . $item)) { + rmdir(uploads_dir() . DS . $item); + }elseif (is_file(uploads_dir() . DS . $item)) { + unlink(uploads_dir() . DS . $item); + } + } } - protected function loadAppFunctionality() + private function loadAppFunctionality() { App::setBaseDir(dirname(__DIR__, 2)); App::loadCoreFunctions(dirname(__DIR__, 2) . DS . 'vendor' . DS . 'quantum' . DS . 'framework' . DS . 'src' . DS . 'Helpers'); Di::loadDefinitions(); + + $loader = Di::get(Loader::class); + $loader->loadDir(base_dir() . DS . 'helpers'); + $loader->loadDir(base_dir() . DS . 'libraries'); + $loader->loadDir(base_dir() . DS . 'hooks'); + Environment::getInstance()->load(new Setup('config', 'env')); } } diff --git a/tests/Feature/TestData.php b/tests/Feature/TestData.php new file mode 100644 index 0000000..414e886 --- /dev/null +++ b/tests/Feature/TestData.php @@ -0,0 +1,66 @@ + self::$faker->firstName, + 'lastname' => self::$faker->lastName, + 'role' => self::$role, + 'email' => self::$email, + 'password' => (new Hasher())->hash(self::$password), + ]; + + $authService->add($user); + } + + public static function createPostData() + { + $users = ServiceFactory::get(AuthService::class)->getAll(); + $postService = ServiceFactory::get(PostService::class); + + foreach ($users as $user){ + for ($i = 0; $i < 10; $i++){ + $title = str_replace(['"', '\'', '-'], '', self::$faker->realText(50)); + + $postData = [ + 'title' => $title, + 'content' => str_replace(['"', '\'', '-'], '', self::$faker->realText(100)), + 'image' => slugify($title) . '.jpg', + 'user_id' => $user->id, + ]; + + $postService->addPost($postData); + } + + } + } + + public static function deleteUserData() + { + ServiceFactory::get(AuthService::class)->deleteTable(); + } + + public static function deletePostData() + { + ServiceFactory::get(PostService::class)->deleteTable(); + } +} \ No newline at end of file diff --git a/tests/Feature/_root/.env.testing b/tests/Feature/_root/.env.testing deleted file mode 100644 index a11d766..0000000 --- a/tests/Feature/_root/.env.testing +++ /dev/null @@ -1,30 +0,0 @@ -APP_KEY=d88d33ea128f578776c6342731c72e8e486b3b59f5fdaac60ff4b527ff4071c4 -APP_NAME="Quantum PHP Framework" -APP_VERSION=2.9 -DB_DRIVER=mysql -DB_HOST=localhost -DB_NAME=quantum -DB_USERNAME=root -DB_PASSWORD= -2FA=false -DEBUG=true -APP_URL= - -MAIL_HOST= -MAIL_SMTP_SECURE= -MAIL_PORT= -MAIL_USERNAME= -MAIL_PASSWORD= - -#Sendinblue -SENDINBLUE_APIKEY= - -#Sendgrid -SENDGRID_APIKEY= - -#Mailgun -MAILGUN_APIKEY= -MAILGUN_DOMAIN= - -#Mandrill -MANDRILL_APIKEY= \ No newline at end of file diff --git a/tests/Feature/_root/modules/test/Resources/lang/en/custom.php b/tests/Feature/_root/modules/test/Resources/lang/en/custom.php deleted file mode 100644 index 4ce07e6..0000000 --- a/tests/Feature/_root/modules/test/Resources/lang/en/custom.php +++ /dev/null @@ -1,7 +0,0 @@ - 'Learn more', - 'info' => 'Information about the {%1} feature', - 'test' => 'Testing' -]; \ No newline at end of file diff --git a/tests/Feature/_root/modules/test/Views/index.php b/tests/Feature/_root/modules/test/Views/index.php deleted file mode 100644 index d2b6b20..0000000 --- a/tests/Feature/_root/modules/test/Views/index.php +++ /dev/null @@ -1 +0,0 @@ -

Hello , this is rendered view

\ No newline at end of file diff --git a/tests/Feature/_root/modules/test/Views/layout.php b/tests/Feature/_root/modules/test/Views/layout.php deleted file mode 100644 index e119b46..0000000 --- a/tests/Feature/_root/modules/test/Views/layout.php +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/tests/Feature/_root/modules/test/Views/partial.php b/tests/Feature/_root/modules/test/Views/partial.php deleted file mode 100644 index 12adce2..0000000 --- a/tests/Feature/_root/modules/test/Views/partial.php +++ /dev/null @@ -1 +0,0 @@ -

Hello , this is rendered partial view

\ No newline at end of file diff --git a/tests/Feature/_root/public/uploads/.gitkeep b/tests/Feature/_root/public/uploads/.gitkeep deleted file mode 100644 index 256c7f2..0000000 --- a/tests/Feature/_root/public/uploads/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -#qt diff --git a/tests/Feature/_root/shared/config/captcha.php b/tests/Feature/_root/shared/config/captcha.php deleted file mode 100644 index d088f37..0000000 --- a/tests/Feature/_root/shared/config/captcha.php +++ /dev/null @@ -1,17 +0,0 @@ - 'recaptcha', - - 'recaptcha' => [ - 'type' => 'visible', - 'secret_key' => '10000000-ffff-ffff-ffff-000000000001', - 'site_key' => '0x0000000000000000000000000000000000000000' - ], - - 'hcaptcha' => [ - 'type' => 'visible', - 'secret_key' => '0xE1a02fB374Bf228678E613645295A2d0fD0Dc5Fa', - 'site_key' => '07737dfc-abfa-44e3-a695-66ac44365d0c' - ] -]; diff --git a/tests/Feature/_root/shared/config/config.php b/tests/Feature/_root/shared/config/config.php deleted file mode 100644 index 7c20fa1..0000000 --- a/tests/Feature/_root/shared/config/config.php +++ /dev/null @@ -1,9 +0,0 @@ - ['en', 'es', 'fr'], - 'lang_default' => 'en', - 'lang_segment' => 1, - 'debug' => 'DEBUG', - 'test' => 'Testing' -]; \ No newline at end of file diff --git a/tests/Feature/_root/shared/config/database.php b/tests/Feature/_root/shared/config/database.php deleted file mode 100644 index a6cd325..0000000 --- a/tests/Feature/_root/shared/config/database.php +++ /dev/null @@ -1,34 +0,0 @@ - 'mysql', - 'mysql' => [ - 'driver' => 'mysql', - 'host' => 'localhost', - 'dbname' => 'database', - 'username' => 'username', - 'password' => 'password', - 'charset' => 'charset', - 'orm' => \Quantum\Libraries\Database\Idiorm\IdiormDbal::class - ], - 'sqlite' => [ - 'driver' => 'sqlite', - 'database' => ':memory:', - 'orm' => \Quantum\Libraries\Database\Idiorm\IdiormDbal::class - ], - 'sleekdb' => [ - 'config' => [ - 'auto_cache' => true, - 'cache_lifetime' => null, - 'timeout' => false, - 'search' => [ - 'min_length' => 2, - 'mode' => 'or', - 'score_key' => 'scoreKey', - 'algorithm' => 1 - ], - ], - 'database_dir' => base_dir() . DS . 'shared' . DS . 'store', - 'orm' => \Quantum\Libraries\Database\Sleekdb\SleekDbal::class - ] -]; \ No newline at end of file diff --git a/tests/Feature/_root/shared/config/dependencies.php b/tests/Feature/_root/shared/config/dependencies.php deleted file mode 100644 index c29cc1c..0000000 --- a/tests/Feature/_root/shared/config/dependencies.php +++ /dev/null @@ -1,5 +0,0 @@ - 'testing' -]; \ No newline at end of file diff --git a/tests/Feature/_root/shared/config/hooks.php b/tests/Feature/_root/shared/config/hooks.php deleted file mode 100644 index 293a655..0000000 --- a/tests/Feature/_root/shared/config/hooks.php +++ /dev/null @@ -1,5 +0,0 @@ - 'smtp', - - 'mail_trap' => true, - - 'smtp' => [ - 'host' => '127.0.0.1', - 'secure' => 'ssl', - 'port' => '80', - 'username' => 'test', - 'password' => 'test' - ], - - 'sendinblue' => [ - 'api_key' => 'sendinblue_api_key', - ], - - 'sendgrid' => [ - 'api_key' => 'sendgrid_api_key', - ], - - 'mandrill' => [ - 'api_key' => 'mandrill_api_key' - ], - - 'mailgun' => [ - 'api_key' => 'mailgun_api_key', - 'domain' => 'mailgun_domain', - ], -]; diff --git a/tests/Feature/_root/shared/config/modules.php b/tests/Feature/_root/shared/config/modules.php deleted file mode 100644 index 21943ab..0000000 --- a/tests/Feature/_root/shared/config/modules.php +++ /dev/null @@ -1,17 +0,0 @@ - [ - 'Api' => [ - 'prefix' => 'api', - 'enabled' => true, - ], - ] -]; diff --git a/tests/Feature/_root/shared/config/session.php b/tests/Feature/_root/shared/config/session.php deleted file mode 100644 index 9fd9b59..0000000 --- a/tests/Feature/_root/shared/config/session.php +++ /dev/null @@ -1,7 +0,0 @@ - 'sessions', - 'driver' => 'file', - 'timeout' => 300, -]; \ No newline at end of file diff --git a/tests/Feature/_root/shared/store/.gitkeep b/tests/Feature/_root/shared/store/.gitkeep deleted file mode 100644 index 256c7f2..0000000 --- a/tests/Feature/_root/shared/store/.gitkeep +++ /dev/null @@ -1 +0,0 @@ -#qt diff --git a/tests/Feature/_root/tmp/php8fe1.tmp b/tests/Feature/_root/tmp/php8fe1.tmp deleted file mode 100644 index e134ce2d6ce4ab2c8b6e73f5a829a06344a22025..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 9113 zcmd6M2UL^I*6vG3kt$tk=$Oz!q)H3Dgx-~sP^1?X5Kt)sp@x=#QbR9FF9H@okRl%t zdQrMGkuIQegZ}q^|2h9Tcdfhrb=SRjK^3!2K(U`h{u0j$Q}RSp|KN+g za5=g9dE)1I;4!bKM<9L;zuU!5uE4#_Oz2@S_(# zXaCwx;+k2q}kdTm)T_GpKH);xsOIK*A z>F8*wX=$%AvN2tyXJw$JW#(pPWoPH)cV4$l8<x8)X1oaK?o&GY_;0h6b zp|nJ_fHHu&^GEvsSub~T7_6_@)gV`P8HBU`pu1C4C$R>Sm_KG+O@kTC7^ zdGI9GB7vjG?QH@`%2fwGc2fv~5uC_bnwK)Pj+VL)A{!ATxbv$O^7^4v61(>fwH@Q9 z4pz;?rsKHLuJ}t`9!gDApIh=Y90~1op^e3So#W=)kqYxH4nGHD8rB3e>L|6cX82E0 zOUqO4w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sR$dv@vH(T+Il$e*vtEVB zW*xGY#wlpz6xexc?5*10Vx1s3FmJuifNpqrE4o~fJv}updJ$R9yBxHEVQSFcTdVh; z6B2h!k2<>ih5o*kMzC{ONfb++=*A#Cleyr>2x!uFN!yVMlYSbh37X2-r1!USHZE%E zk;|RZrsYj~jgG&;?pNVse!IfFoKE0la+S;NQ0qR}&pAMrTDHm7c)ZX!4N=6hhuI#` z{YCjao#NH8UXY$z*Uq&h=&bt@N7&1qQjUt?f=B_8(!~a8y;Ew%&o>O7J@5^+w?t~^ zdRQN_RwBx}W)gc;1W{G~3Q4YiiGQPJ&IyE+P;U|=f)Mq5ymtGN*N$I=oCCMcf#z_* zA2*9Pqazl#=r`eY)_Fled9vTB3+!O6UBRn-!jdpcm~5Ph!QHA+NYQ)2M!H}Mh4;fF zuUOYDL)?_zXZBd^x*>_&jTi}u$l(m@zJA}8mob`mk99qCnhRU#l4BTWs2HK8vC{3C zYH@R)x$^`D(&bEQi?#2m?Ff!B8L+#a3CHOMvyxl0RaVlX+Qk}KlU%`)Kv zUq3}juA(E$=5K^0Om1%}8dhjr4=A56ZG9@;T7txl@qn8+?#S3@SvrN!O}3foy5q{s zxC4pwcZX+q3~F33-mLPIoXpCd)1L-1=Xo!!ziQee``L4%x%ndC=jZU|b3l;%WQ#hU zb79+iRdC;UR$ From 8785ad42941a6e9f8cb65b2df5a5fc07565229dd Mon Sep 17 00:00:00 2001 From: Vahram Date: Thu, 31 Oct 2024 17:49:55 +0400 Subject: [PATCH 04/10] Adding commands for setup demo --- .github/workflows/php.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 4c969d0..5ae8ec6 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -42,6 +42,12 @@ jobs: - name: Install dependencies run: composer install --prefer-dist --no-progress + - name: Create env + run: php qt core:env + + - name: Create APP key + run: php qt core:key --length=64 + - name: Install demo run: php qt install:demo From 5955f28e4317262f4b36b877960932ce5110c91c Mon Sep 17 00:00:00 2001 From: Vahram Date: Thu, 31 Oct 2024 18:01:16 +0400 Subject: [PATCH 05/10] Removing property type declarations for version 7.3 --- tests/Feature/Api/AuthControllerTest.php | 17 ++++++++++----- tests/Feature/Api/PostControllerTest.php | 11 ++++++++-- tests/Feature/BaseTestCase.php | 16 ++++++++------ tests/Feature/TestData.php | 27 ++++++++++++++++++------ 4 files changed, 52 insertions(+), 19 deletions(-) diff --git a/tests/Feature/Api/AuthControllerTest.php b/tests/Feature/Api/AuthControllerTest.php index ca1d4d8..b76d7a1 100644 --- a/tests/Feature/Api/AuthControllerTest.php +++ b/tests/Feature/Api/AuthControllerTest.php @@ -10,8 +10,15 @@ class AuthControllerTest extends BaseTestCase { - protected string $email = 'test@test.test'; - protected string $password = 'password'; + /** + * @var string + */ + protected $email = 'test@test.test'; + + /** + * @var string + */ + protected $password = 'password'; public function setUp(): void { @@ -140,7 +147,7 @@ public function testActivateApi() ]); $userModel->save(); - $response = $this->request('get', '/api/en/activate/'. $activationToken); + $response = $this->request('get', '/api/en/activate/' . $activationToken); $this->assertEquals('success', $response->get('status')); $this->assertEquals('Account is activated', $response->get('message')); @@ -167,7 +174,7 @@ public function testResetApi() ]); $userModel->save(); - $response = $this->request('post', '/api/en/reset/'. $resetToken, [ + $response = $this->request('post', '/api/en/reset/' . $resetToken, [ 'password' => $this->password, 'repeat_password' => $this->password, ]); @@ -196,7 +203,7 @@ public function testResendApi() 'otp_token' => $otpToken ]); $userModel->save(); - $response = $this->request('get', '/api/en/resend/'. $otpToken); + $response = $this->request('get', '/api/en/resend/' . $otpToken); $this->assertEquals('success', $response->get('status')); $this->assertArrayHasKey('code', $response->all()); diff --git a/tests/Feature/Api/PostControllerTest.php b/tests/Feature/Api/PostControllerTest.php index 7efac66..090448e 100644 --- a/tests/Feature/Api/PostControllerTest.php +++ b/tests/Feature/Api/PostControllerTest.php @@ -12,8 +12,15 @@ class PostControllerTest extends BaseTestCase { - protected string $email = 'test@test.test'; - protected string $password = 'password'; + /** + * @var string + */ + protected $email = 'test@test.test'; + + /** + * @var string + */ + protected $password = 'password'; public function setUp(): void { diff --git a/tests/Feature/BaseTestCase.php b/tests/Feature/BaseTestCase.php index 4dea60c..57b87ff 100644 --- a/tests/Feature/BaseTestCase.php +++ b/tests/Feature/BaseTestCase.php @@ -15,11 +15,15 @@ class BaseTestCase extends TestCase { - protected HttpClient $client; + /** + * @var HttpClient + */ + protected $client; - protected static bool $isDatabasePrepared = false; - - protected string $baseUrl; + /** + * @var string + */ + protected $baseUrl; public function setUp(): void { @@ -60,10 +64,10 @@ public function tearDown(): void TestData::deleteUserData(); TestData::deletePostData(); - foreach (array_diff(scandir(uploads_dir()), array('.', '..', '.gitkeep')) as $item){ + foreach (array_diff(scandir(uploads_dir()), array('.', '..', '.gitkeep')) as $item) { if (is_dir(uploads_dir() . DS . $item)) { rmdir(uploads_dir() . DS . $item); - }elseif (is_file(uploads_dir() . DS . $item)) { + } elseif (is_file(uploads_dir() . DS . $item)) { unlink(uploads_dir() . DS . $item); } } diff --git a/tests/Feature/TestData.php b/tests/Feature/TestData.php index 414e886..f85adc4 100644 --- a/tests/Feature/TestData.php +++ b/tests/Feature/TestData.php @@ -11,11 +11,26 @@ class TestData { - protected static Generator $faker; + /** + * @var Generator + */ + protected static $faker; + + /** + * @var string + */ + protected static $email = 'test@test.test'; + + /** + * @var string + */ + protected static $role = 'editor'; + + /** + * @var string + */ + protected static $password = 'password'; - protected static string $email = 'test@test.test'; - protected static string $role = 'editor'; - protected static string $password = 'password'; public static function createUserData() { self::$faker = Factory::create(); @@ -37,8 +52,8 @@ public static function createPostData() $users = ServiceFactory::get(AuthService::class)->getAll(); $postService = ServiceFactory::get(PostService::class); - foreach ($users as $user){ - for ($i = 0; $i < 10; $i++){ + foreach ($users as $user) { + for ($i = 0; $i < 10; $i++) { $title = str_replace(['"', '\'', '-'], '', self::$faker->realText(50)); $postData = [ From 9b1ff1b6afeda21942dc187a42c2e52279373728 Mon Sep 17 00:00:00 2001 From: Vahram Date: Thu, 31 Oct 2024 18:04:29 +0400 Subject: [PATCH 06/10] Correcting install demo command --- .github/workflows/php.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/php.yml b/.github/workflows/php.yml index 5ae8ec6..852f06c 100644 --- a/.github/workflows/php.yml +++ b/.github/workflows/php.yml @@ -49,7 +49,7 @@ jobs: run: php qt core:key --length=64 - name: Install demo - run: php qt install:demo + run: php qt install:demo --yes - name: Run tests run: composer test From b52e7274e71c5cad02cc775fcf314f79cb3b618d Mon Sep 17 00:00:00 2001 From: Vahram Date: Thu, 31 Oct 2024 18:16:20 +0400 Subject: [PATCH 07/10] Correcting removing data from uploads directory --- tests/Feature/BaseTestCase.php | 30 +++++++++++++++++++++++------- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/tests/Feature/BaseTestCase.php b/tests/Feature/BaseTestCase.php index 57b87ff..8bfc7b8 100644 --- a/tests/Feature/BaseTestCase.php +++ b/tests/Feature/BaseTestCase.php @@ -64,13 +64,7 @@ public function tearDown(): void TestData::deleteUserData(); TestData::deletePostData(); - foreach (array_diff(scandir(uploads_dir()), array('.', '..', '.gitkeep')) as $item) { - if (is_dir(uploads_dir() . DS . $item)) { - rmdir(uploads_dir() . DS . $item); - } elseif (is_file(uploads_dir() . DS . $item)) { - unlink(uploads_dir() . DS . $item); - } - } + $this->deleteDirectory(uploads_dir()); } private function loadAppFunctionality() @@ -86,5 +80,27 @@ private function loadAppFunctionality() Environment::getInstance()->load(new Setup('config', 'env')); } + + private function deleteDirectory(string $dir) + { + if (!is_dir($dir)) { + return; + } + + $files = array_diff(scandir($dir), array('.', '..', '.gitkeep')); + + foreach ($files as $file) { + $path = "$dir/$file"; + if (is_dir($path)) { + $this->deleteDirectory($path); + } else { + unlink($path); + } + } + + if ($dir != uploads_dir()) { + rmdir($dir); + } + } } From c566c250c0c0a24f722bbfd62322504931e2c916 Mon Sep 17 00:00:00 2001 From: Vahram Date: Thu, 31 Oct 2024 18:46:50 +0400 Subject: [PATCH 08/10] Removing unused classes --- tests/Feature/Api/PostControllerTest.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/tests/Feature/Api/PostControllerTest.php b/tests/Feature/Api/PostControllerTest.php index 090448e..51a36fc 100644 --- a/tests/Feature/Api/PostControllerTest.php +++ b/tests/Feature/Api/PostControllerTest.php @@ -3,12 +3,9 @@ namespace Quantum\Tests\Feature\Api; use Quantum\Tests\Feature\BaseTestCase; -use Quantum\Libraries\Hasher\Hasher; use Quantum\Factory\ModelFactory; use Quantum\Router\Router; use Shared\Models\Post; -use Shared\Models\User; -use Faker\Factory; class PostControllerTest extends BaseTestCase { From 7cc097630a96f7edbec54d5d88bc328bee4b4ada Mon Sep 17 00:00:00 2001 From: Vahram Date: Fri, 1 Nov 2024 12:19:14 +0400 Subject: [PATCH 09/10] Removing unused statements --- tests/Feature/Api/AuthControllerTest.php | 6 ------ tests/Feature/BaseTestCase.php | 7 ------- 2 files changed, 13 deletions(-) diff --git a/tests/Feature/Api/AuthControllerTest.php b/tests/Feature/Api/AuthControllerTest.php index b76d7a1..3689b6b 100644 --- a/tests/Feature/Api/AuthControllerTest.php +++ b/tests/Feature/Api/AuthControllerTest.php @@ -52,9 +52,6 @@ public function testSignInWithIncorrectRequestApi() public function testMeApi() { Router::setCurrentRoute([ - 'route' => '/api/en/signin', - 'prefix' => 'api', - 'method' => 'POST', 'module' => 'Api', ]); $tokens = auth()->signin($this->email, $this->password); @@ -83,9 +80,6 @@ public function testMeIncorrectApi() public function testSignoutApi() { Router::setCurrentRoute([ - 'route' => '/api/en/signin', - 'prefix' => 'api', - 'method' => 'POST', 'module' => 'Api', ]); $tokens = auth()->signin($this->email, $this->password); diff --git a/tests/Feature/BaseTestCase.php b/tests/Feature/BaseTestCase.php index 8bfc7b8..8108df6 100644 --- a/tests/Feature/BaseTestCase.php +++ b/tests/Feature/BaseTestCase.php @@ -8,7 +8,6 @@ use PHPUnit\Framework\TestCase; use Quantum\Http\Response; use Quantum\Http\Request; -use Quantum\Loader\Loader; use Quantum\Loader\Setup; use Quantum\Di\Di; use Quantum\App; @@ -45,7 +44,6 @@ public function request(string $method, string $url, array $options = [], array if (!empty($headers)) { foreach ($headers as $name => $value) { $_SERVER['HTTP_' . strtoupper($name)] = $value; - Request::setHeader($name, $value); } } @@ -73,11 +71,6 @@ private function loadAppFunctionality() App::loadCoreFunctions(dirname(__DIR__, 2) . DS . 'vendor' . DS . 'quantum' . DS . 'framework' . DS . 'src' . DS . 'Helpers'); Di::loadDefinitions(); - $loader = Di::get(Loader::class); - $loader->loadDir(base_dir() . DS . 'helpers'); - $loader->loadDir(base_dir() . DS . 'libraries'); - $loader->loadDir(base_dir() . DS . 'hooks'); - Environment::getInstance()->load(new Setup('config', 'env')); } From b78d0dfd0117d0053f06c600080e85f1c6997d50 Mon Sep 17 00:00:00 2001 From: Vahram Date: Fri, 1 Nov 2024 17:21:05 +0400 Subject: [PATCH 10/10] Cleaning up feature tests --- tests/Feature/Api/AuthControllerTest.php | 15 +++----- tests/Feature/Api/PostControllerTest.php | 35 ++++--------------- .../{BaseTestCase.php => AppTestCase.php} | 13 +++++-- 3 files changed, 21 insertions(+), 42 deletions(-) rename tests/Feature/{BaseTestCase.php => AppTestCase.php} (89%) diff --git a/tests/Feature/Api/AuthControllerTest.php b/tests/Feature/Api/AuthControllerTest.php index 3689b6b..f5dc536 100644 --- a/tests/Feature/Api/AuthControllerTest.php +++ b/tests/Feature/Api/AuthControllerTest.php @@ -2,13 +2,12 @@ namespace Quantum\Tests\Feature\Api; -use Quantum\Tests\Feature\BaseTestCase; +use Quantum\Tests\Feature\AppTestCase; use Quantum\Libraries\Hasher\Hasher; use Quantum\Factory\ModelFactory; -use Quantum\Router\Router; use Shared\Models\User; -class AuthControllerTest extends BaseTestCase +class AuthControllerTest extends AppTestCase { /** * @var string @@ -51,10 +50,7 @@ public function testSignInWithIncorrectRequestApi() public function testMeApi() { - Router::setCurrentRoute([ - 'module' => 'Api', - ]); - $tokens = auth()->signin($this->email, $this->password); + $tokens = $this->signInAndReturnTokens(); $response = $this->request('get', '/api/en/me', [], ['Authorization' => 'Bearer ' . $tokens['access_token']]); @@ -79,10 +75,7 @@ public function testMeIncorrectApi() public function testSignoutApi() { - Router::setCurrentRoute([ - 'module' => 'Api', - ]); - $tokens = auth()->signin($this->email, $this->password); + $tokens = $this->signInAndReturnTokens(); $response = $this->request('get', '/api/en/signout', [], [ 'Authorization' => 'Bearer ' . $tokens['access_token'], diff --git a/tests/Feature/Api/PostControllerTest.php b/tests/Feature/Api/PostControllerTest.php index 51a36fc..c521234 100644 --- a/tests/Feature/Api/PostControllerTest.php +++ b/tests/Feature/Api/PostControllerTest.php @@ -2,12 +2,11 @@ namespace Quantum\Tests\Feature\Api; -use Quantum\Tests\Feature\BaseTestCase; +use Quantum\Tests\Feature\AppTestCase; use Quantum\Factory\ModelFactory; -use Quantum\Router\Router; use Shared\Models\Post; -class PostControllerTest extends BaseTestCase +class PostControllerTest extends AppTestCase { /** * @var string @@ -68,10 +67,7 @@ public function testSinglePostApi() public function testMyPostsApi() { - Router::setCurrentRoute([ - 'module' => 'Api', - ]); - $tokens = auth()->signin($this->email, $this->password); + $tokens = $this->signInAndReturnTokens(); $response = $this->request('get', '/api/en/my-posts', [], [ 'Authorization' => 'Bearer ' . $tokens['access_token'], @@ -92,10 +88,7 @@ public function testMyPostsApi() public function testPostCreateApi() { - Router::setCurrentRoute([ - 'module' => 'Api', - ]); - $tokens = auth()->signin($this->email, $this->password); + $tokens = $this->signInAndReturnTokens(); $response = $this->request('post', '/api/en/my-posts/create', [ @@ -115,12 +108,7 @@ public function testPostCreateApi() public function testAmendPostApi() { $post = ModelFactory::get(Post::class)->first(); - - Router::setCurrentRoute([ - 'module' => 'Api', - ]); - - $tokens = auth()->signin($this->email, $this->password); + $tokens = $this->signInAndReturnTokens(); $response = $this->request('put', '/api/en/my-posts/amend/' . $post->uuid, [ @@ -138,12 +126,7 @@ public function testAmendPostApi() public function testDeletePostApi() { $post = ModelFactory::get(Post::class)->first(); - - Router::setCurrentRoute([ - 'module' => 'Api', - ]); - - $tokens = auth()->signin($this->email, $this->password); + $tokens = $this->signInAndReturnTokens(); $response = $this->request('delete', '/api/en/my-posts/delete/' . $post->uuid, [], [ 'Authorization' => 'Bearer ' . $tokens['access_token'] @@ -157,11 +140,7 @@ public function testDeletePostApi() public function testDeleteImagePostApi() { $post = ModelFactory::get(Post::class)->first(); - Router::setCurrentRoute([ - 'module' => 'Api', - ]); - - $tokens = auth()->signin($this->email, $this->password); + $tokens = $this->signInAndReturnTokens(); $response = $this->request('delete', '/api/en/my-posts/delete-image/' . $post->uuid, [], [ 'Authorization' => 'Bearer ' . $tokens['access_token'] diff --git a/tests/Feature/BaseTestCase.php b/tests/Feature/AppTestCase.php similarity index 89% rename from tests/Feature/BaseTestCase.php rename to tests/Feature/AppTestCase.php index 8108df6..396352a 100644 --- a/tests/Feature/BaseTestCase.php +++ b/tests/Feature/AppTestCase.php @@ -11,8 +11,9 @@ use Quantum\Loader\Setup; use Quantum\Di\Di; use Quantum\App; +use Quantum\Router\Router; -class BaseTestCase extends TestCase +class AppTestCase extends TestCase { /** * @var HttpClient @@ -38,8 +39,6 @@ public function request(string $method, string $url, array $options = [], array $_SERVER['REQUEST_METHOD'] = strtoupper($method); $_SERVER['CONTENT_TYPE'] = $contentType; $_SERVER['REQUEST_URI'] = $url; - $_SERVER['SERVER_NAME'] = '127.0.0.1'; - $_SERVER['SERVER_PORT'] = '8000'; if (!empty($headers)) { foreach ($headers as $name => $value) { @@ -65,6 +64,14 @@ public function tearDown(): void $this->deleteDirectory(uploads_dir()); } + protected function signInAndReturnTokens(): array + { + Router::setCurrentRoute([ + 'module' => 'Api', + ]); + return auth()->signin($this->email, $this->password); + } + private function loadAppFunctionality() { App::setBaseDir(dirname(__DIR__, 2));