Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Laracasts/TestDummy : setting up lots of similar factories pattern
// Grade
$grade_defaults = [
'courseid' => 'factory:App\Models\Course',
'itemname' => $faker->sentence,
'itemtype' => $faker->word,
'score' => $faker->randomFloat(2, 0, 1),
'grademax' => 100
];
$factory('App\Models\Grade',
$grade_defaults
);
$factory('App\Models\Grade', 'grade_grademax_not_100', array_merge(
$grade_defaults,
[
'grademax' => $faker->numberBetween(1,100)
])
);
$factory('App\Models\Grade', 'grade_score_10', array_merge(
$grade_defaults,
[
'score' => 10
])
);
$factory('App\Models\Grade', 'grade_score_90', array_merge(
$grade_defaults,
[
'score' => 90
])
);
@dancourse
Copy link
Author

dancourse commented Apr 2, 2015

I'm aware this could be fe-ractored down, but I don't have the time. So please go wild!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment