snipe-it/tests/unit/BaseTest.php
Laravel Shift 934afa036f Adopt Laravel coding style
Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions.

You may customize the adopted coding style by adding your own [PHP CS Fixer][1] `.php_cs` config file to your project root. Feel free to use [Shift's Laravel ruleset][2] to help you get started.

[1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer
[2]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200
2021-06-10 20:15:52 +00:00

104 lines
3.2 KiB
PHP

<?php
use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithoutMiddleware;
class BaseTest extends \Codeception\TestCase\Test
{
use DatabaseTransactions;
protected function _before()
{
Artisan::call('migrate');
factory(App\Models\Setting::class)->create();
}
protected function signIn($user = null)
{
if (! $user) {
$user = factory(User::class)->states('superuser')->create([
'location_id' => $this->createValidLocation()->id,
]);
}
Auth::login($user);
return $user;
}
protected function createValidAssetModel($state = 'mbp-13-model', $overrides = [])
{
return factory(\App\Models\AssetModel::class)->states($state)->create(array_merge([
'category_id' => $this->createValidCategory(),
'manufacturer_id' => $this->createValidManufacturer(),
'depreciation_id' => $this->createValidDepreciation(),
], $overrides));
}
protected function createValidCategory($state = 'asset-laptop-category', $overrides = [])
{
return factory(App\Models\Category::class)->states($state)->create($overrides);
}
protected function createValidCompany($overrides = [])
{
return factory(App\Models\Company::class)->create($overrides);
}
protected function createValidDepartment($state = 'engineering', $overrides = [])
{
return factory(App\Models\Department::class)->states($state)->create(array_merge([
'location_id' => $this->createValidLocation()->id,
], $overrides));
}
protected function createValidDepreciation($state = 'computer', $overrides = [])
{
return factory(App\Models\Depreciation::class)->states($state)->create($overrides);
}
protected function createValidLocation($overrides = [])
{
return factory(App\Models\Location::class)->create($overrides);
}
protected function createValidManufacturer($state = 'apple', $overrides = [])
{
return factory(App\Models\Manufacturer::class)->states($state)->create($overrides);
}
protected function createValidSupplier($overrides = [])
{
return factory(App\Models\Supplier::class)->create($overrides);
}
protected function createValidStatuslabel($state = 'rtd', $overrides = [])
{
return factory(App\Models\Statuslabel::class)->states($state)->create($overrides);
}
protected function createValidUser($overrides = [])
{
return factory(App\Models\User::class)->create(
array_merge([
'location_id'=>$this->createValidLocation()->id,
], $overrides)
);
}
protected function createValidAsset($overrides = [])
{
$locId = $this->createValidLocation()->id;
$this->createValidAssetModel();
return factory(\App\Models\Asset::class)->states('laptop-mbp')->create(
array_merge([
'rtd_location_id' => $locId,
'location_id' => $locId,
'supplier_id' => $this->createValidSupplier()->id,
], $overrides)
);
}
}