EcomDev_PHPUnit icon indicating copy to clipboard operation
EcomDev_PHPUnit copied to clipboard

Multiple dispatches in one test run: Events not properly isloated

Open amenk opened this issue 12 years ago • 3 comments

I have a module that registers a frontend event "controller_action_predispatch_wishlist_index_send"

Steps to reproduce:

  1. $this->dispatch('/);
  2. $this->dispatch('wishlist/index/send');
  3. 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:

  1. $this->dispatch('wishlist/index/send');
  2. 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:

  1. 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)

amenk avatar Feb 14 '13 12:02 amenk

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.

IvanChepurnyi avatar Feb 14 '13 17:02 IvanChepurnyi

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?

amenk avatar Feb 18 '13 09:02 amenk

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?

amenk avatar Mar 11 '13 15:03 amenk