Skip to content

Instantly share code, notes, and snippets.

@viralsolani
Last active May 9, 2017 12:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save viralsolani/5409a37f877fa5cb2809aae4ec34c361 to your computer and use it in GitHub Desktop.
Save viralsolani/5409a37f877fa5cb2809aae4ec34c361 to your computer and use it in GitHub Desktop.
Test Case Model Factory Utility Function with Signin Example
<?php
abstract class TestCase extends BaseTestCase
{
use CreatesApplication;
protected function setUp()
{
parent::setUp();
$this->disableExceptionHandling();
}
protected function signIn($user = null)
{
$user = $user ?: create('App\User');
$this->actingAs($user);
return $this;
}
}
<?php
function create($class, $attributes = [], $times = null)
{
return factory($class, $times)->create($attributes);
}
function make($class, $attributes = [], $times = null)
{
return factory($class, $times)->make($attributes);
}
@viralsolani
Copy link
Author

Then autoload functions.php like below.
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
},
"files": ["tests/utilities/functions.php"]
},

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