Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jenkin integration fail #8259

Closed
wants to merge 18 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 13 additions & 5 deletions app/Console/Commands/SetupTestEnv.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Console\Commands;

use App\Model\helpdesk\Settings\System;
use Database\Seeders\v_2_0_0\DatabaseSeeder;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\Artisan;
use Illuminate\Support\Facades\Config;
Expand All @@ -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.
Expand Down Expand Up @@ -43,10 +44,11 @@ public function handle()
{
$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";

Expand All @@ -63,7 +65,7 @@ public function handle()
//closing the database connection
DB::disconnect('mysql');

$this->createEnv($dbUsername, $dbPassword);
$this->createEnv($dbUsername, $dbPassword, $dbName);

$this->updateAppUrl();

Expand Down Expand Up @@ -144,7 +146,7 @@ private function seed()
{
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) {
Expand All @@ -159,7 +161,13 @@ private function seed()
*/
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";
}
}

/**
Expand Down
20 changes: 20 additions & 0 deletions config/database.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@
]) : [],
],

'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'),
Expand Down
32 changes: 20 additions & 12 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,27 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" backupStaticAttributes="false" bootstrap="bootstrap/autoload.php" colors="true" convertErrorsToExceptions="true" convertNoticesToExceptions="true" convertWarningsToExceptions="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
<coverage includeUncoveredFiles="true">
<include>
<directory suffix=".php">app/</directory>
</include>
</coverage>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="bootstrap/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="feature">
<directory>tests/Feature</directory>
<testsuite name="all">
<directory>./tests/</directory>
</testsuite>
<testsuite name="unit">
<directory>tests/Unit</directory>
<directory>./tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist addUncoveredFilesFromWhitelist="true">
<directory suffix=".php">app/</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<!-- <env name="DB_CONNECTION" value="testing"/>
<env name="DB_DATABASE" value="testing_db"/> -->
<env name="DB_CONNECTION" value="testing"/>
<env name="DB_DATABASE" value="testing_db"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_CONNECTION" value="sync"/>
<env name="MAIL_MAILER" value="mail"/>
<env name="APP_URL" value="http://localhost:8000"/>
<env name="DB_INSTALL" value="1"/>
</php>
</phpunit>
</phpunit>
56 changes: 56 additions & 0 deletions tests/Unit/RouteTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
<?php

namespace Tests\Unit;

use App\User;
use Faker\Factory as FakerFactory;
use Illuminate\Support\Facades\Hash;
use Tests\TestCase;

class RouteTest extends TestCase
{
/**
* A basic unit test example.
*
* @return void
*/
public function test_example()
{
$this->assertTrue(true);
}

public function test_store_user()
{
$faker = FakerFactory::create();

//Create User -> Agent

//$str = Str::random(10);
$str = 'demopass';
$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,
'assign_group' => 1,
'primary_dpt' => 1,
'active' => 1,
'role' => 'agent',
'agent_tzone' => 81,
]);
$user->save();

// Check if data is inserted
//$this->assertDatabaseHas('users', ['email' => $email]);

// Authenticate as the created user
$this->actingAs($user);

$this->assertAuthenticated();

$this->assertDatabaseMissing('users', ['email' => $email]);
}
}