Last active
May 9, 2017 12:24
-
-
Save viralsolani/5409a37f877fa5cb2809aae4ec34c361 to your computer and use it in GitHub Desktop.
Test Case Model Factory Utility Function with Signin Example
This file contains hidden or 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
<?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; | |
} | |
} |
This file contains hidden or 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
<?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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Then autoload functions.php like below.
"autoload-dev": {
"psr-4": {
"Tests\": "tests/"
},
"files": ["tests/utilities/functions.php"]
},