lumen-framework: $this->expectsJobs not working
Hi,
I’ve using this method when testing my previous Laravel projects. I have now a job-heavy Lumen app on which I would like to do the same. But for some reason I cannot get this to work. I then pulled out an fresh Lumen 5.2.6 app and did the following changes to make the most simplistic working example. I assume this should work.
routes.php
<?php
use App\Jobs\ExampleJob;
$app->get('/', function () use ($app) {
dispatch(new ExampleJob);
});
ExampleTest.php
<?php
class ExampleTest extends TestCase
{
public function testExample()
{
$this->expectsJobs('App\Jobs\ExampleJob');
$this->get('/');
}
}
Running phpunit:
vagrant@homestead:~/Code/lumen-test$ phpunit
PHPUnit 4.8.26 by Sebastian Bergmann and contributors.
E
Time: 3.54 seconds, Memory: 6.00MB
There was 1 error:
1) ExampleTest::testExample
Mockery\Exception\InvalidCountException: Method dispatch(object(Mockery\Matcher\Type)) from Mockery_0_Illuminate_Bus_Dispatcher should be called
at least 1 times but called 0 times.
/home/vagrant/Code/lumen-test/vendor/mockery/mockery/library/Mockery/CountValidator/AtLeast.php:48
/home/vagrant/Code/lumen-test/vendor/mockery/mockery/library/Mockery/Expectation.php:297
/home/vagrant/Code/lumen-test/vendor/mockery/mockery/library/Mockery/ExpectationDirector.php:120
/home/vagrant/Code/lumen-test/vendor/mockery/mockery/library/Mockery/Container.php:297
/home/vagrant/Code/lumen-test/vendor/mockery/mockery/library/Mockery/Container.php:282
/home/vagrant/Code/lumen-test/vendor/mockery/mockery/library/Mockery.php:142
/home/vagrant/Code/lumen-test/vendor/laravel/lumen-framework/src/Testing/TestCase.php:107
FAILURES!
Tests: 1, Assertions: 0, Errors: 1.
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Reactions: 2
- Comments: 20 (14 by maintainers)
I’m pretty sure I figured out what is happening.
I added a failing test here, that shows how the container overwrites bindings. This will happen with any bindings listed in the availableBindings property of the application.
A hacky workaround is to resolve the object once out of the container before trying to register your binding.
I have the same problem, am using lumen 5.5
Hi there, this is solved? I’m facing the same problem with a simple test…
@feeekkk you need to do something like this:
// Now it will work correctly $this->expectsJobs($args); On Jul 2, 2016 8:25 AM, “feeekkk” notifications@github.com wrote: