WindowsSmtpConfigTest.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. declare(strict_types=1);
  7. namespace Magento\Email\Test\Unit\Model\Plugin;
  8. use Magento\Email\Model\Plugin\WindowsSmtpConfig;
  9. use Magento\Framework\App\Config\ReinitableConfigInterface;
  10. use Magento\Framework\Mail\TransportInterface;
  11. use Magento\Framework\OsInfo;
  12. use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
  13. /**
  14. * WindowsSmtpConfigTest
  15. */
  16. class WindowsSmtpConfigTest extends \PHPUnit\Framework\TestCase
  17. {
  18. /**
  19. * @var WindowsSmtpConfig
  20. */
  21. private $windowsSmtpConfig;
  22. /**
  23. * @var OsInfo|\PHPUnit_Framework_MockObject_MockObject
  24. */
  25. private $osInfoMock;
  26. /**
  27. * @var ReinitableConfigInterface|\PHPUnit_Framework_MockObject_MockObject
  28. */
  29. private $configMock;
  30. /**
  31. * @var TransportInterface
  32. */
  33. private $transportMock;
  34. /**
  35. * setUp
  36. *
  37. * @return void
  38. */
  39. public function setUp(): void
  40. {
  41. $objectManager = new ObjectManager($this);
  42. $this->osInfoMock = $this->createMock(OsInfo::class);
  43. $this->configMock = $this->createMock(ReinitableConfigInterface::class);
  44. $this->transportMock = $this->createMock(TransportInterface::class);
  45. $this->windowsSmtpConfig = $objectManager->getObject(
  46. WindowsSmtpConfig::class,
  47. [
  48. 'config' => $this->configMock,
  49. 'osInfo' => $this->osInfoMock
  50. ]
  51. );
  52. }
  53. /**
  54. * Test if SMTP settings if windows server
  55. *
  56. * @return void
  57. */
  58. public function testBeforeSendMessageOsWindows(): void
  59. {
  60. $this->osInfoMock->expects($this->once())
  61. ->method('isWindows')
  62. ->willReturn(true);
  63. $this->configMock->expects($this->exactly(2))
  64. ->method('getValue')
  65. ->willReturnMap([
  66. [WindowsSmtpConfig::XML_SMTP_HOST, '127.0.0.1'],
  67. [WindowsSmtpConfig::XML_SMTP_PORT, '80']
  68. ]);
  69. $this->windowsSmtpConfig->beforeSendMessage($this->transportMock);
  70. }
  71. /**
  72. * Test if SMTP settings if not windows server
  73. *
  74. * @return void
  75. */
  76. public function testBeforeSendMessageOsIsWindows(): void
  77. {
  78. $this->osInfoMock->expects($this->once())
  79. ->method('isWindows')
  80. ->willReturn(false);
  81. $this->configMock->expects($this->never())
  82. ->method('getValue');
  83. $this->windowsSmtpConfig->beforeSendMessage($this->transportMock);
  84. }
  85. }