EventDispatcherTraitTest.php 2.0 KB

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