diff --git a/app/Console/Commands/SetupTestEnv.php b/app/Console/Commands/SetupTestEnv.php
index f3877a819..4a1652e28 100644
--- a/app/Console/Commands/SetupTestEnv.php
+++ b/app/Console/Commands/SetupTestEnv.php
@@ -7,6 +7,7 @@ use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Config;
use Illuminate\Support\Facades\DB;
+use Database\Seeders\v_2_0_0\DatabaseSeeder;
class SetupTestEnv extends Command
{
@@ -15,7 +16,7 @@ class SetupTestEnv extends Command
*
* @var string
*/
- protected $signature = 'testing-setup {--username=} {--password=}';
+ protected $signature = 'testing-setup {--username=} {--password=} {--database=}';
/**
* The console command description.
@@ -43,10 +44,11 @@ class SetupTestEnv extends Command
{
$dbUsername = $this->option('username') ? $this->option('username') : env('DB_USERNAME');
$dbPassword = $this->option('password') ? $this->option('password') : (env('DB_PASSWORD'));
+ $dbName = $this->option('database') ? $this->option('database') : 'testing_db';
+
$this->setupConfig($dbUsername, $dbPassword);
echo "\nCreating database...\n";
- $dbName = 'testing_db';
createDB($dbName);
echo "\nDatabase Created Successfully!\n";
@@ -144,7 +146,7 @@ class SetupTestEnv extends Command
{
try {
echo "\nSeeding...\n";
- Artisan::call('db:seed', ['--force' => true]);
+ Artisan::call('db:seed', ['--class' => DatabaseSeeder::class, '--force' => true]);
echo Artisan::output();
echo "\nSeeded Successfully!\n";
} catch (\Exception $e) {
@@ -159,7 +161,13 @@ class SetupTestEnv extends Command
*/
private function updateAppUrl()
{
- return System::first()->update(['url' => 'http://localhost:8000']);
+ $system = System::latest()->first();
+
+ if ($system) {
+ $system->update(['url' => 'http://localhost:8000']);
+ } else {
+ echo "\nData doesn't exists";
+ }
}
/**
diff --git a/config/database.php b/config/database.php
index c112d3eb6..60cf6ec56 100644
--- a/config/database.php
+++ b/config/database.php
@@ -63,6 +63,26 @@ return [
]) : [],
],
+ 'testing' => [
+ 'driver' => 'mysql',
+ 'url' => env('DATABASE_URL'),
+ 'host' => env('DB_HOST', 'localhost'),
+ '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' => false,
+ 'engine' => env('DB_ENGINE', null),
+ 'options' => extension_loaded('pdo_mysql') ? array_filter([
+ PDO::MYSQL_ATTR_SSL_CA => env('MYSQL_ATTR_SSL_CA'),
+ ]) : [],
+ ],
+
'pgsql' => [
'driver' => 'pgsql',
'url' => env('DATABASE_URL'),
diff --git a/phpunit.xml b/phpunit.xml
index b12fae924..414bb090b 100755
--- a/phpunit.xml
+++ b/phpunit.xml
@@ -13,7 +13,7 @@
./tests/
- ./tests/unit
+ ./tests/Unit
diff --git a/tests/Unit/ExampleTest.php b/tests/Unit/ExampleTest.php
new file mode 100644
index 000000000..5c3ae4354
--- /dev/null
+++ b/tests/Unit/ExampleTest.php
@@ -0,0 +1,50 @@
+assertTrue(true);
+ }
+
+ public function test_store_user()
+ {
+ $faker = FakerFactory::create();
+
+ //Create User -> Agent
+ $str = Str::random(10);
+ $password = Hash::make($str);
+ $email = $faker->unique()->email();
+ $user = new User([
+ 'first_name' => $faker->firstName(),
+ 'last_name' => $faker->lastName(),
+ 'email' => $email,
+ 'user_name' => $faker->unique()->userName(),
+ 'password' => $password,
+ 'active' => 1,
+ 'role' => 'user',
+ ]);
+ $user->save();
+
+ // Check if data is inserted
+ $this->assertDatabaseHas('users', ['email' => $email]);
+
+ // Authenticate as the created user
+ $this->actingAs($user);
+
+ $this->assertAuthenticated();
+ }
+}