NotifierPoolTest.php 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Framework\Notification\Test\Unit;
  7. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
  8. class NotifierPoolTest extends \PHPUnit\Framework\TestCase
  9. {
  10. /** @var \Magento\Framework\Notification\NotifierPool */
  11. protected $notifierPool;
  12. /** @var ObjectManagerHelper */
  13. protected $objectManagerHelper;
  14. /** @var \Magento\Framework\Notification\NotifierList|\PHPUnit_Framework_MockObject_MockObject */
  15. protected $notifierList;
  16. /**
  17. * @var \Magento\Framework\Notification\NotifierPool[]|\PHPUnit_Framework_MockObject_MockObject[]
  18. */
  19. protected $notifiers;
  20. protected function setUp()
  21. {
  22. $this->objectManagerHelper = new ObjectManagerHelper($this);
  23. $notifier1 = $this->createMock(\Magento\Framework\Notification\NotifierPool::class);
  24. $notifier2 = $this->createMock(\Magento\Framework\Notification\NotifierPool::class);
  25. $this->notifiers = [$notifier1, $notifier2];
  26. $this->notifierList = $this->createMock(\Magento\Framework\Notification\NotifierList::class);
  27. $this->notifierList->expects($this->any())->method('asArray')->will($this->returnValue($this->notifiers));
  28. $this->notifierPool = $this->objectManagerHelper->getObject(
  29. \Magento\Framework\Notification\NotifierPool::class,
  30. [
  31. 'notifierList' => $this->notifierList
  32. ]
  33. );
  34. }
  35. public function testAdd()
  36. {
  37. $severity = \Magento\Framework\Notification\MessageInterface::SEVERITY_CRITICAL;
  38. $title = 'title';
  39. $description = 'desc';
  40. foreach ($this->notifiers as $notifier) {
  41. $notifier->expects($this->once())->method('add')->with($severity, $title, $description);
  42. }
  43. $this->notifierPool->add($severity, $title, $description);
  44. }
  45. public function testAddCritical()
  46. {
  47. $title = 'title';
  48. $description = 'desc';
  49. foreach ($this->notifiers as $notifier) {
  50. $notifier->expects($this->once())->method('addCritical')->with($title, $description);
  51. }
  52. $this->notifierPool->addCritical($title, $description);
  53. }
  54. public function testAddMajor()
  55. {
  56. $title = 'title';
  57. $description = 'desc';
  58. foreach ($this->notifiers as $notifier) {
  59. $notifier->expects($this->once())->method('addMajor')->with($title, $description);
  60. }
  61. $this->notifierPool->addMajor($title, $description);
  62. }
  63. public function testAddMinor()
  64. {
  65. $title = 'title';
  66. $description = 'desc';
  67. foreach ($this->notifiers as $notifier) {
  68. $notifier->expects($this->once())->method('addMinor')->with($title, $description);
  69. }
  70. $this->notifierPool->addMinor($title, $description);
  71. }
  72. public function testAddNotice()
  73. {
  74. $title = 'title';
  75. $description = 'desc';
  76. foreach ($this->notifiers as $notifier) {
  77. $notifier->expects($this->once())->method('addNotice')->with($title, $description);
  78. }
  79. $this->notifierPool->addNotice($title, $description);
  80. }
  81. }