diff --git a/mailpoet/tests/integration/API/JSON/v1/SubscribersTest.php b/mailpoet/tests/integration/API/JSON/v1/SubscribersTest.php index 3a49847456..5d3553dbe3 100644 --- a/mailpoet/tests/integration/API/JSON/v1/SubscribersTest.php +++ b/mailpoet/tests/integration/API/JSON/v1/SubscribersTest.php @@ -401,7 +401,7 @@ class SubscribersTest extends \MailPoetTest { '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); } diff --git a/mailpoet/tests/integration/API/MP/CustomFieldsTest.php b/mailpoet/tests/integration/API/MP/CustomFieldsTest.php index ba1b3862fd..0115234155 100644 --- a/mailpoet/tests/integration/API/MP/CustomFieldsTest.php +++ b/mailpoet/tests/integration/API/MP/CustomFieldsTest.php @@ -67,8 +67,8 @@ class CustomFieldsTest extends \MailPoetTest { 'type' => 'text', 'params' => [ 'required' => '1', - 'label' => 'text custom field', 'date_type' => 'year_month_day', + 'label' => 'text custom field', ], ]); expect($response)->contains([ diff --git a/mailpoet/tests/integration/API/MP/SubscribersTest.php b/mailpoet/tests/integration/API/MP/SubscribersTest.php index 7593e0c5a5..da873e9f17 100644 --- a/mailpoet/tests/integration/API/MP/SubscribersTest.php +++ b/mailpoet/tests/integration/API/MP/SubscribersTest.php @@ -698,8 +698,8 @@ class SubscribersTest extends \MailPoetTest { 'settings' => $this->diContainer->get(SettingsController::class), 'requiredCustomFieldsValidator' => Stub::makeEmpty(RequiredCustomFieldValidator::class, ['validate']), 'subscribeToLists' => Expected::once(function ($subscriberId, $segmentsIds, $options) { - expect($options)->contains('send_confirmation_email'); - expect($options['send_confirmation_email'])->equals(true); + expect($options)->hasKey('send_confirmation_email'); + expect($options['send_confirmation_email'])->equals(1); return []; }), ], diff --git a/mailpoet/tests/integration/Config/MenuTest.php b/mailpoet/tests/integration/Config/MenuTest.php index bb22478cc6..dd543f9363 100644 --- a/mailpoet/tests/integration/Config/MenuTest.php +++ b/mailpoet/tests/integration/Config/MenuTest.php @@ -73,19 +73,18 @@ class MenuTest extends \MailPoetTest { $wpMock = $this->createMock(WPFunctions::class); $wpMock->method('isPluginActive')->willReturn(true); - $wpMock->method('addSubmenuPage')->willReturn(true); $accessControlMock = $this->createMock(AccessControl::class); $accessControlMock->method('validatePermission')->willReturn(true); - $wpMock->expects($this->at(8))->method('addSubmenuPage')->with( - null, - $this->anything(), - $this->anything(), - $this->anything(), - Menu::AUTOMATIONS_PAGE_SLUG, - $this->anything() - ); + $wpMock->expects($this->any())->method('addSubmenuPage')->withConsecutive( + [$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(), $this->anything(), $this->anything(), $this->anything()], + [null, $this->anything(), $this->anything(), $this->anything(), Menu::AUTOMATIONS_PAGE_SLUG, $this->anything()] + )->willReturn(true); $menu = new Menu( $accessControlMock, diff --git a/mailpoet/tests/integration/Cron/DaemonHttpRunnerTest.php b/mailpoet/tests/integration/Cron/DaemonHttpRunnerTest.php index a748e2da1f..e5184218bf 100644 --- a/mailpoet/tests/integration/Cron/DaemonHttpRunnerTest.php +++ b/mailpoet/tests/integration/Cron/DaemonHttpRunnerTest.php @@ -69,15 +69,18 @@ class DaemonHttpRunnerTest extends \MailPoetTest { 'token' => 123, ]; + $matcher = $this->any(); $cronWorkerRunnerMock = $this->createMock(CronWorkerRunner::class); $cronWorkerRunnerMock - ->expects($this->at(0)) + ->expects($matcher) ->method('run') - ->willThrowException(new \Exception('Message')); - $cronWorkerRunnerMock - ->expects($this->at(1)) - ->method('run') - ->willThrowException(new \Exception()); + ->willReturnCallback(function () use ($matcher) { + if ($matcher->getInvocationCount() === 1) { + throw new \Exception('Message'); + } else if ($matcher->getInvocationCount() === 2) { + throw new \Exception(); + } + }); $daemon = new Daemon($this->cronHelper, $cronWorkerRunnerMock, $this->createWorkersFactoryMock(), $this->diContainer->get(LoggerFactory::class)); $daemonHttpRunner = $this->make(DaemonHttpRunner::class, [ @@ -213,18 +216,18 @@ class DaemonHttpRunnerTest extends \MailPoetTest { } public function testItUpdatesTimestampsDuringExecution() { + $matcher = $this->any(); $cronWorkerRunnerMock = $this->createMock(CronWorkerRunner::class); $cronWorkerRunnerMock - ->expects($this->at(0)) + ->expects($matcher) ->method('run') - ->willReturnCallback(function () { - sleep(2); + ->willReturnCallback(function () use ($matcher) { + if ($matcher->getInvocationCount() === 1) { + 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)); $daemonHttpRunner = $this->make(DaemonHttpRunner::class, [ 'pauseExecution' => null, diff --git a/mailpoet/tests/integration/Cron/Workers/SendingQueue/Tasks/MailerTest.php b/mailpoet/tests/integration/Cron/Workers/SendingQueue/Tasks/MailerTest.php index 162eb34ede..12f6cb34b9 100644 --- a/mailpoet/tests/integration/Cron/Workers/SendingQueue/Tasks/MailerTest.php +++ b/mailpoet/tests/integration/Cron/Workers/SendingQueue/Tasks/MailerTest.php @@ -41,18 +41,13 @@ class MailerTest extends \MailPoetTest { $mailerFactoryMock = $this->createMock(MailerFactory::class); // First call in constructor - $mailerFactoryMock->expects($this->at(0)) + $mailerFactoryMock->expects($this->exactly(2)) ->method('buildMailer') - ->willReturn($this->createMock(Mailer::class)); - // Second call in custom mailer configuration should be called with sender and reply to from newsletter - $mailerFactoryMock->expects($this->at(1)) - ->method('buildMailer') - ->with( - null, - ['name' => 'Sender', 'address' => 'from@example.com'], - ['name' => 'Reply-to', 'address' => 'reply-to@example.com'] - ) - ->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 + [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->configureMailer($newsletter); } diff --git a/mailpoet/tests/integration/Cron/Workers/StatsNotifications/AutomatedEmailsTest.php b/mailpoet/tests/integration/Cron/Workers/StatsNotifications/AutomatedEmailsTest.php index 3636a9b8b0..05788295e5 100644 --- a/mailpoet/tests/integration/Cron/Workers/StatsNotifications/AutomatedEmailsTest.php +++ b/mailpoet/tests/integration/Cron/Workers/StatsNotifications/AutomatedEmailsTest.php @@ -118,15 +118,13 @@ class AutomatedEmailsTest extends \MailPoetTest { public function testItRenders() { $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') - ->with($this->equalTo('emails/statsNotificationAutomatedEmails.txt')); + ->withConsecutive( + ['emails/statsNotificationAutomatedEmails.html'], + ['emails/statsNotificationAutomatedEmails.txt'] + ); $this->mailer->expects($this->once()) ->method('send'); diff --git a/mailpoet/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php b/mailpoet/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php index 1e81f6ea7c..fb7a0bb62d 100644 --- a/mailpoet/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php +++ b/mailpoet/tests/integration/Cron/Workers/StatsNotifications/WorkerTest.php @@ -158,16 +158,13 @@ class WorkerTest extends \MailPoetTest { } public function testRendersTemplate() { - $this->renderer->expects($this->exactly(2)) - ->method('render'); - $this->renderer->expects($this->at(0)) + $matcher = $this->exactly(2); + $this->renderer->expects($matcher) ->method('render') - ->with($this->equalTo('emails/statsNotification.html')); - - $this->renderer->expects($this->at(1)) - ->method('render') - ->with($this->equalTo('emails/statsNotification.txt')); - + ->withConsecutive( + ['emails/statsNotification.html'], + ['emails/statsNotification.txt'] + ); $this->statsNotifications->process(); } diff --git a/mailpoet/tests/integration/Mailer/WordPress/WordpressMailerTest.php b/mailpoet/tests/integration/Mailer/WordPress/WordpressMailerTest.php index a4d16620f7..740f0164a7 100644 --- a/mailpoet/tests/integration/Mailer/WordPress/WordpressMailerTest.php +++ b/mailpoet/tests/integration/Mailer/WordPress/WordpressMailerTest.php @@ -301,15 +301,13 @@ class WordpressMailerTest extends \MailPoetTest { */ public function testItChangesReplyToEmailOnDifferentCalls() { $mailerFactory = $this->getMailerFactoryInstanceForReplyToTests(); - $mailerFactory->expects($this->at(0)) + + $mailerFactory->expects($this->exactly(2)) ->method('buildMailer') - ->with($this->isNull(), $this->isNull(), $this->equalTo([ - 'address' => 'reply-to@example.com', - 'name' => 'Reply To', - ])); - $mailerFactory->expects($this->at(1)) - ->method('buildMailer') - ->with($this->isNull(), $this->isNull(), $this->isNull()); + ->withConsecutive( + [null, null, ['address' => 'reply-to@example.com', 'name' => 'Reply To',]], + [null, null, null] + ); $wpMailer = new WordPressMailer($mailerFactory, new MetaInfo, $this->subscribersRepository); $wpMailer->addAddress('email@example.com', 'Full Name');