EventTest.php 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\EventDispatcher\Tests;
  11. use Symfony\Component\EventDispatcher\Event;
  12. use Symfony\Component\EventDispatcher\EventDispatcher;
  13. /**
  14. * Test class for Event.
  15. */
  16. class EventTest extends \PHPUnit_Framework_TestCase
  17. {
  18. /**
  19. * @var \Symfony\Component\EventDispatcher\Event
  20. */
  21. protected $event;
  22. /**
  23. * @var \Symfony\Component\EventDispatcher\EventDispatcher
  24. */
  25. protected $dispatcher;
  26. /**
  27. * Sets up the fixture, for example, opens a network connection.
  28. * This method is called before a test is executed.
  29. */
  30. protected function setUp()
  31. {
  32. $this->event = new Event();
  33. $this->dispatcher = new EventDispatcher();
  34. }
  35. /**
  36. * Tears down the fixture, for example, closes a network connection.
  37. * This method is called after a test is executed.
  38. */
  39. protected function tearDown()
  40. {
  41. $this->event = null;
  42. $this->dispatcher = null;
  43. }
  44. public function testIsPropagationStopped()
  45. {
  46. $this->assertFalse($this->event->isPropagationStopped());
  47. }
  48. public function testStopPropagationAndIsPropagationStopped()
  49. {
  50. $this->event->stopPropagation();
  51. $this->assertTrue($this->event->isPropagationStopped());
  52. }
  53. /**
  54. * @group legacy
  55. */
  56. public function testLegacySetDispatcher()
  57. {
  58. $this->event->setDispatcher($this->dispatcher);
  59. $this->assertSame($this->dispatcher, $this->event->getDispatcher());
  60. }
  61. /**
  62. * @group legacy
  63. */
  64. public function testLegacyGetDispatcher()
  65. {
  66. $this->assertNull($this->event->getDispatcher());
  67. }
  68. /**
  69. * @group legacy
  70. */
  71. public function testLegacyGetName()
  72. {
  73. $this->assertNull($this->event->getName());
  74. }
  75. /**
  76. * @group legacy
  77. */
  78. public function testLegacySetName()
  79. {
  80. $this->event->setName('foo');
  81. $this->assertEquals('foo', $this->event->getName());
  82. }
  83. }