Files
piratepoet/mailpoet/tests/unit/Referrals/ReferralDetectorTest.php
Rodrigo Primo afe378ba22 Replace expect()->equals() with verify()->equals()
codeception/verify 2.1 removed support for expect()->equals() so we need
to replace it with verify()->equals().

[MAILPOET-5664]
2023-10-24 08:58:22 +03:00

71 lines
2.3 KiB
PHP

<?php declare(strict_types = 1);
namespace MailPoet\Referrals;
use MailPoet\Settings\SettingsController;
use MailPoet\WP\Functions as WPFunctions;
use PHPUnit\Framework\MockObject\MockObject;
class ReferralDetectorTest extends \MailPoetUnitTest {
/** @var SettingsController&MockObject */
private $settingsMock;
/** @var WPFunctions&MockObject */
private $wpMock;
public function _before() {
$this->settingsMock = $this->createMock(SettingsController::class);
$this->wpMock = $this->createMock(WPFunctions::class);
if (!defined(ReferralDetector::REFERRAL_CONSTANT_NAME)) {
define(ReferralDetector::REFERRAL_CONSTANT_NAME, 'constant_referral_id');
}
}
public function testItPrefersSettingsValue() {
$this->settingsMock
->expects($this->once())
->method('get')
->willReturn('settings_referral_id');
$this->wpMock
->expects($this->never())
->method('getOption');
$referralDetector = new ReferralDetector($this->wpMock, $this->settingsMock);
verify($referralDetector->detect())->equals('settings_referral_id');
}
public function testItPrefersOptionValueToConstantAndStoresValueToSettings() {
$this->settingsMock
->expects($this->once())
->method('get')
->willReturn(null);
$this->wpMock
->expects($this->once())
->method('getOption')
->willReturn('option_referral_id');
$this->settingsMock
->expects($this->once())
->method('set')
->with(ReferralDetector::REFERRAL_SETTING_NAME, 'option_referral_id');
$referralDetector = new ReferralDetector($this->wpMock, $this->settingsMock);
verify($referralDetector->detect())->equals('option_referral_id');
}
public function testItCanReadConstantAndStoreValueToSettings() {
$this->settingsMock
->expects($this->once())
->method('get')
->willReturn(null);
$this->wpMock
->expects($this->once())
->method('getOption')
->willReturn(null);
$this->settingsMock
->expects($this->once())
->method('set')
->with(ReferralDetector::REFERRAL_SETTING_NAME, 'constant_referral_id');
$referralDetector = new ReferralDetector($this->wpMock, $this->settingsMock);
verify($referralDetector->detect())->equals('constant_referral_id');
}
}