Skip to content

Instantly share code, notes, and snippets.

@thmsbkkr
Last active February 21, 2018 03:35
Show Gist options
  • Save thmsbkkr/d1e85bf07810fd8b29d4f2a45f58c0d9 to your computer and use it in GitHub Desktop.
Save thmsbkkr/d1e85bf07810fd8b29d4f2a45f58c0d9 to your computer and use it in GitHub Desktop.
A helper trait for working with factories in tests
<?php
namespace Tests;
trait FactoryHelpers
{
public function create($class, $attributes = [], $times = null)
{
return factory($class, $times)->create($attributes);
}
public function make($class, $attributes = [], $times = null)
{
return factory($class, $times)->make($attributes);
}
public function createState($class, $state, $attributes = [], $times = null)
{
return factory($class, $times)->states($state)->create($attributes);
}
public function makeState($class, $state, $attributes = [], $times = null)
{
return factory($class, $times)->states($state)->make($attributes);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment