EventTest.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. /*
  3. * This file is part of the symfony package.
  4. * (c) Fabien Potencier <fabien.potencier@symfony-project.com>
  5. *
  6. * For the full copyright and license information, please view the LICENSE
  7. * file that was distributed with this source code.
  8. */
  9. require_once __DIR__.'/../../../bootstrap.php';
  10. use Symfony\Components\EventDispatcher\Event;
  11. $t = new LimeTest(11);
  12. $subject = new stdClass();
  13. $parameters = array('foo' => 'bar');
  14. $event = new Event($subject, 'name', $parameters);
  15. // ->getSubject()
  16. $t->diag('->getSubject()');
  17. $t->is($event->getSubject(), $subject, '->getSubject() returns the event subject');
  18. // ->getName()
  19. $t->diag('->getName()');
  20. $t->is($event->getName(), 'name', '->getName() returns the event name');
  21. // ->getParameters()
  22. $t->diag('->getParameters()');
  23. $t->is($event->getParameters(), $parameters, '->getParameters() returns the event parameters');
  24. // ->getReturnValue() ->setReturnValue()
  25. $t->diag('->getReturnValue() ->setReturnValue()');
  26. $event->setReturnValue('foo');
  27. $t->is($event->getReturnValue(), 'foo', '->getReturnValue() returns the return value of the event');
  28. // ->setProcessed() ->isProcessed()
  29. $t->diag('->setProcessed() ->isProcessed()');
  30. $event->setProcessed(true);
  31. $t->is($event->isProcessed(), true, '->isProcessed() returns true if the event has been processed');
  32. $event->setProcessed(false);
  33. $t->is($event->isProcessed(), false, '->setProcessed() changes the processed status');
  34. // ArrayAccess interface
  35. $t->diag('ArrayAccess interface');
  36. $t->is($event['foo'], 'bar', 'Event implements the ArrayAccess interface');
  37. $event['foo'] = 'foo';
  38. $t->is($event['foo'], 'foo', 'Event implements the ArrayAccess interface');
  39. try
  40. {
  41. $event['foobar'];
  42. $t->fail('::offsetGet() throws an \InvalidArgumentException exception when the parameter does not exist');
  43. }
  44. catch (\InvalidArgumentException $e)
  45. {
  46. $t->pass('::offsetGet() throws an \InvalidArgumentException exception when the parameter does not exist');
  47. }
  48. $t->ok(isset($event['foo']), 'Event implements the ArrayAccess interface');
  49. unset($event['foo']);
  50. $t->ok(!isset($event['foo']), 'Event implements the ArrayAccess interface');