123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899 |
- <?php
- /*
- * This file is part of the symfony package.
- * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
- *
- * For the full copyright and license information, please view the LICENSE
- * file that was distributed with this source code.
- */
- namespace Symfony\Tests\Components\EventDispatcher;
- use Symfony\Components\EventDispatcher\Event;
- class EventTest extends \PHPUnit_Framework_TestCase
- {
- protected $subject;
- protected $parameters;
- public function testGetSubject()
- {
- $event = $this->createEvent();
- $this->assertEquals($this->subject, $event->getSubject(), '->getSubject() returns the event subject');
- }
- public function testGetName()
- {
- $this->assertEquals('name', $this->createEvent()->getName(), '->getName() returns the event name');
- }
- public function testParameters()
- {
- $event = $this->createEvent();
- $this->assertEquals($this->parameters, $event->getParameters(), '->getParameters() returns the event parameters');
- $this->assertEquals('bar', $event->getParameter('foo'), '->getParameter() returns the value of a parameter');
- $event->setParameter('foo', 'foo');
- $this->assertEquals('foo', $event->getParameter('foo'), '->setParameter() changes the value of a parameter');
- $this->assertTrue($event->hasParameter('foo'), '->hasParameter() returns true if the parameter is defined');
- unset($event['foo']);
- $this->assertTrue(!$event->hasParameter('foo'), '->hasParameter() returns false if the parameter is not defined');
- try
- {
- $event->getParameter('foobar');
- $this->fail('->getParameter() throws an \InvalidArgumentException exception when the parameter does not exist');
- }
- catch (\InvalidArgumentException $e)
- {
- }
- $event = new Event($this->subject, 'name', $this->parameters);
- }
- public function testSetGetReturnValue()
- {
- $event = $this->createEvent();
- $event->setReturnValue('foo');
- $this->assertEquals('foo', $event->getReturnValue(), '->getReturnValue() returns the return value of the event');
- }
- public function testSetIsProcessed()
- {
- $event = $this->createEvent();
- $event->setProcessed(true);
- $this->assertEquals(true, $event->isProcessed(), '->isProcessed() returns true if the event has been processed');
- $event->setProcessed(false);
- $this->assertEquals(false, $event->isProcessed(), '->setProcessed() changes the processed status');
- }
- public function testArrayAccessInterface()
- {
- $event = $this->createEvent();
- $this->assertEquals('bar', $event['foo'], 'Event implements the ArrayAccess interface');
- $event['foo'] = 'foo';
- $this->assertEquals('foo', $event['foo'], 'Event implements the ArrayAccess interface');
- try
- {
- $event['foobar'];
- $this->fail('::offsetGet() throws an \InvalidArgumentException exception when the parameter does not exist');
- }
- catch (\InvalidArgumentException $e)
- {
- }
- $this->assertTrue(isset($event['foo']), 'Event implements the ArrayAccess interface');
- unset($event['foo']);
- $this->assertTrue(!isset($event['foo']), 'Event implements the ArrayAccess interface');
- }
- protected function createEvent()
- {
- $this->subject = new \stdClass();
- $this->parameters = array('foo' => 'bar');
- return new Event($this->subject, 'name', $this->parameters);
- }
- }
|