EventDispatcherTraitTest.php 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. <?php
  2. declare(strict_types=1);
  3. /**
  4. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  5. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  6. *
  7. * Licensed under The MIT License
  8. * Redistributions of files must retain the above copyright notice.
  9. *
  10. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  11. * @link https://cakephp.org CakePHP(tm) Project
  12. * @since 3.0.0
  13. * @license https://opensource.org/licenses/mit-license.php MIT License
  14. */
  15. namespace Cake\Test\TestCase\Event;
  16. use Cake\Event\Event;
  17. use Cake\Event\EventDispatcherTrait;
  18. use Cake\Event\EventManager;
  19. use Cake\TestSuite\TestCase;
  20. /**
  21. * EventDispatcherTrait test case
  22. */
  23. class EventDispatcherTraitTest extends TestCase
  24. {
  25. /**
  26. * @var \Cake\Event\EventDispatcherTrait
  27. */
  28. protected $subject;
  29. /**
  30. * setup
  31. */
  32. public function setUp(): void
  33. {
  34. parent::setUp();
  35. $this->subject = $this->getObjectForTrait(EventDispatcherTrait::class);
  36. }
  37. /**
  38. * testGetEventManager
  39. */
  40. public function testGetEventManager(): void
  41. {
  42. $this->assertInstanceOf(EventManager::class, $this->subject->getEventManager());
  43. }
  44. /**
  45. * testDispatchEvent
  46. */
  47. public function testDispatchEvent(): void
  48. {
  49. $event = $this->subject->dispatchEvent('some.event', ['foo' => 'bar']);
  50. $this->assertInstanceOf(Event::class, $event);
  51. $this->assertSame($this->subject, $event->getSubject());
  52. $this->assertSame('some.event', $event->getName());
  53. $this->assertEquals(['foo' => 'bar'], $event->getData());
  54. }
  55. }