EventDispatcherTraitTest.php 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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. class EventDispatcherTraitTest extends TestCase
  21. {
  22. /**
  23. * setup
  24. *
  25. * @return void
  26. */
  27. public function setUp()
  28. {
  29. parent::setUp();
  30. $this->subject = $this->getObjectForTrait('Cake\Event\EventDispatcherTrait');
  31. }
  32. /**
  33. * testIsInitiallyEmpty
  34. *
  35. * @return void
  36. */
  37. public function testIsInitiallyEmpty()
  38. {
  39. $this->assertAttributeEmpty('_eventManager', $this->subject);
  40. }
  41. /**
  42. * testSettingEventManager
  43. *
  44. * @covers \Cake\Event\EventDispatcherTrait::eventManager
  45. * @return void
  46. */
  47. public function testSettingEventManager()
  48. {
  49. $eventManager = new EventManager();
  50. $this->subject->eventManager($eventManager);
  51. $this->assertSame($eventManager, $this->subject->eventManager());
  52. }
  53. /**
  54. * testDispatchEvent
  55. *
  56. * @return void
  57. */
  58. public function testDispatchEvent()
  59. {
  60. $event = $this->subject->dispatchEvent('some.event', ['foo' => 'bar']);
  61. $this->assertInstanceOf('Cake\Event\Event', $event);
  62. $this->assertSame($this->subject, $event->subject);
  63. $this->assertEquals('some.event', $event->name);
  64. $this->assertEquals(['foo' => 'bar'], $event->data);
  65. }
  66. }