EcomDev_PHPUnit
EcomDev_PHPUnit copied to clipboard
Multiple dispatches in one test run: Events not properly isloated
I have a module that registers a frontend event "controller_action_predispatch_wishlist_index_send"
Steps to reproduce:
- $this->dispatch('/);
- $this->dispatch('wishlist/index/send');
- Event controller_action_predispatch_wishlist_index_send is not fired
If I directly dispatch the "right" action, i.e. the action that fires the event, it will be fired:
Steps to reproduce:
- $this->dispatch('wishlist/index/send');
- Event controller_action_predispatch_wishlist_index_send is fired
I debugged this a little and there seems to be some kind of caching problem. After the first dispatch, the event cache is already initialized. Now during the second call, events that have not fired before, are just ignored.
Correction:
- the two dispatches must be in seperate tests
- there must be fixture loading involved, but the fixture can be empty
- $this->assertEventDispatched('controller_action_predispatch_wishlist_index_send'); actually is not failing, but inside the dispatching the event is not really dispatched
I made a small test module to reproduce this: https://github.com/amenk/N98_EcomDevPHPUnitIssue
Running both tests
phpunit.phar --debug --filter N98_EcomDevPHPUnitIssue_Test_Controller_TestController PHPUnit 3.7.13 by Sebastian Bergmann.
Configuration read from tests/integration/phpunit.xml
Starting test 'N98_EcomDevPHPUnitIssue_Test_Controller_TestController::aAction'. . Starting test 'N98_EcomDevPHPUnitIssue_Test_Controller_TestController::bAction'. F
Time: 5 seconds, Memory: 55.50Mb
There was 1 failure:
- N98_EcomDevPHPUnitIssue_Test_Controller_TestController::bAction event was not really fired Failed asserting that null is true.
app/code/local/N98/EcomDevPHPUnitIssue/Test/Controller/TestController.php:30 phpunit.phar:524
FAILURES! Tests: 2, Assertions: 4, Failures: 1.
Running only bAction
phpunit.phar --debug --filter N98_EcomDevPHPUnitIssue_Test_Controller_TestController::bAction PHPUnit 3.7.13 by Sebastian Bergmann.
Configuration read from tests/integration/phpunit.xml
Starting test 'N98_EcomDevPHPUnitIssue_Test_Controller_TestController::bAction'. .
Time: 4 seconds, Memory: 36.50Mb
OK (1 test, 4 assertions)
Probably issue is in Magento core, but strange, since I easily created tests before with the same action dispatch that was checking execution of observer and it was working without problems, including fixtures, the only problem I was facing it is core Mage::register() calls in controllers so in setUp I cleared them up to make it testable.
I guess all the issues are somehow in Magento core as Mage 1 it is just not so well testable, isn't it :-) ? Did you check actual execution or just the assertEventDispatches() ? Is that test you made in the testsuite?
This actually seems to be fixed in the latest EcomDev_PHPUnit - i was not noticing this because the version number in the config.xml stayed the same.
@IvanChepurnyi Is it possible to updated the version number in config.xml on new pushes to master? Or is the master just not considered stable?