Can't use Laravel's built in DB Mock in a Codeception run
timbroder opened this issue · 5 comments
What are you trying to achieve?
Use Laravel's built in DB
Mock in a Codeception run
Note: This works in 2.2.9 but breaks in 2.2.10
What do you get instead?
./vendor/bin/codecept run -f -d unit Traits/
Codeception PHP Testing Framework v2.2.10
Powered by PHPUnit 4.8.27 by Sebastian Bergmann and contributors.
Rebuilding UnitTester...
Unit Tests (7) ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Modules: Laravel5, Asserts, \Helper\Unit, Mockery, Db
-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
✔ DatabaseToolsUnitTest: Date_modify_works_for_postgres (0.06s)
[BadMethodCallException]
Method Mockery_0_Illuminate_Database_DatabaseManager::getConnections() does not exist on this mock object
Exception trace:
() at /Users/timbroder/workspace/kidfund/web/vendor/mockery/mockery/library/Mockery/Loader/EvalLoader.php(16) : eval()'d code:709
Mockery_0_Illuminate_Database_DatabaseManager->_mockery_handleMethodCall() at /Users/timbroder/workspace/kidfund/web/vendor/mockery/mockery/library/Mockery/Loader/EvalLoader.php(16) : eval()'d code:857
Mockery_0_Illuminate_Database_DatabaseManager->getConnections() at /Users/timbroder/workspace/kidfund/web/vendor/codeception/codeception/src/Codeception/Module/Laravel5.php:203
Codeception\Module\Laravel5->_after() at /Users/timbroder/workspace/kidfund/web/vendor/codeception/codeception/src/Codeception/Subscriber/Module.php:68
Codeception\Subscriber\Module->after() at n/a:n/a
call_user_func() at /Users/timbroder/workspace/kidfund/web/vendor/symfony/event-dispatcher/EventDispatcher.php:174
Symfony\Component\EventDispatcher\EventDispatcher->doDispatch() at /Users/timbroder/workspace/kidfund/web/vendor/symfony/event-dispatcher/EventDispatcher.php:43
Symfony\Component\EventDispatcher\EventDispatcher->dispatch() at /Users/timbroder/workspace/kidfund/web/vendor/codeception/codeception/src/Codeception/PHPUnit/Listener.php:126
Codeception\PHPUnit\Listener->fire() at /Users/timbroder/workspace/kidfund/web/vendor/codeception/codeception/src/Codeception/PHPUnit/Listener.php:112
Codeception\PHPUnit\Listener->endTest() at /Users/timbroder/workspace/kidfund/web/vendor/phpunit/phpunit/src/Framework/TestResult.php:340
PHPUnit_Framework_TestResult->endTest() at /Users/timbroder/workspace/kidfund/web/vendor/phpunit/phpunit/src/Framework/TestResult.php:733
PHPUnit_Framework_TestResult->run() at /Users/timbroder/workspace/kidfund/web/vendor/phpunit/phpunit/src/Framework/TestCase.php:724
PHPUnit_Framework_TestCase->run() at /Users/timbroder/workspace/kidfund/web/vendor/phpunit/phpunit/src/Framework/TestSuite.php:747
PHPUnit_Framework_TestSuite->run() at /Users/timbroder/workspace/kidfund/web/vendor/codeception/codeception/src/Codeception/PHPUnit/Runner.php:106
Codeception\PHPUnit\Runner->doEnhancedRun() at /Users/timbroder/workspace/kidfund/web/vendor/codeception/codeception/src/Codeception/SuiteManager.php:157
Codeception\SuiteManager->run() at /Users/timbroder/workspace/kidfund/web/vendor/codeception/codeception/src/Codeception/Codecept.php:184
Codeception\Codecept->runSuite() at /Users/timbroder/workspace/kidfund/web/vendor/codeception/codeception/src/Codeception/Codecept.php:153
Codeception\Codecept->run() at /Users/timbroder/workspace/kidfund/web/vendor/codeception/codeception/src/Codeception/Command/Run.php:288
Codeception\Command\Run->execute() at /Users/timbroder/workspace/kidfund/web/vendor/symfony/console/Command/Command.php:259
Symfony\Component\Console\Command\Command->run() at /Users/timbroder/workspace/kidfund/web/vendor/symfony/console/Application.php:847
Symfony\Component\Console\Application->doRunCommand() at /Users/timbroder/workspace/kidfund/web/vendor/symfony/console/Application.php:192
Symfony\Component\Console\Application->doRun() at /Users/timbroder/workspace/kidfund/web/vendor/symfony/console/Application.php:123
Symfony\Component\Console\Application->run() at /Users/timbroder/workspace/kidfund/web/vendor/codeception/codeception/src/Codeception/Application.php:103
Codeception\Application->run() at /Users/timbroder/workspace/kidfund/web/vendor/codeception/codeception/codecept:36
Provide test source code if related
/**
* @test
*/
public function date_modify_works_for_postgres()
{
DB::shouldReceive('getDriverName')
->once()
->andReturn('pgsql');
$return = $this->dateModify('field_name', '10', '-', 'month');
$this->assertEquals("field_name - INTERVAL '10' month", $return);
}
Details
- Codeception version: 2.2.10
- PHP Version: 2.3.5
- Operating System: OSX 10.12.6
- Installation type: Composer
- List of installed packages gist
- Suite configuration: Using Codeceptions tests
Caused by Codeception/Codeception#4032
@rmblstrp @janhenkgerritsen any comments?
I should also mention I'm running Laravel 5.2.45
@Naktibalda I actually resigned as maintainer of the Laravel module a month ago
@janhenkgerritsen sorry, I missed that.
@timbroder it is up to you to fix this issue then.
I think that it could be fixed either by wrapping foreach ($db->getConnections() as $connection) {
with if (method_exists($db, 'getConnections')
or by adding a check that $db
isn't a mock to if ($db instanceof \Illuminate\Database\DatabaseManager) {
@Naktibalda I can take this one but it may be a few weeks. Once this release goes out I'll investigate a test and PR. You can assign this to me
Thanks