From 2bb68a5f989fb325e792e6018a8969da2ef934f5 Mon Sep 17 00:00:00 2001 From: Emanuel1989 Date: Sat, 5 Oct 2013 01:21:25 +0100 Subject: [PATCH 1/4] Bug 1331 - detachAll listeners from EventsManager --- ext/events/manager.c | 7 ++- ext/events/manager.h | 6 +-- ext/events/managerinterface.c | 2 +- ext/events/managerinterface.h | 4 +- unit-tests/EventsTest.php | 88 ++++++++++++++++++++++++++++++++--- 5 files changed, 91 insertions(+), 16 deletions(-) diff --git a/ext/events/manager.c b/ext/events/manager.c index 321159200ec..103a8d1aa8e 100644 --- a/ext/events/manager.c +++ b/ext/events/manager.c @@ -231,9 +231,9 @@ PHP_METHOD(Phalcon_Events_Manager, getResponses){ * * @param string $type */ -PHP_METHOD(Phalcon_Events_Manager, dettachAll){ +PHP_METHOD(Phalcon_Events_Manager, detachAll){ - zval *type = NULL, *events = NULL, *null_value; + zval *type = NULL, *events = NULL; PHALCON_MM_GROW(); @@ -249,8 +249,7 @@ PHP_METHOD(Phalcon_Events_Manager, dettachAll){ PHALCON_INIT_NVAR(events); } else { if (phalcon_array_isset(events, type)) { - PHALCON_INIT_VAR(null_value); - phalcon_array_update_zval(&events, type, &null_value, PH_COPY | PH_SEPARATE); + phalcon_array_unset(&events, type, 0); } } diff --git a/ext/events/manager.h b/ext/events/manager.h index f7c93e23450..124a1b871ea 100644 --- a/ext/events/manager.h +++ b/ext/events/manager.h @@ -27,7 +27,7 @@ PHP_METHOD(Phalcon_Events_Manager, arePrioritiesEnabled); PHP_METHOD(Phalcon_Events_Manager, collectResponses); PHP_METHOD(Phalcon_Events_Manager, isCollecting); PHP_METHOD(Phalcon_Events_Manager, getResponses); -PHP_METHOD(Phalcon_Events_Manager, dettachAll); +PHP_METHOD(Phalcon_Events_Manager, detachAll); PHP_METHOD(Phalcon_Events_Manager, fireQueue); PHP_METHOD(Phalcon_Events_Manager, fire); PHP_METHOD(Phalcon_Events_Manager, hasListeners); @@ -47,7 +47,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_events_manager_collectresponses, 0, 0, 1) ZEND_ARG_INFO(0, collect) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_events_manager_dettachall, 0, 0, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_events_manager_detachall, 0, 0, 0) ZEND_ARG_INFO(0, type) ZEND_END_ARG_INFO() @@ -78,7 +78,7 @@ PHALCON_INIT_FUNCS(phalcon_events_manager_method_entry){ PHP_ME(Phalcon_Events_Manager, collectResponses, arginfo_phalcon_events_manager_collectresponses, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Events_Manager, isCollecting, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Events_Manager, getResponses, NULL, ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Events_Manager, dettachAll, arginfo_phalcon_events_manager_dettachall, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Events_Manager, detachAll, arginfo_phalcon_events_manager_detachall, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Events_Manager, fireQueue, arginfo_phalcon_events_manager_firequeue, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Events_Manager, fire, arginfo_phalcon_events_manager_fire, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Events_Manager, hasListeners, arginfo_phalcon_events_manager_haslisteners, ZEND_ACC_PUBLIC) diff --git a/ext/events/managerinterface.c b/ext/events/managerinterface.c index 699b381867e..29fd7f1c501 100644 --- a/ext/events/managerinterface.c +++ b/ext/events/managerinterface.c @@ -50,7 +50,7 @@ PHALCON_DOC_METHOD(Phalcon_Events_ManagerInterface, attach); * * @param string $type */ -PHALCON_DOC_METHOD(Phalcon_Events_ManagerInterface, dettachAll); +PHALCON_DOC_METHOD(Phalcon_Events_ManagerInterface, detachAll); /** * Fires a event in the events manager causing that the acive listeners will be notified about it diff --git a/ext/events/managerinterface.h b/ext/events/managerinterface.h index fdb71f3e10a..70bf3a81afc 100644 --- a/ext/events/managerinterface.h +++ b/ext/events/managerinterface.h @@ -26,7 +26,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_events_managerinterface_attach, 0, 0, 2) ZEND_ARG_INFO(0, handler) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_events_managerinterface_dettachall, 0, 0, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_events_managerinterface_detachall, 0, 0, 0) ZEND_ARG_INFO(0, type) ZEND_END_ARG_INFO() @@ -42,7 +42,7 @@ ZEND_END_ARG_INFO() PHALCON_INIT_FUNCS(phalcon_events_managerinterface_method_entry){ PHP_ABSTRACT_ME(Phalcon_Events_ManagerInterface, attach, arginfo_phalcon_events_managerinterface_attach) - PHP_ABSTRACT_ME(Phalcon_Events_ManagerInterface, dettachAll, arginfo_phalcon_events_managerinterface_dettachall) + PHP_ABSTRACT_ME(Phalcon_Events_ManagerInterface, detachAll, arginfo_phalcon_events_managerinterface_detachall) PHP_ABSTRACT_ME(Phalcon_Events_ManagerInterface, fire, arginfo_phalcon_events_managerinterface_fire) PHP_ABSTRACT_ME(Phalcon_Events_ManagerInterface, getListeners, arginfo_phalcon_events_managerinterface_getlisteners) PHP_FE_END diff --git a/unit-tests/EventsTest.php b/unit-tests/EventsTest.php index 0bf4a89304d..7bae6e9e7f8 100644 --- a/unit-tests/EventsTest.php +++ b/unit-tests/EventsTest.php @@ -23,10 +23,15 @@ class LeDummyComponent protected $_eventsManager; - public function setEventManager($eventsManager) + public function setEventsManager($eventsManager) { $this->_eventsManager = $eventsManager; } + + public function getEventsManager() + { + return $this->_eventsManager; + } public function leAction() { @@ -41,7 +46,7 @@ class LeAnotherComponent protected $_eventsManager; - public function setEventManager($eventsManager) + public function setEventsManager($eventsManager) { $this->_eventsManager = $eventsManager; } @@ -125,10 +130,10 @@ public function testEvents() $eventsManager->attach('dummy', $listener); $component = new LeDummyComponent(); - $component->setEventManager($eventsManager); + $component->setEventsManager($eventsManager); $another = new LeAnotherComponent(); - $another->setEventManager($eventsManager); + $another->setEventsManager($eventsManager); $component->leAction(); $component->leAction(); @@ -156,9 +161,9 @@ public function testEvents() /* //This is failling :( - $eventsManager->dettach('dummy', $listener);*/ + $eventsManager->detach('dummy', $listener);*/ - /*$eventsManager->dettachAll('dummy'); + /*$eventsManager->detachAll('dummy'); $component->leAction(); $component->leAction(); @@ -218,4 +223,75 @@ public function testEventsWeakref() $this->assertEquals($data, "show first listener\n"); } + + /** + * "Attaching event listeners by event name fails if preceded by + * detachment of all listeners for that type." + * + * Test contains 4 steps: + * - assigning event manager to dummy service with single log event + * listener attached + * - attaching second log listener + * - detaching all log listeners + * - attaching different listener + * + * @see https://github.com/phalcon/cphalcon/issues/1331 + */ + public function testBug1331() + { + if (!class_exists('MyFirstWeakrefListener') + || !class_exists('MySecondWeakrefListener') + ) { + return; + } + + $di = new Phalcon\Di; + $di->set('componentX', function() use ($di) { + $component = new LeDummyComponent(); + $eventsManager = new Phalcon\Events\Manager; + $eventsManager->attach('log', $di->get('MyFirstWeakrefListener')); + $component->setEventsManager($eventsManager); + return $component; + }); + + $di->set('firstListener', 'MyFirstWeakrefListener'); + $di->set('secondListener', 'MySecondWeakrefListener'); + + // ----- TESTING STEP 1 - SIGNLE 'LOG' LISTENER ATTACHED + + $component = $di->get('componentX'); + + $logListeners = $component->getEventsManager()->getListeners('log'); + + $this->assertContainsOnlyInstancesOf('MyFirstWeakrefListener', $logListeners); + $this->assertCount(1, $logListeners); + + // ----- TESTING STEP 2 - SECOND 'LOG' LISTENER ATTACHED + + $component->getEventsManager()->attach('log', $di->get('MySecondWeakrefListener')); + + $logListeners = $component->getEventsManager()->getListeners('log'); + + $this->assertCount(2, $logListeners); + $firstLister = array_shift($logListeners); + $secondLister = array_shift($logListeners); + $this->assertInstanceOf('MyFirstWeakrefListener', $firstLister); + $this->assertInstanceOf('MySecondWeakrefListener', $secondLister); + + // ----- TESTING STEP 3 - ALL 'LOG' LISTENER DETACHED + + $component->getEventsManager()->detachAll('log'); + + $logListeners = $component->getEventsManager()->getListeners('log'); + $this->assertEmpty($logListeners); + + // ----- TESTING STEP 4 - SINGLE 'LOG' LISTENER ATTACHED SECOND TIME + + $component->getEventsManager()->attach('log', $di->get('MySecondWeakrefListener')); + + $logListeners = $component->getEventsManager()->getListeners('log'); + + $this->assertContainsOnlyInstancesOf('MySecondWeakrefListener', $logListeners); + $this->assertCount(1, $logListeners); + } } From 58489a89fe4f852c7138c5e4affb50cfa6678c47 Mon Sep 17 00:00:00 2001 From: Emanuel1989 Date: Sat, 5 Oct 2013 02:02:07 +0100 Subject: [PATCH 2/4] Bug 1331 - detachAll listeners from EventsManager --- ext/events/manager.c | 36 ++++++++++++++++- ext/events/manager.h | 8 +++- ext/events/managerinterface.c | 2 +- ext/events/managerinterface.h | 4 +- unit-tests/EventsTest.php | 75 +++++++++++++++++++++++++++++++++++ 5 files changed, 120 insertions(+), 5 deletions(-) diff --git a/ext/events/manager.c b/ext/events/manager.c index 103a8d1aa8e..2213e63d343 100644 --- a/ext/events/manager.c +++ b/ext/events/manager.c @@ -226,6 +226,40 @@ PHP_METHOD(Phalcon_Events_Manager, getResponses){ RETURN_MEMBER(this_ptr, "_responses"); } +/** + * Removes all events from the EventsManager (deprecated) + * + * @param string $type + * + * @deprecated + */ +PHP_METHOD(Phalcon_Events_Manager, dettachAll){ + + zval *type = NULL, *events = NULL; + + PHALCON_MM_GROW(); + + phalcon_fetch_params(1, 0, 1, &type); + + if (!type) { + type = PHALCON_GLOBAL(z_null); + } + + PHALCON_OBS_VAR(events); + phalcon_read_property_this(&events, this_ptr, SL("_events"), PH_NOISY_CC); + if (Z_TYPE_P(type) == IS_NULL) { + PHALCON_INIT_NVAR(events); + } else { + if (phalcon_array_isset(events, type)) { + phalcon_array_unset(&events, type, 0); + } + } + + phalcon_update_property_this(this_ptr, SL("_events"), events TSRMLS_CC); + + PHALCON_MM_RESTORE(); +} + /** * Removes all events from the EventsManager * @@ -252,7 +286,7 @@ PHP_METHOD(Phalcon_Events_Manager, detachAll){ phalcon_array_unset(&events, type, 0); } } - + phalcon_update_property_this(this_ptr, SL("_events"), events TSRMLS_CC); PHALCON_MM_RESTORE(); diff --git a/ext/events/manager.h b/ext/events/manager.h index 124a1b871ea..1adf3f73c3a 100644 --- a/ext/events/manager.h +++ b/ext/events/manager.h @@ -27,6 +27,7 @@ PHP_METHOD(Phalcon_Events_Manager, arePrioritiesEnabled); PHP_METHOD(Phalcon_Events_Manager, collectResponses); PHP_METHOD(Phalcon_Events_Manager, isCollecting); PHP_METHOD(Phalcon_Events_Manager, getResponses); +PHP_METHOD(Phalcon_Events_Manager, dettachAll); PHP_METHOD(Phalcon_Events_Manager, detachAll); PHP_METHOD(Phalcon_Events_Manager, fireQueue); PHP_METHOD(Phalcon_Events_Manager, fire); @@ -47,6 +48,10 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_events_manager_collectresponses, 0, 0, 1) ZEND_ARG_INFO(0, collect) ZEND_END_ARG_INFO() +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_events_manager_dettachall, 0, 0, 0) + ZEND_ARG_INFO(0, type) +ZEND_END_ARG_INFO() + ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_events_manager_detachall, 0, 0, 0) ZEND_ARG_INFO(0, type) ZEND_END_ARG_INFO() @@ -78,7 +83,8 @@ PHALCON_INIT_FUNCS(phalcon_events_manager_method_entry){ PHP_ME(Phalcon_Events_Manager, collectResponses, arginfo_phalcon_events_manager_collectresponses, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Events_Manager, isCollecting, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Events_Manager, getResponses, NULL, ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Events_Manager, detachAll, arginfo_phalcon_events_manager_detachall, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Events_Manager, dettachAll, arginfo_phalcon_events_manager_dettachall, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Events_Manager, detachAll, arginfo_phalcon_events_manager_detachall, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Events_Manager, fireQueue, arginfo_phalcon_events_manager_firequeue, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Events_Manager, fire, arginfo_phalcon_events_manager_fire, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Events_Manager, hasListeners, arginfo_phalcon_events_manager_haslisteners, ZEND_ACC_PUBLIC) diff --git a/ext/events/managerinterface.c b/ext/events/managerinterface.c index 29fd7f1c501..699b381867e 100644 --- a/ext/events/managerinterface.c +++ b/ext/events/managerinterface.c @@ -50,7 +50,7 @@ PHALCON_DOC_METHOD(Phalcon_Events_ManagerInterface, attach); * * @param string $type */ -PHALCON_DOC_METHOD(Phalcon_Events_ManagerInterface, detachAll); +PHALCON_DOC_METHOD(Phalcon_Events_ManagerInterface, dettachAll); /** * Fires a event in the events manager causing that the acive listeners will be notified about it diff --git a/ext/events/managerinterface.h b/ext/events/managerinterface.h index 70bf3a81afc..fdb71f3e10a 100644 --- a/ext/events/managerinterface.h +++ b/ext/events/managerinterface.h @@ -26,7 +26,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_events_managerinterface_attach, 0, 0, 2) ZEND_ARG_INFO(0, handler) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_events_managerinterface_detachall, 0, 0, 0) +ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_events_managerinterface_dettachall, 0, 0, 0) ZEND_ARG_INFO(0, type) ZEND_END_ARG_INFO() @@ -42,7 +42,7 @@ ZEND_END_ARG_INFO() PHALCON_INIT_FUNCS(phalcon_events_managerinterface_method_entry){ PHP_ABSTRACT_ME(Phalcon_Events_ManagerInterface, attach, arginfo_phalcon_events_managerinterface_attach) - PHP_ABSTRACT_ME(Phalcon_Events_ManagerInterface, detachAll, arginfo_phalcon_events_managerinterface_detachall) + PHP_ABSTRACT_ME(Phalcon_Events_ManagerInterface, dettachAll, arginfo_phalcon_events_managerinterface_dettachall) PHP_ABSTRACT_ME(Phalcon_Events_ManagerInterface, fire, arginfo_phalcon_events_managerinterface_fire) PHP_ABSTRACT_ME(Phalcon_Events_ManagerInterface, getListeners, arginfo_phalcon_events_managerinterface_getlisteners) PHP_FE_END diff --git a/unit-tests/EventsTest.php b/unit-tests/EventsTest.php index 7bae6e9e7f8..d66dc2cb12d 100644 --- a/unit-tests/EventsTest.php +++ b/unit-tests/EventsTest.php @@ -294,4 +294,79 @@ public function testBug1331() $this->assertContainsOnlyInstancesOf('MySecondWeakrefListener', $logListeners); $this->assertCount(1, $logListeners); } + + /** + * "Attaching event listeners by event name fails if preceded by + * detachment of all listeners for that type." + * + * Test contains 4 steps: + * - assigning event manager to dummy service with single log event + * listener attached + * - attaching second log listener + * - detaching all log listeners + * - attaching different listener + * + * NOTE: This test looks the same as above but it checks dettachAll() + * instead of detachAll() method. To be DELETED when dettachAll() + * will not supported any more. + * + * @see https://github.com/phalcon/cphalcon/issues/1331 + */ + public function testBug1331BackwardCompatibility() + { + if (!class_exists('MyFirstWeakrefListener') + || !class_exists('MySecondWeakrefListener') + ) { + return; + } + + $di = new Phalcon\Di; + $di->set('componentX', function() use ($di) { + $component = new LeDummyComponent(); + $eventsManager = new Phalcon\Events\Manager; + $eventsManager->attach('log', $di->get('MyFirstWeakrefListener')); + $component->setEventsManager($eventsManager); + return $component; + }); + + $di->set('firstListener', 'MyFirstWeakrefListener'); + $di->set('secondListener', 'MySecondWeakrefListener'); + + // ----- TESTING STEP 1 - SIGNLE 'LOG' LISTENER ATTACHED + + $component = $di->get('componentX'); + + $logListeners = $component->getEventsManager()->getListeners('log'); + + $this->assertContainsOnlyInstancesOf('MyFirstWeakrefListener', $logListeners); + $this->assertCount(1, $logListeners); + + // ----- TESTING STEP 2 - SECOND 'LOG' LISTENER ATTACHED + + $component->getEventsManager()->attach('log', $di->get('MySecondWeakrefListener')); + + $logListeners = $component->getEventsManager()->getListeners('log'); + + $this->assertCount(2, $logListeners); + $firstLister = array_shift($logListeners); + $secondLister = array_shift($logListeners); + $this->assertInstanceOf('MyFirstWeakrefListener', $firstLister); + $this->assertInstanceOf('MySecondWeakrefListener', $secondLister); + + // ----- TESTING STEP 3 - ALL 'LOG' LISTENER DETACHED + + $component->getEventsManager()->dettachAll('log'); + + $logListeners = $component->getEventsManager()->getListeners('log'); + $this->assertEmpty($logListeners); + + // ----- TESTING STEP 4 - SINGLE 'LOG' LISTENER ATTACHED SECOND TIME + + $component->getEventsManager()->attach('log', $di->get('MySecondWeakrefListener')); + + $logListeners = $component->getEventsManager()->getListeners('log'); + + $this->assertContainsOnlyInstancesOf('MySecondWeakrefListener', $logListeners); + $this->assertCount(1, $logListeners); + } } From 7cc18b4f108d2e0c011543182366d4bc342591fb Mon Sep 17 00:00:00 2001 From: Cinderella-Man Date: Sat, 5 Oct 2013 09:36:39 +0100 Subject: [PATCH 3/4] Bug 1331 - detachAll listeners from EventsManager changes --- ext/events/manager.c | 36 +----------------------------------- ext/events/manager.h | 11 +++-------- unit-tests/EventsTest.php | 20 ++++---------------- 3 files changed, 8 insertions(+), 59 deletions(-) diff --git a/ext/events/manager.c b/ext/events/manager.c index 2213e63d343..4e1155af670 100644 --- a/ext/events/manager.c +++ b/ext/events/manager.c @@ -226,40 +226,6 @@ PHP_METHOD(Phalcon_Events_Manager, getResponses){ RETURN_MEMBER(this_ptr, "_responses"); } -/** - * Removes all events from the EventsManager (deprecated) - * - * @param string $type - * - * @deprecated - */ -PHP_METHOD(Phalcon_Events_Manager, dettachAll){ - - zval *type = NULL, *events = NULL; - - PHALCON_MM_GROW(); - - phalcon_fetch_params(1, 0, 1, &type); - - if (!type) { - type = PHALCON_GLOBAL(z_null); - } - - PHALCON_OBS_VAR(events); - phalcon_read_property_this(&events, this_ptr, SL("_events"), PH_NOISY_CC); - if (Z_TYPE_P(type) == IS_NULL) { - PHALCON_INIT_NVAR(events); - } else { - if (phalcon_array_isset(events, type)) { - phalcon_array_unset(&events, type, 0); - } - } - - phalcon_update_property_this(this_ptr, SL("_events"), events TSRMLS_CC); - - PHALCON_MM_RESTORE(); -} - /** * Removes all events from the EventsManager * @@ -283,7 +249,7 @@ PHP_METHOD(Phalcon_Events_Manager, detachAll){ PHALCON_INIT_NVAR(events); } else { if (phalcon_array_isset(events, type)) { - phalcon_array_unset(&events, type, 0); + phalcon_array_unset(&events, type, PH_SEPARATE); } } diff --git a/ext/events/manager.h b/ext/events/manager.h index 1adf3f73c3a..02a4625191c 100644 --- a/ext/events/manager.h +++ b/ext/events/manager.h @@ -27,7 +27,6 @@ PHP_METHOD(Phalcon_Events_Manager, arePrioritiesEnabled); PHP_METHOD(Phalcon_Events_Manager, collectResponses); PHP_METHOD(Phalcon_Events_Manager, isCollecting); PHP_METHOD(Phalcon_Events_Manager, getResponses); -PHP_METHOD(Phalcon_Events_Manager, dettachAll); PHP_METHOD(Phalcon_Events_Manager, detachAll); PHP_METHOD(Phalcon_Events_Manager, fireQueue); PHP_METHOD(Phalcon_Events_Manager, fire); @@ -48,10 +47,6 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_events_manager_collectresponses, 0, 0, 1) ZEND_ARG_INFO(0, collect) ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_events_manager_dettachall, 0, 0, 0) - ZEND_ARG_INFO(0, type) -ZEND_END_ARG_INFO() - ZEND_BEGIN_ARG_INFO_EX(arginfo_phalcon_events_manager_detachall, 0, 0, 0) ZEND_ARG_INFO(0, type) ZEND_END_ARG_INFO() @@ -83,12 +78,12 @@ PHALCON_INIT_FUNCS(phalcon_events_manager_method_entry){ PHP_ME(Phalcon_Events_Manager, collectResponses, arginfo_phalcon_events_manager_collectresponses, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Events_Manager, isCollecting, NULL, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Events_Manager, getResponses, NULL, ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Events_Manager, dettachAll, arginfo_phalcon_events_manager_dettachall, ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Events_Manager, detachAll, arginfo_phalcon_events_manager_detachall, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Events_Manager, detachAll, arginfo_phalcon_events_manager_detachall, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Events_Manager, fireQueue, arginfo_phalcon_events_manager_firequeue, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Events_Manager, fire, arginfo_phalcon_events_manager_fire, ZEND_ACC_PUBLIC) PHP_ME(Phalcon_Events_Manager, hasListeners, arginfo_phalcon_events_manager_haslisteners, ZEND_ACC_PUBLIC) - PHP_ME(Phalcon_Events_Manager, getListeners, arginfo_phalcon_events_manager_getlisteners, ZEND_ACC_PUBLIC) + PHP_ME(Phalcon_Events_Manager, getListeners, arginfo_phalcon_events_manager_getlisteners, ZEND_ACC_PUBLIC) + PHP_MALIAS(Phalcon_Events_Manager, dettachAll, detachAll, arginfo_phalcon_events_manager_detachall, ZEND_ACC_PUBLIC | ZEND_ACC_DEPRECATED) PHP_FE_END }; diff --git a/unit-tests/EventsTest.php b/unit-tests/EventsTest.php index d66dc2cb12d..b81412dc859 100644 --- a/unit-tests/EventsTest.php +++ b/unit-tests/EventsTest.php @@ -239,12 +239,6 @@ public function testEventsWeakref() */ public function testBug1331() { - if (!class_exists('MyFirstWeakrefListener') - || !class_exists('MySecondWeakrefListener') - ) { - return; - } - $di = new Phalcon\Di; $di->set('componentX', function() use ($di) { $component = new LeDummyComponent(); @@ -263,7 +257,7 @@ public function testBug1331() $logListeners = $component->getEventsManager()->getListeners('log'); - $this->assertContainsOnlyInstancesOf('MyFirstWeakrefListener', $logListeners); + $this->assertInstanceOf('MyFirstWeakrefListener', $logListeners[0]); $this->assertCount(1, $logListeners); // ----- TESTING STEP 2 - SECOND 'LOG' LISTENER ATTACHED @@ -291,7 +285,7 @@ public function testBug1331() $logListeners = $component->getEventsManager()->getListeners('log'); - $this->assertContainsOnlyInstancesOf('MySecondWeakrefListener', $logListeners); + $this->assertInstanceOf('MySecondWeakrefListener', $logListeners[0]); $this->assertCount(1, $logListeners); } @@ -314,12 +308,6 @@ public function testBug1331() */ public function testBug1331BackwardCompatibility() { - if (!class_exists('MyFirstWeakrefListener') - || !class_exists('MySecondWeakrefListener') - ) { - return; - } - $di = new Phalcon\Di; $di->set('componentX', function() use ($di) { $component = new LeDummyComponent(); @@ -338,7 +326,7 @@ public function testBug1331BackwardCompatibility() $logListeners = $component->getEventsManager()->getListeners('log'); - $this->assertContainsOnlyInstancesOf('MyFirstWeakrefListener', $logListeners); + $this->assertInstanceOf('MyFirstWeakrefListener', $logListeners[0]); $this->assertCount(1, $logListeners); // ----- TESTING STEP 2 - SECOND 'LOG' LISTENER ATTACHED @@ -366,7 +354,7 @@ public function testBug1331BackwardCompatibility() $logListeners = $component->getEventsManager()->getListeners('log'); - $this->assertContainsOnlyInstancesOf('MySecondWeakrefListener', $logListeners); + $this->assertInstanceOf('MySecondWeakrefListener', $logListeners[0]); $this->assertCount(1, $logListeners); } } From 6e6f3c96348c740e9c8b9b4208adbab867f87564 Mon Sep 17 00:00:00 2001 From: Cinderella-Man Date: Sat, 5 Oct 2013 14:30:24 +0100 Subject: [PATCH 4/4] Deprecated warnings disabled for dettachAll() method --- unit-tests/EventsTest.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/unit-tests/EventsTest.php b/unit-tests/EventsTest.php index b81412dc859..98751fb5a07 100644 --- a/unit-tests/EventsTest.php +++ b/unit-tests/EventsTest.php @@ -343,7 +343,11 @@ public function testBug1331BackwardCompatibility() // ----- TESTING STEP 3 - ALL 'LOG' LISTENER DETACHED - $component->getEventsManager()->dettachAll('log'); + $oldErrorLevel = error_reporting(E_ALL & ~E_DEPRECATED); + + @$component->getEventsManager()->dettachAll('log'); + + error_reporting($oldErrorLevel); $logListeners = $component->getEventsManager()->getListeners('log'); $this->assertEmpty($logListeners);