Fixed location unit test

Signed-off-by: snipe <snipe@snipe.net>
This commit is contained in:
snipe 2021-12-01 22:45:39 -08:00
parent d96e95abd6
commit 17bd6d71e7
4 changed files with 20 additions and 73 deletions

View file

@ -1,36 +1,12 @@
<?php
/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| Here you may define all of your model factories. Model factories give
| you a convenient way to create models for testing and seeding your
| database. Just tell the factory how a default model should look.
|
*/
namespace Database\Factories;
use App\Models\AssetModel;
use App\Models\Category;
use App\Models\Company;
use App\Models\Location;
use App\Models\Manufacturer;
use App\Models\Statuslabel;
use App\Models\Supplier;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
class LocationFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = \App\Models\Location::class;
/**
* Define the model's default state.
*
@ -39,15 +15,17 @@ class LocationFactory extends Factory
public function definition()
{
return [
'name' => $this->faker->city,
'address' => $this->faker->streetAddress,
'address2' => $this->faker->secondaryAddress,
'city' => $this->faker->city,
'state' => $this->faker->stateAbbr,
'country' => $this->faker->countryCode,
'currency' => $this->faker->currencyCode,
'zip' => $this->faker->postcode,
'name' => $this->faker->city(),
'address' => $this->faker->streetAddress(),
'address2' => $this->faker->secondaryAddress(),
'city' => $this->faker->city(),
'state' => $this->faker->stateAbbr(),
'country' => $this->faker->countryCode(),
'currency' => $this->faker->currencyCode(),
'zip' => $this->faker->postcode(),
'image' => rand(1, 9).'.jpg',
];
}
}

View file

@ -1,40 +1,10 @@
<?php
namespace Tests;
use PHPUnit\Framework\TestCase;
use Illuminate\Foundation\Testing\TestCase as BaseTestCase;
class TestCase extends TestCase
abstract class TestCase extends BaseTestCase
{
/**
* The base URL to use while testing the application.
*
* @var string
*/
protected $baseUrl = 'http://localhost:8000';
/**
* Creates the application.
*
* @return \Illuminate\Foundation\Application
*/
public function createApplication()
{
$app = require __DIR__.'/../bootstrap/app.php';
$app->make(Illuminate\Contracts\Console\Kernel::class)->bootstrap();
return $app;
}
public function setUp() : void
{
parent::setUp();
\Artisan::call('migrate:fresh');
$this->seed();
}
public function tearDown() : void
{
//Artisan::call('migrate:reset');
parent::tearDown();
}
use CreatesApplication;
}

View file

@ -5,7 +5,7 @@ use App\Models\User;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use PHPUnit\Framework\TestCase;
use Tests\TestCase;
class BaseTest extends TestCase
{

View file

@ -2,10 +2,9 @@
namespace Tests\Unit;
use App\Models\Location;
use Illuminate\Foundation\Testing\DatabaseMigrations;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Foundation\Testing\WithoutMiddleware;
use Tests\Unit\BaseTest;
use Illuminate\Database\Eloquent\Factories\Factory;
use Tests\TestCase;
class LocationTest extends BaseTest
{
@ -36,6 +35,6 @@ class LocationTest extends BaseTest
]);
$this->assertFalse($a->isValid());
$this->assertStringContainsString('The parent id and id must be different', $a->getErrors());
$this->assertStringContainsString(trans('validation.non_circular', ['attribute' => 'parent id']), $a->getErrors());
}
}