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(' ')); } }