EventDispatcherTraitTest.php 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (https://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  5. *
  6. * Licensed under The MIT License
  7. * Redistributions of files must retain the above copyright notice.
  8. *
  9. * @copyright Copyright (c) Cake Software Foundation, Inc. (https://cakefoundation.org)
  10. * @link https://cakephp.org CakePHP(tm) Project
  11. * @since 3.0.0
  12. * @license https://opensource.org/licenses/mit-license.php MIT License
  13. */
  14. namespace Cake\Test\TestCase\Event;
  15. use Cake\Event\EventManager;
  16. use Cake\TestSuite\TestCase;
  17. /**
  18. * EventDispatcherTrait test case
  19. */
  20. class EventDispatcherTraitTest extends TestCase
  21. {
  22. /**
  23. * @var EventDispatcherTrait
  24. */
  25. public $subject;
  26. /**
  27. * setup
  28. *
  29. * @return void
  30. */
  31. public function setUp()
  32. {
  33. parent::setUp();
  34. $this->subject = $this->getObjectForTrait('Cake\Event\EventDispatcherTrait');
  35. }
  36. /**
  37. * testIsInitiallyEmpty
  38. *
  39. * @return void
  40. */
  41. public function testIsInitiallyEmpty()
  42. {
  43. $this->assertAttributeEmpty('_eventManager', $this->subject);
  44. }
  45. /**
  46. * testEventManager
  47. *
  48. * @return void
  49. */
  50. public function testEventManager()
  51. {
  52. $eventManager = new EventManager();
  53. $this->subject->eventManager($eventManager);
  54. $this->assertSame($eventManager, $this->subject->eventManager());
  55. }
  56. /**
  57. * testGetEventManager
  58. *
  59. * @return void
  60. */
  61. public function testGetEventManager()
  62. {
  63. $this->assertInstanceOf(EventManager::class, $this->subject->getEventManager());
  64. }
  65. /**
  66. * testSetEventManager
  67. *
  68. * @return void
  69. */
  70. public function testSetEventManager()
  71. {
  72. $eventManager = new EventManager();
  73. $this->subject->setEventManager($eventManager);
  74. $this->assertSame($eventManager, $this->subject->getEventManager());
  75. }
  76. /**
  77. * testDispatchEvent
  78. *
  79. * @return void
  80. */
  81. public function testDispatchEvent()
  82. {
  83. $event = $this->subject->dispatchEvent('some.event', ['foo' => 'bar']);
  84. $this->assertInstanceOf('Cake\Event\Event', $event);
  85. $this->assertSame($this->subject, $event->subject());
  86. $this->assertEquals('some.event', $event->name());
  87. $this->assertEquals(['foo' => 'bar'], $event->data());
  88. }
  89. }