Files
piratepoet/mailpoet/tests/integration/Cron/Workers/SendingQueue/SendingThrottlingHandlerTest.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

57 lines
2.1 KiB
PHP

<?php declare(strict_types = 1);
namespace MailPoet\Test\Cron\Workers;
use MailPoet\Cron\Workers\SendingQueue\SendingThrottlingHandler;
use MailPoet\Settings\SettingsController;
class SendingThrottlingHandlerTest extends \MailPoetTest {
/** @var SendingThrottlingHandler */
private $throttlingHandler;
/** @var SettingsController */
private $settings;
public function _before() {
parent::_before();
$this->throttlingHandler = $this->diContainer->get(SendingThrottlingHandler::class);
$this->settings = $this->diContainer->get(SettingsController::class);
}
public function testItReturnsDefaultBatchSize(): void {
$batchSize = $this->throttlingHandler->getBatchSize();
verify($batchSize)->equals(SendingThrottlingHandler::BATCH_SIZE);
}
public function testItThrottlesBatchSizeToHalf(): void {
$batchSize = $this->throttlingHandler->getBatchSize();
verify($batchSize)->equals(SendingThrottlingHandler::BATCH_SIZE);
verify($this->throttlingHandler->throttleBatchSize())->equals($batchSize / 2);
}
public function testItIncreaseSuccessRequestCountInRow(): void {
$this->throttlingHandler->throttleBatchSize();
$this->throttlingHandler->processSuccess();
$throttlingSettings = $this->settings->get(SendingThrottlingHandler::SETTINGS_KEY);
verify($throttlingSettings['success_count'])->equals(1);
}
public function testItSetsBatchSizeMinimumToOne(): void {
for ($i = 1; $i <= 10; $i++) {
$this->throttlingHandler->throttleBatchSize();
}
verify($this->throttlingHandler->getBatchSize())->equals(1);
}
public function testInIncreasesBatchSizeBack(): void {
$this->settings->set(SendingThrottlingHandler::SETTINGS_KEY, []);
$this->throttlingHandler->throttleBatchSize();
verify($this->throttlingHandler->getBatchSize())->equals(SendingThrottlingHandler::BATCH_SIZE / 2);
for ($i = 1; $i <= SendingThrottlingHandler::SUCCESS_THRESHOLD_TO_INCREASE; $i++) {
$this->throttlingHandler->processSuccess();
}
verify($this->throttlingHandler->getBatchSize())->equals(SendingThrottlingHandler::BATCH_SIZE);
}
}