3
votes

I'm following through Jeffrey Way's Laravel Testing Decoded and I've hit an issue I can't seem to fix.

I'm actually work through this tutorial: http://net.tutsplus.com/tutorials/php/testing-laravel-controllers/ Which is an excerpt from his book.

Basically I have a test like so:

class PostsTest extends TestCase {


    public function __construct() 
    {
        $this->mock = Mockery::mock('Eloquent', 'Post');        
    }

And that like for mocking Eloquent and Post returns:

PHP Fatal error:  Class 'Eloquent' not found

When I run phpunit. Incidentally if I use Jeffrey's Laravel Generators and just generate some scaffold e.g.

php artisan generate:scaffold post --fields="title:string, body:string"

And run phpunit I get same error. He's using the same:

$this->mock = Mockery::mock('Eloquent', 'Post');

To mock the classes. Does anyone have any suggestions on what the issue could be?


I've been working through the tutorial again from scratch and am still getting the same error. I've pushed it to a public repo so people can see: https://github.com/RyanHavoc/tdd-laravel

Just pull it down, run composer install/update and phpunit.

1

1 Answers

6
votes

I found a solution to the issue.

//Causes the Class 'Eloquent' not found error
public function __construct()
{
    $this->mock = Mockery::mock('Eloquent', 'Post');
}

//Setting the mocks in the setUp() method instead works
public function setUp() 
{
    parent::setUp();
    $this->mock = Mockery::mock('Eloquent', 'Post');
}