prepaeres to some code for the tests

This commit is contained in:
Berkay Güre 2018-07-14 13:22:33 +03:00
parent 1745f0a41e
commit 12bdb951f9
23 changed files with 1559 additions and 163 deletions

24
.env.testing Normal file
View File

@ -0,0 +1,24 @@
APP_NAME=Akaunting
APP_ENV=testing
APP_LOCALE=en-GB
APP_INSTALLED=false
APP_KEY=base64:xBC+BxlC7sXhYAtpTZv8TYAHqoPgsJaXL0S5Id6BbBc=
APP_DEBUG=true
APP_LOG_LEVEL=debug
APP_URL=http://akaunting.test
DB_CONNECTION=sqlite
DB_DATABASE=:memory:
DB_PREFIX=
BROADCAST_DRIVER=log
CACHE_DRIVER=file
SESSION_DRIVER=file
QUEUE_DRIVER=database
MAIL_DRIVER=mail
MAIL_HOST=localhost
MAIL_PORT=2525
MAIL_USERNAME=null
MAIL_PASSWORD=null
MAIL_ENCRYPTION=null

View File

@ -39,6 +39,10 @@ class Info
public static function mysqlVersion()
{
if(\App::environment() === "testing") {
return DB::selectOne('select sqlite_version() as mversion')->mversion;
}
return DB::selectOne('select version() as mversion')->mversion;
}
}

View File

