From 80e0b0b44cfbb11711286887f323ca7d3ce24daf Mon Sep 17 00:00:00 2001 From: smetdenis Date: Sat, 30 Jan 2016 14:13:37 +0600 Subject: [PATCH] namespaces fixes --- src/EventManager.php | 2 +- tests/EventsNamespacesTest.php | 70 +++++++++++++++++++++++----------- 2 files changed, 49 insertions(+), 23 deletions(-) diff --git a/src/EventManager.php b/src/EventManager.php index 0af58cf..660167e 100644 --- a/src/EventManager.php +++ b/src/EventManager.php @@ -183,7 +183,7 @@ public function listeners($eventName) $eNameParts = explode('.', $eName); - if (count($eNameParts) <= count($ePaths)) { + if (count($eNameParts) === count($ePaths)) { $isFound = true; foreach ($eNameParts as $pos => $eNamePart) { diff --git a/tests/EventsNamespacesTest.php b/tests/EventsNamespacesTest.php index 2790867..6931566 100644 --- a/tests/EventsNamespacesTest.php +++ b/tests/EventsNamespacesTest.php @@ -71,9 +71,10 @@ public function testAnyPart() $eManager->on('item.*', $this->noop); is(1, $eManager->trigger('item.save')); - is(1, $eManager->trigger('item.save.before')); - is(1, $eManager->trigger('item.save.after')); - is(1, $eManager->trigger('item.save.after.realy.deep')); + + is(0, $eManager->trigger('item.save.before')); + is(0, $eManager->trigger('item.save.after')); + is(0, $eManager->trigger('item.save.after.realy.deep')); } public function testAnyPart2() @@ -82,11 +83,12 @@ public function testAnyPart2() $eManager->on('item.*.after', $this->noop); + is(1, $eManager->trigger('item.save.after')); + is(1, $eManager->trigger('item.init.after')); + is(0, $eManager->trigger('item.save')); is(0, $eManager->trigger('item.save.before')); - - is(1, $eManager->trigger('item.save.after')); - is(1, $eManager->trigger('item.save.after.realy.deep')); + is(0, $eManager->trigger('item.save.after.realy.deep')); } public function testAnyPart3() @@ -95,11 +97,11 @@ public function testAnyPart3() $eManager->on('*.save.after', $this->noop); + is(1, $eManager->trigger('item.save.after')); + is(0, $eManager->trigger('item.save')); is(0, $eManager->trigger('item.save.before')); - - is(1, $eManager->trigger('item.save.after')); - is(1, $eManager->trigger('item.save.after.realy.deep')); + is(0, $eManager->trigger('item.save.after.realy.deep')); } public function testAnyPart4() @@ -108,11 +110,11 @@ public function testAnyPart4() $eManager->on('*.save.*', $this->noop); - is(0, $eManager->trigger('item.save')); - is(1, $eManager->trigger('item.save.before')); is(1, $eManager->trigger('item.save.after')); - is(1, $eManager->trigger('item.save.after.realy.deep')); + + is(0, $eManager->trigger('item.save')); + is(0, $eManager->trigger('item.save.after.realy.deep')); } public function testAnyPart5() @@ -121,20 +123,44 @@ public function testAnyPart5() $eManager->on('*.*.after', $this->noop); - is(0, $eManager->trigger('item.save')); - is(0, $eManager->trigger('item.save.before')); - is(1, $eManager->trigger('category.init.after')); is(1, $eManager->trigger('item.save.after')); - is(1, $eManager->trigger('item.save.after.realy.deep.name')); is(1, $eManager->trigger('item.load.after')); - is(1, $eManager->trigger('item.load.after.realy.deep.name')); + + is(0, $eManager->trigger('item.save')); + is(0, $eManager->trigger('item.save.before')); + is(0, $eManager->trigger('item.save.after.realy.deep.name')); + is(0, $eManager->trigger('item.load.after.realy.deep.name')); } public function testComplex() { $eManager = new EventManager(); + $eManager->on('item.*', function () { + }); + $eManager->on('*.init', function () { + }); + $eManager->on('*.save', function () { + }); + $eManager->on('*.save.after', function () { + }); + + is(1, $eManager->trigger('tag.init')); + is(0, $eManager->trigger('tag.save.before')); + is(1, $eManager->trigger('tag.save')); + is(1, $eManager->trigger('tag.save.after')); + + is(2, $eManager->trigger('item.init')); + is(0, $eManager->trigger('item.save.before')); + is(2, $eManager->trigger('item.save')); + is(1, $eManager->trigger('item.save.after')); + } + + public function testComplex2() + { + $eManager = new EventManager(); + $eManager->on('*.save', $this->noop); $eManager->on('*.save.*', $this->noop); $eManager->on('*.save.*', $this->noop); @@ -151,13 +177,13 @@ public function testComplex() is(0, $eManager->trigger('item.load')); is(0, $eManager->trigger('item.load.before')); is(0, $eManager->trigger('save.before')); + is(0, $eManager->trigger('item.save.before.realy.deep.name')); + is(0, $eManager->trigger('category.save.before.realy.deep.name')); is(1, $eManager->trigger('item.save')); is(1, $eManager->trigger('category')); - is(6, $eManager->trigger('item.save.before')); - is(6, $eManager->trigger('item.save.before.realy.deep.name')); - is(6, $eManager->trigger('category.save.before.realy.deep.name')); - is(4, $eManager->trigger('item.save.after')); - is(5, $eManager->trigger('item.save.after.deep')); + is(1, $eManager->trigger('item.save.after.deep')); + is(3, $eManager->trigger('item.save.after')); + is(5, $eManager->trigger('item.save.before')); } }