-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
27 changed files
with
369 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
<?php | ||
|
||
namespace ExampleApp\Models; | ||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Ingredient extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = ['name', 'description']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,13 @@ | ||
<?php | ||
|
||
namespace ExampleApp\Models\ModelsWithArrayState; | ||
namespace App\Models\ModelsWithArrayState; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
|
||
class Book extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = ['name']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,38 @@ | ||
<?php | ||
|
||
/** @var \Illuminate\Database\Eloquent\Factory $factory */ | ||
namespace Database\Factories; | ||
|
||
use Faker\Generator as Faker; | ||
use App\Models\ModelsWithArrayState\Book; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
$factory->define(\ExampleApp\Models\ModelsWithArrayState\Book::class, function (Faker $faker) { | ||
return [ | ||
'name' => $faker->word, | ||
]; | ||
}); | ||
class BookFactory extends Factory | ||
{ | ||
/** | ||
* The name of the factory's corresponding model. | ||
* | ||
* @var string | ||
*/ | ||
protected $model = Book::class; | ||
|
||
$factory->state( | ||
\ExampleApp\Models\ModelsWithArrayState\Book::class, | ||
'customName', | ||
[ | ||
'name' => 'custom-name', | ||
] | ||
); | ||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() | ||
{ | ||
return ['name' => $this->faker->word]; | ||
} | ||
|
||
/** | ||
* Indicate that the user is suspended. | ||
* | ||
* @return Factory | ||
*/ | ||
public function customName(): Factory | ||
{ | ||
return $this->state([ | ||
'name' => 'custom-name', | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,29 @@ | ||
<?php | ||
|
||
/** @var \Illuminate\Database\Eloquent\Factory $factory */ | ||
namespace Database\Factories; | ||
|
||
use ExampleApp\Models\Group; | ||
use Faker\Generator as Faker; | ||
use App\Models\Group; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
$factory->define(Group::class, function (Faker $faker) { | ||
return [ | ||
'name' => $faker->word, | ||
'size' => $faker->numberBetween(1, 10), | ||
]; | ||
}); | ||
class GroupFactory extends Factory | ||
{ | ||
/** | ||
* The name of the factory's corresponding model. | ||
* | ||
* @var string | ||
*/ | ||
protected $model = Group::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() | ||
{ | ||
return [ | ||
'name' => $this->faker->word, | ||
'size' => $this->faker->numberBetween(1, 10), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,71 @@ | ||
<?php | ||
|
||
/** @var \Illuminate\Database\Eloquent\Factory $factory */ | ||
|
||
use ExampleApp\Models\Group; | ||
use ExampleApp\Models\Recipe; | ||
use Faker\Generator as Faker; | ||
|
||
$factory->define(Recipe::class, function (Faker $faker) { | ||
return [ | ||
'name' => $faker->word, | ||
'description' => $faker->sentence, | ||
]; | ||
}); | ||
|
||
$factory->state(Recipe::class, 'withGroup', function () { | ||
return [ | ||
'group_id' => factory(Group::class), | ||
]; | ||
}); | ||
|
||
$factory->state(Recipe::class, 'withDifferentGroup', function () { | ||
$group = factory(Group::class)->create(); | ||
|
||
return [ | ||
'group_id' => $group->id, | ||
]; | ||
}); | ||
|
||
$factory->state(Recipe::class, 'withOneLineGroup', function () { | ||
return ['group_id' => factory(Group::class)]; | ||
}); | ||
|
||
$factory->state(Recipe::class, 'withReturnGroupName', function () { | ||
return ['group_name' => 'return all']; | ||
}); | ||
|
||
$factory->state(Recipe::class, 'withSquareBracketGroupName', function () { | ||
return ['group_name' => 'something];']; | ||
}); | ||
namespace Database\Factories; | ||
|
||
use App\Models\Group; | ||
use App\Models\Recipe; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
|
||
class RecipeFactory extends Factory | ||
{ | ||
/** | ||
* The name of the factory's corresponding model. | ||
* | ||
* @var string | ||
*/ | ||
protected $model = Recipe::class; | ||
|
||
/** | ||
* Define the model's default state. | ||
* | ||
* @return array | ||
*/ | ||
public function definition() | ||
{ | ||
return [ | ||
'name' => $this->faker->word, | ||
'description' => $this->faker->sentence, | ||
]; | ||
} | ||
|
||
public function withGroup(): Factory | ||
{ | ||
return $this->state([ | ||
'group_id' => Group::factory(), | ||
]); | ||
} | ||
|
||
public function withDifferentGroup(): Factory | ||
{ | ||
$group = GroupFactory::new() | ||
->create(); | ||
|
||
return $this->state([ | ||
'group_id' => $group->id, | ||
]); | ||
} | ||
|
||
public function withOneLineGroup(): Factory | ||
{ | ||
return $this->state(['group_id' => Group::factory()]); | ||
} | ||
|
||
public function withReturnGroupName(): Factory | ||
{ | ||
return $this->state(['group_name' => 'return all']); | ||
} | ||
|
||
public function withClosureGroupName(): Factory | ||
{ | ||
return $this->state(function (array $attributes) { | ||
return [ | ||
'name' => $attributes['name'] . ' New Name', | ||
]; | ||
}); | ||
} | ||
|
||
public function withSquareBracketGroupName(): Factory | ||
{ | ||
return $this->state(['group_name' => 'something];']); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.