Skip to content

Commit

Permalink
namespaces fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
SmetDenis committed Jan 30, 2016
1 parent 5b16ad2 commit 80e0b0b
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/EventManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
70 changes: 48 additions & 22 deletions tests/EventsNamespacesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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);
Expand All @@ -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'));
}
}

0 comments on commit 80e0b0b

Please sign in to comment.