From 6aea3beec15b32bf2e43ab1aa7319342f8058738 Mon Sep 17 00:00:00 2001 From: zigzagdev Date: Tue, 27 Dec 2022 21:53:14 +0900 Subject: [PATCH 1/4] phpUnitTest_dbCreated --- config/database.php | 19 ++++++++++++ phpunit.xml | 3 +- tests/Feature/Api/AdminCreateTest.php | 44 +++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 2 deletions(-) create mode 100644 tests/Feature/Api/AdminCreateTest.php diff --git a/config/database.php b/config/database.php index b42d9b3..aafb25d 100644 --- a/config/database.php +++ b/config/database.php @@ -77,6 +77,25 @@ 'schema' => 'public', 'sslmode' => 'prefer', ], + 'mountain_test' => [ + 'driver' => 'mysql', + 'url' => env('DATABASE_URL'), + 'host' => env('DB_HOST', '127.0.0.1'), + 'port' => env('DB_PORT', '3306'), + 'database' => env('DB_DATABASE', 'forge'), + 'username' => env('DB_USERNAME', 'forge'), + 'password' => env('DB_PASSWORD', ''), + 'unix_socket' => env('DB_SOCKET', ''), + 'charset' => 'utf8mb4', + 'collation' => 'utf8mb4_unicode_ci', + 'prefix' => '', + 'prefix_indexes' => true, + 'strict' => true, + 'engine' => null, + 'options' => extension_loaded('pdo_mysql') ? array_filter([ + PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'), + ]) : [] + ], 'sqlsrv' => [ 'driver' => 'sqlsrv', diff --git a/phpunit.xml b/phpunit.xml index 4ae4d97..1336036 100644 --- a/phpunit.xml +++ b/phpunit.xml @@ -21,11 +21,10 @@ - - + diff --git a/tests/Feature/Api/AdminCreateTest.php b/tests/Feature/Api/AdminCreateTest.php new file mode 100644 index 0000000..ef7b1fc --- /dev/null +++ b/tests/Feature/Api/AdminCreateTest.php @@ -0,0 +1,44 @@ +json('POST', 'api/registerUser') + ->assertStatus(400) + ->assertJson([ + "message" => "Bad Request...", + "errors" => [ + 'address' => ["The email field is required."], + 'password' => ["The password field is required."], + 'age' => ["The age filed is required."], + 'sex' => ["The sex filed is required."], + ] + ]); + + // Success registerUser at here. + $this->json('POST', 'api/registerUser') + ->assertStatus(201) + ->assertJson([ + "message" => "User was created successfully", + ]); + + } +} From e6bf16544141829dfdfa5841918f9610ea011f1d Mon Sep 17 00:00:00 2001 From: zigzagdev Date: Fri, 30 Dec 2022 15:32:53 +0900 Subject: [PATCH 2/4] featureTest_create --- .env.testing | 51 ++++++++++++++++++ tests/Feature/Api/AdminCreateTest.php | 44 ---------------- tests/Feature/Api/AdminTest.php | 52 +++++++++++++++++++ .../{ExampleTest.php => Api/NewsTest.php} | 7 +-- tests/Feature/Api/RegisterUserTest.php.php | 39 -------------- tests/Feature/Feature/Api/AdminTest.php | 22 ++++++++ 6 files changed, 129 insertions(+), 86 deletions(-) create mode 100644 .env.testing delete mode 100644 tests/Feature/Api/AdminCreateTest.php create mode 100644 tests/Feature/Api/AdminTest.php rename tests/Feature/{ExampleTest.php => Api/NewsTest.php} (63%) delete mode 100644 tests/Feature/Api/RegisterUserTest.php.php create mode 100644 tests/Feature/Feature/Api/AdminTest.php diff --git a/.env.testing b/.env.testing new file mode 100644 index 0000000..e854750 --- /dev/null +++ b/.env.testing @@ -0,0 +1,51 @@ +APP_NAME=testing +APP_ENV=mountain_test +APP_KEY=base64:dW8mf76HLLHs+FgYrVLSp3aW7VyTWZhw8gP2vKXJXo8= +APP_DEBUG=true +APP_URL=http://localhost + +LOG_CHANNEL=stack +LOG_DEPRECATIONS_CHANNEL=null +LOG_LEVEL=debug + +DB_CONNECTION=mysql +DB_HOST=127.0.0.1 +DB_PORT=3306 +DB_DATABASE=mountain_test +DB_USERNAME=root +DB_PASSWORD=root + +BROADCAST_DRIVER=log +CACHE_DRIVER=file +FILESYSTEM_DRIVER=local +QUEUE_CONNECTION=sync +SESSION_DRIVER=file +SESSION_LIFETIME=120 + +MEMCACHED_HOST=127.0.0.1 + +REDIS_HOST=127.0.0.1 +REDIS_PASSWORD=null +REDIS_PORT=6379 + +MAIL_DRIVER=smtp +MAIL_HOST=smtp.gmail.com +MAIL_PORT=465 +MAIL_USERNAME=msts.oo0131@gmail.com +MAIL_PASSWORD=qvzbziunlagondly +MAIL_ENCRYPTION=ssl +MAIL_FROM_NAME=Newsletter + +AWS_ACCESS_KEY_ID= +AWS_SECRET_ACCESS_KEY= +AWS_DEFAULT_REGION=us-east-1 +AWS_BUCKET= +AWS_USE_PATH_STYLE_ENDPOINT=false + +PUSHER_APP_ID= +PUSHER_APP_KEY= +PUSHER_APP_SECRET= +PUSHER_APP_CLUSTER=mt1 + +MIX_PUSHER_APP_KEY="${PUSHER_APP_KEY}" +MIX_PUSHER_APP_CLUSTER="${PUSHER_APP_CLUSTER}" diff --git a/tests/Feature/Api/AdminCreateTest.php b/tests/Feature/Api/AdminCreateTest.php deleted file mode 100644 index ef7b1fc..0000000 --- a/tests/Feature/Api/AdminCreateTest.php +++ /dev/null @@ -1,44 +0,0 @@ -json('POST', 'api/registerUser') - ->assertStatus(400) - ->assertJson([ - "message" => "Bad Request...", - "errors" => [ - 'address' => ["The email field is required."], - 'password' => ["The password field is required."], - 'age' => ["The age filed is required."], - 'sex' => ["The sex filed is required."], - ] - ]); - - // Success registerUser at here. - $this->json('POST', 'api/registerUser') - ->assertStatus(201) - ->assertJson([ - "message" => "User was created successfully", - ]); - - } -} diff --git a/tests/Feature/Api/AdminTest.php b/tests/Feature/Api/AdminTest.php new file mode 100644 index 0000000..4cb7201 --- /dev/null +++ b/tests/Feature/Api/AdminTest.php @@ -0,0 +1,52 @@ + 'test1234', + 'address'=>'test1234@com', + 'password' => bcrypt('secret123$'), + 'age' => '30', + 'sex' => '1' + ]); + + $data = [ + 'email' => '', + 'password' => 'secret123$', + ]; + + //attempt login + $response = $this->json('POST', redirect('http://127.0.0.1:8000/api/login'), $data); + //Assert it was successful and a token was received + $response->assertStatus(404); + } + +// public function testLoginSuccess() +// { +// // When the Parameter is null, response this errorMessages. +// $response = $this->postJson('/api/login', ['email' => ''], ['password' => Hash::make('test1234')]); +// $response +// ->assertStatus(401) +// ->assertJson([ +// 'created' => false, +// ]); +// } +} diff --git a/tests/Feature/ExampleTest.php b/tests/Feature/Api/NewsTest.php similarity index 63% rename from tests/Feature/ExampleTest.php rename to tests/Feature/Api/NewsTest.php index 4ae02bc..8df6028 100644 --- a/tests/Feature/ExampleTest.php +++ b/tests/Feature/Api/NewsTest.php @@ -1,14 +1,15 @@ json('POST', 'api/RegisterUser') - ->assertStatus(401) - ->assertJson([ - "message" => "Bad Request...", - "errors" => [ - 'address' => ["The email field is required."], - 'password' => ["The password field is required."], - 'age' => ["The age filed is required."], - 'sex' => ["The sex filed is required."], - ] - ]); - - // Success registerUser at here. - $this->json('POST', 'api/RegisterUser') - ->assertStatus(201) - ->assertJson([ - "message" => "User was created successfully", - ]); - - } -} diff --git a/tests/Feature/Feature/Api/AdminTest.php b/tests/Feature/Feature/Api/AdminTest.php new file mode 100644 index 0000000..92fcccb --- /dev/null +++ b/tests/Feature/Feature/Api/AdminTest.php @@ -0,0 +1,22 @@ +get('/'); + + $response->assertStatus(200); + } +} From 6865fb6da041bde2733c2cf8ad20e1383571ce98 Mon Sep 17 00:00:00 2001 From: zigzagdev Date: Fri, 30 Dec 2022 16:22:52 +0900 Subject: [PATCH 3/4] gitIgnore_Fix --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index eb003b0..5a39615 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ /storage/*.key /vendor .env +.env.testing .env.backup .phpunit.result.cache docker-compose.override.yml From cfadb8ca6525c85206650721edfd5318cec86288 Mon Sep 17 00:00:00 2001 From: zigzagdev Date: Sat, 7 Jan 2023 14:23:27 +0900 Subject: [PATCH 4/4] factoryData_fix --- database/factories/UserFactory.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/database/factories/UserFactory.php b/database/factories/UserFactory.php index a3eb239..2acf810 100644 --- a/database/factories/UserFactory.php +++ b/database/factories/UserFactory.php @@ -4,6 +4,8 @@ use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Support\Str; +use Illuminate\Support\Facades\Hash; +use Illuminate\Testing\Fluent\Concerns\Has; class UserFactory extends Factory { @@ -17,8 +19,7 @@ public function definition() return [ 'name' => $this->faker->name(), 'email' => $this->faker->unique()->safeEmail(), - 'email_verified_at' => now(), - 'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password + 'password' => Hash::make('test1234'), // password 'remember_token' => Str::random(10), ]; }