EventDispatcherTraitTest.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * CakePHP(tm) : Rapid Development Framework (http://cakephp.org)
  4. * Copyright (c) Cake Software Foundation, Inc. (http://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. (http://cakefoundation.org)
  10. * @link http://cakephp.org CakePHP(tm) Project
  11. * @since 3.0.0
  12. * @license http://www.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. */
  21. class EventDispatcherTraitTest extends TestCase
  22. {
  23. /**
  24. * setup
  25. *
  26. * @return void
  27. */
  28. public function setUp()
  29. {
  30. parent::setUp();
  31. $this->subject = $this->getObjectForTrait('Cake\Event\EventDispatcherTrait');
  32. }
  33. /**
  34. * testIsInitiallyEmpty
  35. *
  36. * @return void
  37. */
  38. public function testIsInitiallyEmpty()
  39. {
  40. $this->assertAttributeEmpty('_eventManager', $this->subject);
  41. }
  42. /**
  43. * testSettingEventManager
  44. *
  45. * @covers \Cake\Event\EventDispatcherTrait::eventManager
  46. * @return void
  47. */
  48. public function testSettingEventManager()
  49. {
  50. $eventManager = new EventManager();
  51. $this->subject->eventManager($eventManager);
  52. $this->assertSame($eventManager, $this->subject->eventManager());
  53. }
  54. /**
  55. * testDispatchEvent
  56. *
  57. * @return void
  58. */
  59. public function testDispatchEvent()
  60. {
  61. $event = $this->subject->dispatchEvent('some.event', ['foo' => 'bar']);
  62. $this->assertInstanceOf('Cake\Event\Event', $event);
  63. $this->assertSame($this->subject, $event->subject);
  64. $this->assertEquals('some.event', $event->name);
  65. $this->assertEquals(['foo' => 'bar'], $event->data);
  66. }
  67. }