Fix warnings and errors in integration tests

[PREMIUM-191]
This commit is contained in:
Rostislav Wolny
2023-09-21 20:32:02 +02:00
committed by Jan Jakeš
parent 8eeab7b5cc
commit f56b58a5fe
9 changed files with 52 additions and 62 deletions

View File

@ -401,7 +401,7 @@ class SubscribersTest extends \MailPoetTest {
'segment' => $dynamicSegment->getId(), 'segment' => $dynamicSegment->getId(),
], ],
]); ]);
expect($response->meta['filters']['segment'])->contains(['value' => $dynamicSegment->getId(), 'label' => 'Dynamic (1)']); expect($response->meta['filters']['segment'])->contains(['label' => 'Dynamic (1)', 'value' => $dynamicSegment->getId()]);
$this->tester->deleteWordPressUser($wpUserEmail); $this->tester->deleteWordPressUser($wpUserEmail);
} }

View File

@ -67,8 +67,8 @@ class CustomFieldsTest extends \MailPoetTest {
'type' => 'text', 'type' => 'text',
'params' => [ 'params' => [
'required' => '1', 'required' => '1',
'label' => 'text custom field',
'date_type' => 'year_month_day', 'date_type' => 'year_month_day',
'label' => 'text custom field',
], ],
]); ]);
expect($response)->contains([ expect($response)->contains([

View File

@ -698,8 +698,8 @@ class SubscribersTest extends \MailPoetTest {
'settings' => $this->diContainer->get(SettingsController::class), 'settings' => $this->diContainer->get(SettingsController::class),
'requiredCustomFieldsValidator' => Stub::makeEmpty(RequiredCustomFieldValidator::class, ['validate']), 'requiredCustomFieldsValidator' => Stub::makeEmpty(RequiredCustomFieldValidator::class, ['validate']),
'subscribeToLists' => Expected::once(function ($subscriberId, $segmentsIds, $options) { 'subscribeToLists' => Expected::once(function ($subscriberId, $segmentsIds, $options) {
expect($options)->contains('send_confirmation_email'); expect($options)->hasKey('send_confirmation_email');
expect($options['send_confirmation_email'])->equals(true); expect($options['send_confirmation_email'])->equals(1);
return []; return [];
}), }),
], ],

View File

@ -73,19 +73,18 @@ class MenuTest extends \MailPoetTest {
$wpMock = $this->createMock(WPFunctions::class); $wpMock = $this->createMock(WPFunctions::class);
$wpMock->method('isPluginActive')->willReturn(true); $wpMock->method('isPluginActive')->willReturn(true);
$wpMock->method('addSubmenuPage')->willReturn(true);
$accessControlMock = $this->createMock(AccessControl::class); $accessControlMock = $this->createMock(AccessControl::class);
$accessControlMock->method('validatePermission')->willReturn(true); $accessControlMock->method('validatePermission')->willReturn(true);
$wpMock->expects($this->at(8))->method('addSubmenuPage')->with( $wpMock->expects($this->any())->method('addSubmenuPage')->withConsecutive(
null, [$this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything()],
$this->anything(), [$this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything()],
$this->anything(), [$this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything()],
$this->anything(), [$this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything()],
Menu::AUTOMATIONS_PAGE_SLUG, [$this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything(), $this->anything()],
$this->anything() [null, $this->anything(), $this->anything(), $this->anything(), Menu::AUTOMATIONS_PAGE_SLUG, $this->anything()]
); )->willReturn(true);
$menu = new Menu( $menu = new Menu(
$accessControlMock, $accessControlMock,

View File

@ -69,15 +69,18 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
'token' => 123, 'token' => 123,
]; ];
$matcher = $this->any();
$cronWorkerRunnerMock = $this->createMock(CronWorkerRunner::class); $cronWorkerRunnerMock = $this->createMock(CronWorkerRunner::class);
$cronWorkerRunnerMock $cronWorkerRunnerMock
->expects($this->at(0)) ->expects($matcher)
->method('run') ->method('run')
->willThrowException(new \Exception('Message')); ->willReturnCallback(function () use ($matcher) {
$cronWorkerRunnerMock if ($matcher->getInvocationCount() === 1) {
->expects($this->at(1)) throw new \Exception('Message');
->method('run') } else if ($matcher->getInvocationCount() === 2) {
->willThrowException(new \Exception()); throw new \Exception();
}
});
$daemon = new Daemon($this->cronHelper, $cronWorkerRunnerMock, $this->createWorkersFactoryMock(), $this->diContainer->get(LoggerFactory::class)); $daemon = new Daemon($this->cronHelper, $cronWorkerRunnerMock, $this->createWorkersFactoryMock(), $this->diContainer->get(LoggerFactory::class));
$daemonHttpRunner = $this->make(DaemonHttpRunner::class, [ $daemonHttpRunner = $this->make(DaemonHttpRunner::class, [
@ -213,18 +216,18 @@ class DaemonHttpRunnerTest extends \MailPoetTest {
} }
public function testItUpdatesTimestampsDuringExecution() { public function testItUpdatesTimestampsDuringExecution() {
$matcher = $this->any();
$cronWorkerRunnerMock = $this->createMock(CronWorkerRunner::class); $cronWorkerRunnerMock = $this->createMock(CronWorkerRunner::class);
$cronWorkerRunnerMock $cronWorkerRunnerMock
->expects($this->at(0)) ->expects($matcher)
->method('run') ->method('run')
->willReturnCallback(function () { ->willReturnCallback(function () use ($matcher) {
if ($matcher->getInvocationCount() === 1) {
sleep(2); sleep(2);
} else if ($matcher->getInvocationCount() === 2) {
throw new \Exception();
}
}); });
$cronWorkerRunnerMock
->expects($this->at(1))
->method('run')
->willThrowException(new \Exception());
$daemon = new Daemon($this->cronHelper, $cronWorkerRunnerMock, $this->createWorkersFactoryMock(), $this->diContainer->get(LoggerFactory::class)); $daemon = new Daemon($this->cronHelper, $cronWorkerRunnerMock, $this->createWorkersFactoryMock(), $this->diContainer->get(LoggerFactory::class));
$daemonHttpRunner = $this->make(DaemonHttpRunner::class, [ $daemonHttpRunner = $this->make(DaemonHttpRunner::class, [
'pauseExecution' => null, 'pauseExecution' => null,

View File

@ -41,18 +41,13 @@ class MailerTest extends \MailPoetTest {
$mailerFactoryMock = $this->createMock(MailerFactory::class); $mailerFactoryMock = $this->createMock(MailerFactory::class);
// First call in constructor // First call in constructor
$mailerFactoryMock->expects($this->at(0)) $mailerFactoryMock->expects($this->exactly(2))
->method('buildMailer') ->method('buildMailer')
->willReturn($this->createMock(Mailer::class)); ->withConsecutive(
[$this->anything(), $this->anything(), $this->anything()],
// Second call in custom mailer configuration should be called with sender and reply to from newsletter // Second call in custom mailer configuration should be called with sender and reply to from newsletter
$mailerFactoryMock->expects($this->at(1)) [null, ['name' => 'Sender', 'address' => 'from@example.com'], ['name' => 'Reply-to', 'address' => 'reply-to@example.com']]
->method('buildMailer') )->willReturn($this->createMock(Mailer::class));
->with(
null,
['name' => 'Sender', 'address' => 'from@example.com'],
['name' => 'Reply-to', 'address' => 'reply-to@example.com']
)
->willReturn($this->createMock(Mailer::class));
$mailerTask = new MailerTask($mailerFactoryMock); $mailerTask = new MailerTask($mailerFactoryMock);
$mailerTask->configureMailer($newsletter); $mailerTask->configureMailer($newsletter);
} }

View File

@ -118,15 +118,13 @@ class AutomatedEmailsTest extends \MailPoetTest {
public function testItRenders() { public function testItRenders() {
$this->createNewsletterClicksAndOpens(); $this->createNewsletterClicksAndOpens();
$this->renderer->expects($this->exactly(2))
->method('render');
$this->renderer->expects($this->at(0))
->method('render')
->with($this->equalTo('emails/statsNotificationAutomatedEmails.html'));
$this->renderer->expects($this->at(1)) $this->renderer->expects($this->exactly(2))
->method('render') ->method('render')
->with($this->equalTo('emails/statsNotificationAutomatedEmails.txt')); ->withConsecutive(
['emails/statsNotificationAutomatedEmails.html'],
['emails/statsNotificationAutomatedEmails.txt']
);
$this->mailer->expects($this->once()) $this->mailer->expects($this->once())
->method('send'); ->method('send');

View File

@ -158,16 +158,13 @@ class WorkerTest extends \MailPoetTest {
} }
public function testRendersTemplate() { public function testRendersTemplate() {
$this->renderer->expects($this->exactly(2)) $matcher = $this->exactly(2);
->method('render'); $this->renderer->expects($matcher)
$this->renderer->expects($this->at(0))
->method('render') ->method('render')
->with($this->equalTo('emails/statsNotification.html')); ->withConsecutive(
['emails/statsNotification.html'],
$this->renderer->expects($this->at(1)) ['emails/statsNotification.txt']
->method('render') );
->with($this->equalTo('emails/statsNotification.txt'));
$this->statsNotifications->process(); $this->statsNotifications->process();
} }

View File

@ -301,15 +301,13 @@ class WordpressMailerTest extends \MailPoetTest {
*/ */
public function testItChangesReplyToEmailOnDifferentCalls() { public function testItChangesReplyToEmailOnDifferentCalls() {
$mailerFactory = $this->getMailerFactoryInstanceForReplyToTests(); $mailerFactory = $this->getMailerFactoryInstanceForReplyToTests();
$mailerFactory->expects($this->at(0))
$mailerFactory->expects($this->exactly(2))
->method('buildMailer') ->method('buildMailer')
->with($this->isNull(), $this->isNull(), $this->equalTo([ ->withConsecutive(
'address' => 'reply-to@example.com', [null, null, ['address' => 'reply-to@example.com', 'name' => 'Reply To',]],
'name' => 'Reply To', [null, null, null]
])); );
$mailerFactory->expects($this->at(1))
->method('buildMailer')
->with($this->isNull(), $this->isNull(), $this->isNull());
$wpMailer = new WordPressMailer($mailerFactory, new MetaInfo, $this->subscribersRepository); $wpMailer = new WordPressMailer($mailerFactory, new MetaInfo, $this->subscribersRepository);
$wpMailer->addAddress('email@example.com', 'Full Name'); $wpMailer->addAddress('email@example.com', 'Full Name');