47 lines
1.6 KiB
PHP
47 lines
1.6 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace MintyPHP\Tests\Service\Settings;
|
||
|
|
|
||
|
|
use MintyPHP\Repository\Settings\SettingRepositoryInterface;
|
||
|
|
use MintyPHP\Service\Settings\SettingsMetadataGateway;
|
||
|
|
use MintyPHP\Service\Settings\SettingsSmtpGateway;
|
||
|
|
use PHPUnit\Framework\TestCase;
|
||
|
|
|
||
|
|
class SettingsSmtpGatewayTest extends TestCase
|
||
|
|
{
|
||
|
|
public function testGetSmtpSecureReturnsNullForNone(): void
|
||
|
|
{
|
||
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
||
|
|
$settings->method('getValue')->willReturnCallback(static function (string $key): ?string {
|
||
|
|
if ($key === 'smtp_secure') {
|
||
|
|
return 'none';
|
||
|
|
}
|
||
|
|
return null;
|
||
|
|
});
|
||
|
|
|
||
|
|
$gateway = new SettingsSmtpGateway(new SettingsMetadataGateway($settings));
|
||
|
|
$this->assertNull($gateway->getSmtpSecure());
|
||
|
|
}
|
||
|
|
|
||
|
|
public function testSetSmtpSecureRejectsInvalidValue(): void
|
||
|
|
{
|
||
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
||
|
|
$settings->expects($this->never())->method('set');
|
||
|
|
|
||
|
|
$gateway = new SettingsSmtpGateway(new SettingsMetadataGateway($settings));
|
||
|
|
$this->assertFalse($gateway->setSmtpSecure('starttls'));
|
||
|
|
}
|
||
|
|
|
||
|
|
public function testSetSmtpHostPersistsNullForEmptyString(): void
|
||
|
|
{
|
||
|
|
$settings = $this->createMock(SettingRepositoryInterface::class);
|
||
|
|
$settings->expects($this->once())
|
||
|
|
->method('set')
|
||
|
|
->with('smtp_host', null, 'setting.smtp_host')
|
||
|
|
->willReturn(true);
|
||
|
|
|
||
|
|
$gateway = new SettingsSmtpGateway(new SettingsMetadataGateway($settings));
|
||
|
|
$this->assertTrue($gateway->setSmtpHost(' '));
|
||
|
|
}
|
||
|
|
}
|