title: Laravel mock with Mockery Eloquent models
body: <p>I'm developing a <strong>PHP (5.4.25)</strong> application with <strong>laravel(4.2)</strong> framework. I'd like test my UserController with <strong>Mockery</strong>, so I've fit my UserController in this way:</p>
  
  <pre><code>class UsersController extends \BaseController {
      protected $user;
  
      public function __construct(User $user) {
          $this-&gt;user = $user;
          $this-&gt;beforeFilter('csrf', array('on'=&gt;'post'));
      }
  
      public function store() {
          $validator = Validator::make(Input::all(), User::$rules);
  
          if ( $validator-&gt;passes() ) {
              $this-&gt;user-&gt;username = Input::get('username');
              $this-&gt;user-&gt;password = Hash::make(Input::get('password'));
              $this-&gt;user-&gt;first_name = Input::get('first_name');
              $this-&gt;user-&gt;last_name = Input::get('last_name');
              $this-&gt;user-&gt;email = Input::get('email');
              $this-&gt;user-&gt;save();
  
  
              return true;
          } else {
              return false;
          }
      }
  </code></pre>
  
  <p>I want mock Eloquent User model so i develop my UsersControllerTest so:</p>
  
  <pre><code>class UsersControllerTest extends TestCase {
  
      private $mock;
  
      public function __construct() {}
  
      public function setUp() {
          parent::setUp();
  
          $this-&gt;createApplication();                                                     
      }
  
      public function tearDown() {
          parent::tearDown();
  
          Mockery::close();
      }
  
      public function testStore() {
          $this-&gt;mock = Mockery::mock('Eloquent','User[save]');                                           
          $this-&gt;mock
              -&gt;shouldReceive('save')
              -&gt;once()
              -&gt;andReturn('true');                                                        
          $this-&gt;app-&gt;instance('User', $this-&gt;mock);                                      
  
          $data['username'] = 'qwerety';
          $data['first_name'] = 'asd';
          $data['last_name'] = 'asd123';
          $data['email'] = 'test@gmail.com';
          $data['password'] = 'password';
          $data['password_confirmation'] = 'password';
  
          $response = $this-&gt;call('POST', 'users', $data);
  
          var_dump($response-&gt;getContent());
      }
  
  } 
  </code></pre>
  
  <p>When I run my test it returns me this error:</p>
  
  <pre><code>Mockery\Exception\InvalidCountException : Method save() from Mockery_0_User should be called
   exactly 1 times but called 0 times.
  </code></pre>
  
  <p>Why? What's wrong?</p>
  
  <p><strong>EDIT:</strong> I found the problem - If I don't use mock object all works fine and the controller create a new user in the DB, but when I use mock the <code>Input:all()</code> method returns empty array.</p>
  
  <p>--
  Thanks</p>