Php Unit test phpunit. how does the mock class call its own method?

Source: Internet
Author: User
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.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.