When laravel5 is used for unit testing, you need to test the querySessionIdTest method, but you need to mock out the sessionidtest method. the specific code is as follows: & quot; extract () {echo & #39; querySessionIdTest & #39; return $ this-& gt; sessionidt phpunit test phplaravel5
When laravel5 is used for unit testing, you need to test the querySessionIdTest method to solve the following problems,
However, the mock sessionidtest method is required. the specific code is as follows:
Class:
class ZabbixSystem implements ApmSystemInterface public function querySessionIdTest() { echo 'querySessionIdTest'; return $this->sessionidtest(); } public function sessionidtest() { echo 'sessionidtest'; return 'aaa'; }}
Unit test method:
Public function testQuerySessionIdSuccess () {$ return = 'aaa'; $ stub = Mockery: mock ('mcokname '); // $ this-> app-> instance ('zabbixsystem', $ stub); $ stub-> shouldReceive ('querysessionidtest')-> andReturn ($ return ); $ response = $ stub-> querySessionIdTest (); $ this-> assertEquals ('AAA', $ response);} public function testQuerySession () {// create a post for the SomeClass class. $ Stub = $ this-> getMockBuilder ('app \ Services \ zabbixsystem')-> setMethods (array ('querysessionidtest', 'sessionidtest')-> getMock (); // Configure the pile. $ Stub-> method ('sessionidtest')-> willReturn ('000000'); $ this-> app-> instance ('zabbixsystem', $ stub ); $ this-> assertEquals ('foo', $ stub-> querySessionIdTest ());}
The test fails in two ways. the expected result is:
Echo 'querysessionidtest ';
Then the test is successful.