Skip to content

Commit 3542f0e

Browse files
ENGCOM-3234: Added Unit Test for WindowsSmtpConfig Plugin #18694
- Merge Pull Request #18694 from vasilii-b/magento2:2.3-WindowsSmtpConfigTest - Merged commits: 1. 1872979
2 parents f710f9b + 1872979 commit 3542f0e

File tree

1 file changed

+100
-0
lines changed

1 file changed

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

0 commit comments

Comments
 (0)