php - Testing Laravel facades with mockery always passes, even when it should fail -


i'm trying mock facades in laravel during unit testing, seems tests pass no matter what.

for example, example taken laravel docs here:

event::shouldreceive('fire')->once()->with('foo', array('name' => 'dayle')); 

it seems can put in of test methods , pass though nothing of sort has been done event facade.

here test class:

class sessionscontrollertest extends testcase {         public function test_invalid_login_returns_to_login_page()     {         // of these pass when should fail         notification::shouldreceive('error')->once()->with('incorrect email or password.');         event::shouldreceive('fire')->once()->with('foo', array('name' => 'dayle'));         notification::shouldreceive('nonsense')->once()->with('nonsense');          // make login attempt bad credentials         $this->post(action('sessionscontroller@postlogin'), [             'inputemail'     => 'bademail@example.com',             'inputpassword'  => 'badpassword'         ]);          // should redirect login form old input         $this->asserthasoldinput();         $this->assertredirectedtoaction('sessionscontroller@getlogin');     }  } 

what missing in order test facades? right in thinking should able call shouldreceive() on laravel facade without setup?

you need tell mockery run it's verification. can putting

\mockery::close(); 

either @ end of test method, or in test class' teardown method.

alternatively, set mockery's phpunit integration adding phpunit.xml

<listeners>   <listener class="\mockery\adapter\phpunit\testlistener"></listener> </listeners> 

see http://docs.mockery.io/en/latest/reference/phpunit_integration.html further information.


Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

thorough guide for profiling racket code -