I read the whole thing just to find out there is not answer -_-' Did you manage to solve this problem?
IoC Container, mocks and Codeception integration testing
Has anyone had luck binding a mock to the Laravel 4.2 IoC container during Codeception 2 integration testing? My mocked binding isn't resolving in integration tests -- App::make() is just returning the original unmocked object. Using the IoC container to pass mocks works for Codeception unit testing. I'm stumped.
Use case: we need to make sure the database is correctly updated (charge is saved as paid, failed, whatever) when certain events are triggered. We wrote some wrapper classes to encapsulate some remote APIs (payment gateways, etc) and just need to mock those wrappers so we don't have to call a bunch of vendors for each test.
I've boiled everything down to the following simple test (it should throw an exception because getMockedOutput() is only defined on the mocked object).
class CodeceptTestCest
{
public function tryToTest(FunctionalTester $I)
{
$mock = \Mockery::mock('Path\To\Class');
$mock->shouldReceive('getMockedOutput')->andReturn('works');
\App::instance('Path\To\Class', $mock);
$I->amOnPage('/functionaltest');
$I->fillField('test', 'test text');
$I->click('Submit Test');
$I->see('works');
}
}
Here's some routes for the test:
Route::get('/functionaltest', function() {
return View::make('functional_test');
});
Route::post('/functionaltest', function() {
$object = \App::make('Path\To\Class');
return $object->getMockedOutput();
});
And here's the view:
<!DOCTYPE html>
<html>
<body>
{{ Form::open(['url' => '/functionaltest', 'method' => 'post']) }}
{{ Form::text('test'}}
{{ Form::submit('Submit Test') }}
{{ Form::close() }}
</body>
</html>
Thank you!
Please or to participate in this conversation.