EventDispatcherTraitTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. * @group deprecated
  49. * @return void
  50. */
  51. public function testEventManager()
  52. {
  53. $this->deprecated(function () {
  54. $eventManager = new EventManager();
  55. $this->subject->eventManager($eventManager);
  56. $this->assertSame($eventManager, $this->subject->eventManager());
  57. });
  58. }
  59. /**
  60. * testGetEventManager
  61. *
  62. * @return void
  63. */
  64. public function testGetEventManager()
  65. {
  66. $this->assertInstanceOf(EventManager::class, $this->subject->getEventManager());
  67. }
  68. /**
  69. * testSetEventManager
  70. *
  71. * @return void
  72. */
  73. public function testSetEventManager()
  74. {
  75. $eventManager = new EventManager();
  76. $this->subject->setEventManager($eventManager);
  77. $this->assertSame($eventManager, $this->subject->getEventManager());
  78. }
  79. /**
  80. * testDispatchEvent
  81. *
  82. * @return void
  83. */
  84. public function testDispatchEvent()
  85. {
  86. $event = $this->subject->dispatchEvent('some.event', ['foo' => 'bar']);
  87. $this->assertInstanceOf('Cake\Event\Event', $event);
  88. $this->assertSame($this->subject, $event->getSubject());
  89. $this->assertEquals('some.event', $event->getName());
  90. $this->assertEquals(['foo' => 'bar'], $event->getData());
  91. }
  92. }