0

I'm calling the endpoint that routes to methodIWantToTest like so:

$response = $this->json('GET', 'my/endpoint/');

I'm attaching the code below, any ideas how I can mock the call to the second method? Thanks.

class MyController extends Controller
{
    public function methodIWantToTest():
    {
        //some code to test  
        $this->methodIWantToMock()
        //some more code to test
    }
    public function methodIWantToMock():
    {
        //mock this response
    }
}

1 Answer 1

1

I don't know if I understand your question correctly but you're already doing it. I don't know also why you're using ':' after the '()' in function and you need semicolon after you call the method you want to call

class MyController extends Controller
{
    public function methodIWantToTest()
    {
        //some code to test  
        $this->methodIWantToMock();
        //some more code to test
    }
    public function methodIWantToMock()
    {
        //mock this response
    }
}

you can also pass value if you want just do this

class MyController extends Controller
{
    public function methodIWantToTest()
    {
        //some code to test  
        $this->methodIWantToMock($value);
        //some more code to test
    }
    public function methodIWantToMock($value)
    {
        //mock this response
    }
}
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.