Level 4
Add this to your test class
/**
* @runTestsInSeparateProcesses
* @preserveGlobalState disabled
*/
Class:
class MyEloquentModel extends Model
{
// Returns input concatenated with output of bar for that input
public function foo($input) {
$bar = MyEloquentModel::bar($input);
return $input." ".$bar;
}
// Returns world if input received is hello
public static function bar($input) {
if ($input == "hello") {
return "world";
}
}
}
Test:
class MyEloquentModelTest extends TestCase
{
public function test_foo_method_returns_correct_value() {
// Mock class
$mock = \Mockery::mock('App\MyEloquentModel');
$mock->shouldReceive('hello')
->once()
->with()
->andReturn('world');
// Create object
$my_eloquent_model = new MyEloquentModel;
$this->assertTrue($my_eloquent_model->foo('hello') == "hello world");
}
}
As it stands, the test returns "Could not load mock App\MyEloquentModel, class already exists"
Please or to participate in this conversation.