2017-07-11 20:37:02 -07:00
|
|
|
<?php
|
2021-11-30 20:09:29 -08:00
|
|
|
namespace Tests\Unit;
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-08-31 11:14:21 -07:00
|
|
|
use App\Models\User;
|
2017-07-11 20:37:02 -07:00
|
|
|
use Illuminate\Foundation\Testing\DatabaseMigrations;
|
|
|
|
use Illuminate\Foundation\Testing\DatabaseTransactions;
|
|
|
|
use Illuminate\Foundation\Testing\WithoutMiddleware;
|
2021-12-01 22:45:39 -08:00
|
|
|
use Tests\TestCase;
|
2021-12-01 23:33:20 -08:00
|
|
|
use Auth;
|
2017-07-11 20:37:02 -07:00
|
|
|
|
2021-11-30 20:47:02 -08:00
|
|
|
class BaseTest extends TestCase
|
2017-07-11 20:37:02 -07:00
|
|
|
{
|
|
|
|
use DatabaseTransactions;
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2017-07-11 20:37:02 -07:00
|
|
|
protected function _before()
|
|
|
|
{
|
|
|
|
Artisan::call('migrate');
|
2021-06-10 13:17:44 -07:00
|
|
|
\App\Models\Setting::factory()->create();
|
2017-07-11 20:37:02 -07:00
|
|
|
}
|
2017-08-31 11:14:21 -07:00
|
|
|
|
|
|
|
protected function signIn($user = null)
|
|
|
|
{
|
2021-06-10 13:15:52 -07:00
|
|
|
if (! $user) {
|
2021-06-10 13:17:44 -07:00
|
|
|
$user = User::factory()->superuser()->create([
|
2021-06-10 13:15:52 -07:00
|
|
|
'location_id' => $this->createValidLocation()->id,
|
2020-04-27 18:02:14 -07:00
|
|
|
]);
|
2017-08-31 11:14:21 -07:00
|
|
|
}
|
|
|
|
Auth::login($user);
|
|
|
|
return $user;
|
|
|
|
}
|
2018-07-23 06:48:21 -07:00
|
|
|
|
2021-12-02 13:40:16 -08:00
|
|
|
protected function createValidAssetModel()
|
2018-07-23 06:48:21 -07:00
|
|
|
{
|
2021-12-02 13:40:16 -08:00
|
|
|
return \App\Models\AssetModel::factory()->create([
|
2018-07-23 06:48:21 -07:00
|
|
|
'category_id' => $this->createValidCategory(),
|
|
|
|
'manufacturer_id' => $this->createValidManufacturer(),
|
|
|
|
'depreciation_id' => $this->createValidDepreciation(),
|
2021-12-02 13:40:16 -08:00
|
|
|
]);
|
2018-07-23 06:48:21 -07:00
|
|
|
}
|
|
|
|
|
2021-12-02 13:40:16 -08:00
|
|
|
protected function createValidCategory()
|
2018-07-23 06:48:21 -07:00
|
|
|
{
|
2021-12-02 13:40:16 -08:00
|
|
|
return \App\Models\Category::factory()->make();
|
2018-07-23 06:48:21 -07:00
|
|
|
}
|
|
|
|
|
2021-12-02 13:40:16 -08:00
|
|
|
protected function createValidCompany()
|
2018-07-23 06:48:21 -07:00
|
|
|
{
|
2021-12-02 13:40:16 -08:00
|
|
|
return \App\Models\Company::factory()->create();
|
2018-07-23 06:48:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function createValidDepartment($state = 'engineering', $overrides = [])
|
|
|
|
{
|
2021-12-02 13:40:16 -08:00
|
|
|
return \App\Models\Department::factory()->create(array_merge([
|
2021-06-10 13:15:52 -07:00
|
|
|
'location_id' => $this->createValidLocation()->id,
|
2018-07-23 06:48:21 -07:00
|
|
|
], $overrides));
|
|
|
|
}
|
|
|
|
|
2021-12-02 13:40:16 -08:00
|
|
|
protected function createValidDepreciation()
|
2018-07-23 06:48:21 -07:00
|
|
|
{
|
2021-12-02 13:40:16 -08:00
|
|
|
return \App\Models\Depreciation::factory()->create();
|
2018-07-23 06:48:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function createValidLocation($overrides = [])
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
return \App\Models\Location::factory()->create($overrides);
|
2018-07-23 06:48:21 -07:00
|
|
|
}
|
|
|
|
|
2021-12-02 13:40:16 -08:00
|
|
|
protected function createValidManufacturer()
|
2018-07-23 06:48:21 -07:00
|
|
|
{
|
2021-12-02 13:40:16 -08:00
|
|
|
return \App\Models\Manufacturer::factory()->create();
|
2018-07-23 06:48:21 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
protected function createValidSupplier($overrides = [])
|
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
return \App\Models\Supplier::factory()->create($overrides);
|
2018-07-23 06:48:21 -07:00
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
protected function createValidStatuslabel($state = 'rtd', $overrides = [])
|
2018-07-23 06:48:21 -07:00
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
return \App\Models\Statuslabel::factory()->state()->create($overrides);
|
2018-07-23 06:48:21 -07:00
|
|
|
}
|
|
|
|
|
2021-06-10 13:15:52 -07:00
|
|
|
protected function createValidUser($overrides = [])
|
2018-07-23 06:48:21 -07:00
|
|
|
{
|
2021-06-10 13:17:44 -07:00
|
|
|
return \App\Models\User::factory()->create(
|
2021-06-10 13:15:52 -07:00
|
|
|
array_merge([
|
|
|
|
'location_id'=>$this->createValidLocation()->id,
|
2020-04-27 18:02:14 -07:00
|
|
|
], $overrides)
|
|
|
|
);
|
2018-07-23 06:48:21 -07:00
|
|
|
}
|
|
|
|
|
2020-04-28 08:37:13 -07:00
|
|
|
protected function createValidAsset($overrides = [])
|
2018-07-23 06:48:21 -07:00
|
|
|
{
|
2020-04-27 18:02:14 -07:00
|
|
|
$locId = $this->createValidLocation()->id;
|
2018-07-23 06:48:21 -07:00
|
|
|
$this->createValidAssetModel();
|
2021-06-10 13:15:52 -07:00
|
|
|
|
2021-06-10 13:17:44 -07:00
|
|
|
return \App\Models\Asset::factory()->laptopMbp()->create(
|
2020-04-27 18:02:14 -07:00
|
|
|
array_merge([
|
|
|
|
'rtd_location_id' => $locId,
|
|
|
|
'location_id' => $locId,
|
2021-06-10 13:15:52 -07:00
|
|
|
'supplier_id' => $this->createValidSupplier()->id,
|
2020-04-27 18:02:14 -07:00
|
|
|
], $overrides)
|
|
|
|
);
|
2018-07-23 06:48:21 -07:00
|
|
|
}
|
2017-07-11 20:37:02 -07:00
|
|
|
}
|