akaunting/tests/Feature/FeatureTestCase.php

78 lines
1.7 KiB
PHP
Raw Normal View History

2018-07-14 13:22:33 +03:00
<?php
namespace Tests\Feature;
use App\Models\Auth\User;
use App\Models\Common\Company;
2020-11-13 17:10:51 +03:00
use App\Utilities\Overrider;
2018-07-14 13:22:33 +03:00
use Faker\Factory;
use Tests\TestCase;
abstract class FeatureTestCase extends TestCase
{
2020-01-13 11:50:38 +03:00
protected $faker;
2018-07-14 13:22:33 +03:00
2020-01-13 11:50:38 +03:00
protected $user;
2018-07-14 13:22:33 +03:00
2020-01-13 11:50:38 +03:00
protected $company;
2018-07-14 13:22:33 +03:00
2020-01-13 11:50:38 +03:00
protected function setUp(): void
{
parent::setUp();
2018-09-29 17:28:34 +03:00
2020-01-13 11:50:38 +03:00
$this->withoutExceptionHandling();
2019-12-22 18:57:04 +03:00
2020-01-13 11:50:38 +03:00
$this->faker = Factory::create();
$this->user = User::first();
$this->company = $this->user->companies()->first();
2019-04-02 18:51:06 +03:00
2020-01-13 11:50:38 +03:00
session(['company_id' => $this->company->id]);
2020-01-07 09:29:45 +03:00
2020-01-13 11:50:38 +03:00
// Set Company settings
2019-04-02 18:51:06 +03:00
setting()->setExtraColumns(['company_id' => $this->company->id]);
2020-01-06 16:37:32 +03:00
setting()->forgetAll();
2020-01-13 11:50:38 +03:00
setting()->load(true);
setting()->set(['email.protocol' => 'array']);
setting()->save();
2020-01-13 11:50:38 +03:00
// Disable debugbar
config(['debugbar.enabled', false]);
2020-11-13 17:10:51 +03:00
Overrider::load('currencies');
2020-01-13 11:50:38 +03:00
}
/**
* 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 = $this->company;
}
$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']);
}
}