@ -38,7 +38,8 @@
"tucker-eric/eloquentfilter": "1.1.*"
},
"require-dev": {
"fzaninotto/faker": "1.6.*"
"fzaninotto/faker": "1.6.*",
"phpunit/phpunit": "^7.0"
},
"autoload": {
"classmap": [

1490
composer.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,28 @@
<?php
use Faker\Generator;
use App\Models\Auth\User;
use App\Models\Common\Item;
use App\Models\Common\Company;
use Illuminate\Database\Eloquent\Factory;
/** @var Factory $factory */
$factory->define(Item::class, function (Generator $faker) {
/** @var User $user */
$user = User::first();
/** @var Company $company */
$company = $user->companies()->first();
return [
'name' => $faker->title,
'sku' => $faker->languageCode,
'company_id' => $company->id,
'description' => $faker->text(100),
'purchase_price' => $faker->randomFloat(2,10,20),
'sale_price' => $faker->randomFloat(2,10,20),
'quantity' => $faker->randomNumber(2),
'category_id' => $company->categories()->first()->id,
'tax_id' => $company->taxes()->first()->id,
'enabled' => $this->faker->boolean ? 1 : 0
];
});

View File

@ -12,7 +12,7 @@
*/
/** @var \Illuminate\Database\Eloquent\Factory $factory */
$factory->define(App\User::class, function (Faker\Generator $faker) {
$factory->define(\App\Models\Auth\User::class, function (Faker\Generator $faker) {
static $password;
return [

View File

@ -29,10 +29,18 @@ class AddCurrencyColumns extends Migration
{
Schema::table('currencies', function ($table) {
$table->dropColumn('precision');
$table->dropColumn('symbol');
$table->dropColumn('symbol_first');
$table->dropColumn('decimal_mark');
$table->dropColumn('thousands_separator');
});
Schema::table('currencies', function ($table) {
$table->dropColumn('symbol');
});
Schema::table('currencies', function ($table) {
$table->dropColumn('symbol_first');
});
Schema::table('currencies', function ($table) {
$table->dropColumn('decimal_mark');
});
Schema::table('currencies', function ($table) {
$table->dropColumn('thousands_separator');
});
}
}

View File

@ -12,11 +12,11 @@ class AddCategoryColumnInvoicesBills extends Migration
public function up()
{
Schema::table('invoices', function ($table) {
$table->integer('category_id');
$table->integer('category_id')->nullable();
});
Schema::table('bills', function ($table) {
$table->integer('category_id');
$table->integer('category_id')->nullable();
});
}

View File

@ -2,6 +2,7 @@
namespace Database\Seeds;
use App\Models\Common\Company;
use App\Models\Model;
use App\Models\Banking\Account;
use Setting;
@ -25,7 +26,7 @@ class Accounts extends Seeder
private function create()
{
$company_id = $this->command->argument('company');
$company_id = Company::first()->id;
$rows = [
[

View File

@ -2,6 +2,7 @@
namespace Database\Seeds;
use App\Models\Common\Company;
use App\Models\Model;
use App\Models\Expense\BillStatus;
@ -25,7 +26,7 @@ class BillStatuses extends Seeder
private function create()
{
$company_id = $this->command->argument('company');
$company_id = Company::first()->id;
$rows = [
[

View File

@ -2,6 +2,7 @@
namespace Database\Seeds;
use App\Models\Common\Company;
use App\Models\Model;
use App\Models\Setting\Category;
@ -25,7 +26,7 @@ class Categories extends Seeder
private function create()
{
$company_id = $this->command->argument('company');
$company_id = Company::first()->id;
$rows = [
[

View File

@ -2,6 +2,7 @@
namespace Database\Seeds;
use App\Models\Common\Company;
use App\Models\Model;
use App\Models\Setting\Currency;
@ -25,7 +26,7 @@ class Currencies extends Seeder
private function create()
{
$company_id = $this->command->argument('company');
$company_id = Company::first()->id;
$rows = [
[

View File

@ -11,6 +11,7 @@ class DatabaseSeeder extends Seeder
*/
public function run()
{
$this->call(\Database\Seeds\TestCompany::class);
$this->call(CompanySeeder::class);
}
}

View File

@ -2,6 +2,7 @@
namespace Database\Seeds;
use App\Models\Common\Company;
use App\Models\Model;
use App\Models\Income\InvoiceStatus;
@ -25,7 +26,7 @@ class InvoiceStatuses extends Seeder
private function create()
{
$company_id = $this->command->argument('company');
$company_id = Company::first()->id;
$rows = [
[

View File

@ -2,6 +2,7 @@
namespace Database\Seeds;
use App\Models\Common\Company;
use App\Models\Model;
use Artisan;
@ -25,7 +26,7 @@ class Modules extends Seeder
private function create()
{
$company_id = $this->command->argument('company');
$company_id = Company::first()->id;
Artisan::call('module:install', ['alias' => 'offlinepayment', 'company_id' => $company_id]);
Artisan::call('module:install', ['alias' => 'paypalstandard', 'company_id' => $company_id]);

View File

@ -10,7 +10,11 @@ use Illuminate\Database\Seeder;
class Roles extends Seeder
{
/**
public function __construct()
{
}
/**
* Run the database seeds.
*
* @return void

View File

@ -2,6 +2,7 @@
namespace Database\Seeds;
use App\Models\Common\Company;
use App\Models\Model;
use Illuminate\Database\Seeder;
use Setting;
@ -24,7 +25,7 @@ class Settings extends Seeder
private function create()
{
$company_id = $this->command->argument('company');
$company_id = Company::first()->id;
Setting::set([
'general.date_format' => 'd M Y',

View File

@ -2,6 +2,7 @@
namespace Database\Seeds;
use App\Models\Common\Company;
use App\Models\Model;
use App\Models\Setting\Tax;
@ -25,7 +26,7 @@ class Taxes extends Seeder
private function create()
{
$company_id = $this->command->argument('company');
$company_id = Company::first()->id;
$rows = [
[

32
phpunit.xml Normal file
View File

@ -0,0 +1,32 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Feature">
<directory suffix="Test.php">./tests/Feature</directory>
</testsuite>
<testsuite name="Unit">
<directory suffix="Test.php">./tests/Unit</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./app</directory>
</whitelist>
</filter>
<php>
<env name="APP_ENV" value="testing"/>
<env name="CACHE_DRIVER" value="array"/>
<env name="SESSION_DRIVER" value="array"/>
<env name="QUEUE_DRIVER" value="sync"/>
<env name="MAIL_DRIVER" value="array"/>
</php>
</phpunit>

View File

@ -2,21 +2,21 @@
namespace Tests\Feature;
use App\Models\Auth\User;
use Tests\TestCase;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
class ExampleTest extends TestCase
{
/**
/**
* A basic test example.
*
* @return void
*/
public function testBasicTest()
{
$response = $this->get('/');
$response = $this
->actingAs(User::first())
->get('/');
$response->assertStatus(200);
}

View File

@ -0,0 +1,64 @@
<?php
/**
* Created by PhpStorm.
* User: bgure
* Date: 13.07.2018
* Time: 19:44
*/
namespace Tests\Feature;
use App\Models\Auth\User;
use App\Models\Common\Company;
use Faker\Factory;
use Tests\TestCase;
abstract class FeatureTestCase extends TestCase
{
/**
* @var \Faker\Generator
*/
protected $faker;
/** @var User */
protected $user;
/** @var Company */
protected $company;
protected function setUp()
{
parent::setUp();
$this->faker = Factory::create();
$this->user = User::first();
$this->company = $this->user->first()->companies()->first();
}
/**
* Empty for default user.
*
* @param User|null $user
* @param Company|null $company
* @return FeatureTestCase
*/
public function loginAs(User $user = null, Company $company = null)
{
if(!$user) $user = $this->user;
if(!$company) $company = $user->companies()->first();
$this->startSession();
return $this->actingAs($user)
->withSession(['company_id' => $company->id]);
}
public function assertFlashLevel($excepted)
{
$flash["level"] = null;
if($flashMessage = session('flash_notification'))
{
$flash = $flashMessage->first();
}
$this->assertEquals($excepted, $flash['level']);
}
}

View File

@ -2,9 +2,17 @@
namespace Tests;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
use CreatesApplication, DatabaseMigrations;
protected function setUp()
{
parent::setUp();
$this->artisan('db:seed');
}
}

View File

@ -8,7 +8,7 @@ use Illuminate\Foundation\Testing\DatabaseTransactions;
class ExampleTest extends TestCase
{
/**
/**
* A basic test example.
*
* @return void