Fixes #16377: Fixed yii\base\Event:off() undefined index error when event handler does not match

This commit is contained in:
Razvan Grigore
2018-06-12 08:50:43 +02:00
committed by Alexander Makarov
parent 858d3531ed
commit ca3c8da503
3 changed files with 23 additions and 12 deletions

View File

@ -91,6 +91,14 @@ class EventTest extends TestCase
$this->assertTrue(Event::hasHandlers('yiiunit\framework\base\SomeInterface', SomeInterface::EVENT_SUPER_EVENT));
}
public function testOffUnmatchedHandler()
{
$this->assertFalse(Event::hasHandlers(Post::className(), 'afterSave'));
Event::on(Post::className(), 'afterSave', [$this, 'bla-bla']);
$this->assertFalse(Event::off(Post::className(), 'afterSave', [$this, 'bla-bla-bla']));
$this->assertTrue(Event::off(Post::className(), 'afterSave', [$this, 'bla-bla']));
}
/**
* @depends testOn
* @depends testHasHandlers