From 3e697c73637e1fc4896a2e8ac3c968d4c23da358 Mon Sep 17 00:00:00 2001 From: "Christopher C. Wells" Date: Wed, 31 Mar 2021 08:25:57 -0700 Subject: [PATCH] Make test typing more specific --- tests/Feature/Http/Controllers/FoodControllerTest.php | 6 +++--- tests/Feature/Http/Controllers/GoalControllerTest.php | 7 +++---- .../Http/Controllers/JournalEntryControllerTest.php | 10 +++++----- .../Feature/Http/Controllers/RecipeControllerTest.php | 4 ++-- 4 files changed, 13 insertions(+), 14 deletions(-) diff --git a/tests/Feature/Http/Controllers/FoodControllerTest.php b/tests/Feature/Http/Controllers/FoodControllerTest.php index 542a84d..bf78818 100644 --- a/tests/Feature/Http/Controllers/FoodControllerTest.php +++ b/tests/Feature/Http/Controllers/FoodControllerTest.php @@ -4,7 +4,7 @@ namespace Tests\Feature\Http\Controllers; use App\Http\Controllers\FoodController; use App\Models\Food; -use Illuminate\Database\Eloquent\Factories\Factory; +use Database\Factories\FoodFactory; use Illuminate\Foundation\Testing\RefreshDatabase; class FoodControllerTest extends HttpControllerTestCase @@ -22,7 +22,7 @@ class FoodControllerTest extends HttpControllerTestCase /** * @inheritdoc */ - public function factory(): Factory + public function factory(): FoodFactory { return Food::factory(); } @@ -38,7 +38,7 @@ class FoodControllerTest extends HttpControllerTestCase public function testCanAddFoodWithoutNutrients(): void { /** @var \App\Models\Food $food */ - $food = Food::factory()->make([ + $food = $this->factory()->make([ 'calories' => NULL, 'fat' => NULL, 'cholesterol' => NULL, diff --git a/tests/Feature/Http/Controllers/GoalControllerTest.php b/tests/Feature/Http/Controllers/GoalControllerTest.php index f8fbede..c63c73a 100644 --- a/tests/Feature/Http/Controllers/GoalControllerTest.php +++ b/tests/Feature/Http/Controllers/GoalControllerTest.php @@ -4,8 +4,7 @@ namespace Tests\Feature\Http\Controllers; use App\Http\Controllers\GoalController; use App\Models\Goal; -use Illuminate\Database\Eloquent\Factories\Factory; -use Illuminate\Database\Eloquent\Model; +use Database\Factories\GoalFactory; use Illuminate\Foundation\Testing\RefreshDatabase; class GoalControllerTest extends HttpControllerTestCase @@ -23,7 +22,7 @@ class GoalControllerTest extends HttpControllerTestCase /** * @inheritdoc */ - public function factory(): Factory + public function factory(): GoalFactory { return Goal::factory(); } @@ -39,7 +38,7 @@ class GoalControllerTest extends HttpControllerTestCase /** * @inheritdoc */ - protected function createInstance(): Model + protected function createInstance(): Goal { return $this->factory()->for($this->user)->create(); } diff --git a/tests/Feature/Http/Controllers/JournalEntryControllerTest.php b/tests/Feature/Http/Controllers/JournalEntryControllerTest.php index e884ef7..6a1c967 100644 --- a/tests/Feature/Http/Controllers/JournalEntryControllerTest.php +++ b/tests/Feature/Http/Controllers/JournalEntryControllerTest.php @@ -5,8 +5,7 @@ namespace Tests\Feature\Http\Controllers; use App\Http\Controllers\JournalEntryController; use App\Models\IngredientAmount; use App\Models\JournalEntry; -use Illuminate\Database\Eloquent\Factories\Factory; -use Illuminate\Database\Eloquent\Model; +use Database\Factories\JournalEntryFactory; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; @@ -25,7 +24,7 @@ class JournalEntryControllerTest extends HttpControllerTestCase /** * @inheritdoc */ - public function factory(): Factory + public function factory(): JournalEntryFactory { return JournalEntry::factory(); } @@ -41,7 +40,7 @@ class JournalEntryControllerTest extends HttpControllerTestCase /** * @inheritdoc */ - protected function createInstance(): Model + protected function createInstance(): JournalEntry { return $this->factory()->for($this->user)->create(); } @@ -87,10 +86,11 @@ class JournalEntryControllerTest extends HttpControllerTestCase 'date' => [], 'meal' => [], 'amount' => [], 'unit' => [], 'id' => [], 'type' => [], ]; - /** @var \App\Models\IngredientAmount[] $ingredient_amounts */ + $ingredient_amounts = IngredientAmount::factory() ->count(10) ->make(['parent_id' => null, 'parent_type' => null]); + /** @var \App\Models\IngredientAmount $ingredient_amount */ foreach ($ingredient_amounts as $ingredient_amount) { $ingredients['date'][] = $this->faker->dateTimeThisMonth; $ingredients['meal'][] = $this->faker->randomElement(JournalEntry::meals()->pluck('value')->toArray()); diff --git a/tests/Feature/Http/Controllers/RecipeControllerTest.php b/tests/Feature/Http/Controllers/RecipeControllerTest.php index 52a4d84..08ca4d4 100644 --- a/tests/Feature/Http/Controllers/RecipeControllerTest.php +++ b/tests/Feature/Http/Controllers/RecipeControllerTest.php @@ -7,8 +7,8 @@ use App\Models\IngredientAmount; use App\Models\Recipe; use App\Models\RecipeSeparator; use App\Models\RecipeStep; +use Database\Factories\RecipeFactory; use Illuminate\Database\Eloquent\Collection; -use Illuminate\Database\Eloquent\Factories\Factory; use Illuminate\Foundation\Testing\RefreshDatabase; use Illuminate\Foundation\Testing\WithFaker; @@ -27,7 +27,7 @@ class RecipeControllerTest extends HttpControllerTestCase /** * @inheritdoc */ - public function factory(): Factory + public function factory(): RecipeFactory { return Recipe::factory(); }