EventTest.php 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 PHPUnit\Framework\TestCase;
  12. use Symfony\Component\EventDispatcher\Event;
  13. use Symfony\Component\EventDispatcher\EventDispatcher;
  14. /**
  15. * Test class for Event.
  16. */
  17. class EventTest extends TestCase
  18. {
  19. /**
  20. * @var \Symfony\Component\EventDispatcher\Event
  21. */
  22. protected $event;
  23. /**
  24. * @var \Symfony\Component\EventDispatcher\EventDispatcher
  25. */
  26. protected $dispatcher;
  27. /**
  28. * Sets up the fixture, for example, opens a network connection.
  29. * This method is called before a test is executed.
  30. */
  31. protected function setUp()
  32. {
  33. $this->event = new Event();
  34. $this->dispatcher = new EventDispatcher();
  35. }
  36. /**
  37. * Tears down the fixture, for example, closes a network connection.
  38. * This method is called after a test is executed.
  39. */
  40. protected function tearDown()
  41. {
  42. $this->event = null;
  43. $this->dispatcher = null;
  44. }
  45. public function testIsPropagationStopped()
  46. {
  47. $this->assertFalse($this->event->isPropagationStopped());
  48. }
  49. public function testStopPropagationAndIsPropagationStopped()
  50. {
  51. $this->event->stopPropagation();
  52. $this->assertTrue($this->event->isPropagationStopped());
  53. }
  54. /**
  55. * @group legacy
  56. */
  57. public function testLegacySetDispatcher()
  58. {
  59. $this->event->setDispatcher($this->dispatcher);
  60. $this->assertSame($this->dispatcher, $this->event->getDispatcher());
  61. }
  62. /**
  63. * @group legacy
  64. */
  65. public function testLegacyGetDispatcher()
  66. {
  67. $this->assertNull($this->event->getDispatcher());
  68. }
  69. /**
  70. * @group legacy
  71. */
  72. public function testLegacyGetName()
  73. {
  74. $this->assertNull($this->event->getName());
  75. }
  76. /**
  77. * @group legacy
  78. */
  79. public function testLegacySetName()
  80. {
  81. $this->event->setName('foo');
  82. $this->assertEquals('foo', $this->event->getName());
  83. }
  84. }