0

I need to use PHPUnit mocking methods like expect($this->once())->returnSelf(); in codecept/yii2 tests. Cannot find any way to call them. The Stub library of codeception does not have as many way to mock a method.

Although phpunit is wrapped by codeception I neither can find a way to use phpunit with yii 2 for API testing using sendPost etc.

Please suggest.

1 Answer 1

1

The Codeception\Test\Unit class indirectly extends PHPUnit\Framework\TestCase. You should be able to use PHPUnit way of creating mock object and then you can set up its methods:

public function testMyTestCase()
{
    $mockedObject = $this->createMock(MockedClassOrInterface::class);
    $mockedObject->expects($this->once())
        ->method('methodName')
        ->willReturnSelf();
    // ... rest of the test case code
}
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.