Make test typing more specific

This commit is contained in:
Christopher C. Wells 2021-03-31 08:25:57 -07:00 committed by Christopher Charbonneau Wells
parent ace3e1710b
commit 3e697c7363
4 changed files with 13 additions and 14 deletions

View File

@ -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,

View File

@ -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();
}

View File

@ -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());

View File

@ -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();
}