We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to mock libraries in controllers tests?
I saw that the reset_instance() is called during the $this->request(...) call, so if I do
reset_instance()
$this->request(...)
public function setUp() { $this->CI->email = new Mock_Libraries_Email(); } public function testFoo() { $this->request(...) }
The mocked library is never called. I would prefer to replace mock library by some vanilla createMock instance, but this way would already help.
createMock
The text was updated successfully, but these errors were encountered:
Okay, I find out, and in fact is covered in the documentation, sorry :)
The trick is to use setCallablePreConstructor() and load_class_instance to mock after the controller instantiation. Here is a sample
setCallablePreConstructor()
load_class_instance
$this->request->setCallablePreConstructor(function () use ($cmsEmailMock) { load_class_instance('cms_email', $cmsEmailMock); }); $response = $this->request('POST', 'api/foo/',[])
Sorry, something went wrong.
No branches or pull requests
How to mock libraries in controllers tests?
I saw that the
reset_instance()
is called during the$this->request(...)
call, so if I doThe mocked library is never called. I would prefer to replace mock library by some vanilla
createMock
instance, but this way would already help.The text was updated successfully, but these errors were encountered: