From 0e3bafd5b4ef60f098fd32579776eb91b3148f14 Mon Sep 17 00:00:00 2001 From: snipe Date: Thu, 2 Dec 2021 19:19:42 -0800 Subject: [PATCH] Fixed depreciation tests Signed-off-by: snipe --- database/factories/DepreciationFactory.php | 2 ++ tests/Unit/DepreciationTest.php | 33 +++++++++------------- 2 files changed, 15 insertions(+), 20 deletions(-) diff --git a/database/factories/DepreciationFactory.php b/database/factories/DepreciationFactory.php index 2a1bfe4cd2..17940ac515 100644 --- a/database/factories/DepreciationFactory.php +++ b/database/factories/DepreciationFactory.php @@ -30,7 +30,9 @@ class DepreciationFactory extends Factory public function definition() { return [ + 'name' => $this->faker->catchPhrase(), 'user_id' => 1, + 'months' => 36, ]; } diff --git a/tests/Unit/DepreciationTest.php b/tests/Unit/DepreciationTest.php index 0b016bb55f..c652acaa76 100644 --- a/tests/Unit/DepreciationTest.php +++ b/tests/Unit/DepreciationTest.php @@ -6,6 +6,9 @@ use Illuminate\Foundation\Testing\DatabaseMigrations; use Illuminate\Foundation\Testing\DatabaseTransactions; use Illuminate\Foundation\Testing\WithoutMiddleware; use Tests\Unit\BaseTest; +use App\Models\Category; +use Carbon; +use App\Models\License; class DepreciationTest extends BaseTest { @@ -14,21 +17,7 @@ class DepreciationTest extends BaseTest */ protected $tester; - public function testFailsEmptyValidation() - { - // An Asset requires a name, a qty, and a category_id. - $a = Depreciation::create(); - $this->assertFalse($a->isValid()); - $fields = [ - 'name' => 'name', - 'months' => 'months', - ]; - $errors = $a->getErrors(); - foreach ($fields as $field => $fieldTitle) { - $this->assertEquals($errors->get($field)[0], "The ${fieldTitle} field is required."); - } - } public function testADepreciationHasModels() { @@ -40,12 +29,16 @@ class DepreciationTest extends BaseTest public function testADepreciationHasLicenses() { - $category = $this->createValidCategory('license-graphics-category'); - $depreciation = $this->createValidDepreciation('computer', ['name' => 'New Depreciation']); - $licenses = \App\Models\License::factory()->count(5)->photoshop()->create([ - 'depreciation_id'=>$depreciation->id, - 'category_id' => $category->id, - ]); + + $depreciation = Depreciation::factory()->create(); + License::factory() + ->count(5) + ->photoshop() + ->create( + [ + 'category_id' => Category::factory()->licenseGraphicsCategory(), + 'depreciation_id' => $depreciation->id + ]); $this->assertEquals(5, $depreciation->licenses()->count()); }