Laravel version update
Laravel version update
This commit is contained in:
@@ -11,11 +11,12 @@
|
||||
|
||||
namespace Symfony\Component\EventDispatcher\Tests;
|
||||
|
||||
use PHPUnit\Framework\TestCase;
|
||||
use Symfony\Component\EventDispatcher\Event;
|
||||
use Symfony\Component\EventDispatcher\EventDispatcher;
|
||||
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
|
||||
|
||||
abstract class AbstractEventDispatcherTest extends \PHPUnit_Framework_TestCase
|
||||
abstract class AbstractEventDispatcherTest extends TestCase
|
||||
{
|
||||
/* Some pseudo events */
|
||||
const preFoo = 'pre.foo';
|
||||
@@ -55,6 +56,7 @@ abstract class AbstractEventDispatcherTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
$this->dispatcher->addListener('pre.foo', array($this->listener, 'preFoo'));
|
||||
$this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'));
|
||||
$this->assertTrue($this->dispatcher->hasListeners());
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::preFoo));
|
||||
$this->assertTrue($this->dispatcher->hasListeners(self::postFoo));
|
||||
$this->assertCount(1, $this->dispatcher->getListeners(self::preFoo));
|
||||
@@ -156,7 +158,7 @@ abstract class AbstractEventDispatcherTest extends \PHPUnit_Framework_TestCase
|
||||
// be executed
|
||||
// Manually set priority to enforce $this->listener to be called first
|
||||
$this->dispatcher->addListener('post.foo', array($this->listener, 'postFoo'), 10);
|
||||
$this->dispatcher->addListener('post.foo', array($otherListener, 'preFoo'));
|
||||
$this->dispatcher->addListener('post.foo', array($otherListener, 'postFoo'));
|
||||
$this->dispatcher->dispatch(self::postFoo);
|
||||
$this->assertTrue($this->listener->postFooInvoked);
|
||||
$this->assertFalse($otherListener->postFooInvoked);
|
||||
@@ -301,6 +303,73 @@ abstract class AbstractEventDispatcherTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertFalse($this->dispatcher->hasListeners('foo'));
|
||||
$this->assertFalse($this->dispatcher->hasListeners());
|
||||
}
|
||||
|
||||
public function testHasListenersIsLazy()
|
||||
{
|
||||
$called = 0;
|
||||
$listener = array(function () use (&$called) { ++$called; }, 'onFoo');
|
||||
$this->dispatcher->addListener('foo', $listener);
|
||||
$this->assertTrue($this->dispatcher->hasListeners());
|
||||
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
||||
$this->assertSame(0, $called);
|
||||
}
|
||||
|
||||
public function testDispatchLazyListener()
|
||||
{
|
||||
$called = 0;
|
||||
$factory = function () use (&$called) {
|
||||
++$called;
|
||||
|
||||
return new TestWithDispatcher();
|
||||
};
|
||||
$this->dispatcher->addListener('foo', array($factory, 'foo'));
|
||||
$this->assertSame(0, $called);
|
||||
$this->dispatcher->dispatch('foo', new Event());
|
||||
$this->dispatcher->dispatch('foo', new Event());
|
||||
$this->assertSame(1, $called);
|
||||
}
|
||||
|
||||
public function testRemoveFindsLazyListeners()
|
||||
{
|
||||
$test = new TestWithDispatcher();
|
||||
$factory = function () use ($test) { return $test; };
|
||||
|
||||
$this->dispatcher->addListener('foo', array($factory, 'foo'));
|
||||
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
||||
$this->dispatcher->removeListener('foo', array($test, 'foo'));
|
||||
$this->assertFalse($this->dispatcher->hasListeners('foo'));
|
||||
|
||||
$this->dispatcher->addListener('foo', array($test, 'foo'));
|
||||
$this->assertTrue($this->dispatcher->hasListeners('foo'));
|
||||
$this->dispatcher->removeListener('foo', array($factory, 'foo'));
|
||||
$this->assertFalse($this->dispatcher->hasListeners('foo'));
|
||||
}
|
||||
|
||||
public function testPriorityFindsLazyListeners()
|
||||
{
|
||||
$test = new TestWithDispatcher();
|
||||
$factory = function () use ($test) { return $test; };
|
||||
|
||||
$this->dispatcher->addListener('foo', array($factory, 'foo'), 3);
|
||||
$this->assertSame(3, $this->dispatcher->getListenerPriority('foo', array($test, 'foo')));
|
||||
$this->dispatcher->removeListener('foo', array($factory, 'foo'));
|
||||
|
||||
$this->dispatcher->addListener('foo', array($test, 'foo'), 5);
|
||||
$this->assertSame(5, $this->dispatcher->getListenerPriority('foo', array($factory, 'foo')));
|
||||
}
|
||||
|
||||
public function testGetLazyListeners()
|
||||
{
|
||||
$test = new TestWithDispatcher();
|
||||
$factory = function () use ($test) { return $test; };
|
||||
|
||||
$this->dispatcher->addListener('foo', array($factory, 'foo'), 3);
|
||||
$this->assertSame(array(array($test, 'foo')), $this->dispatcher->getListeners('foo'));
|
||||
|
||||
$this->dispatcher->removeListener('foo', array($test, 'foo'));
|
||||
$this->dispatcher->addListener('bar', array($factory, 'foo'), 3);
|
||||
$this->assertSame(array('bar' => array(array($test, 'foo'))), $this->dispatcher->getListeners());
|
||||
}
|
||||
}
|
||||
|
||||
class CallableClass
|
||||
|
Reference in New Issue
Block a user