diff --git a/mailpoet/tasks/phpstan/phpstan.neon b/mailpoet/tasks/phpstan/phpstan.neon index b9f7ddb13c..ee743b7894 100644 --- a/mailpoet/tasks/phpstan/phpstan.neon +++ b/mailpoet/tasks/phpstan/phpstan.neon @@ -22,6 +22,7 @@ parameters: - vendor/php-stubs/woocommerce-stubs/woocommerce-stubs.php - custom-stubs.php inferPrivatePropertyTypeFromConstructor: true + checkGenericClassInNonGenericObjectType: false parallel: processTimeout: 300.0 maximumNumberOfProcesses: 4 @@ -100,16 +101,19 @@ parameters: reportUnmatchedIgnoredErrors: true dynamicConstantNames: - MAILPOET_PREMIUM_INITIALIZED + - MAILPOET_PREMIUM_VERSION doctrine: objectManagerLoader: create-entity-manager.php # exclude level 6 errors checkMissingIterableValueType: false + treatPhpDocTypesAsCertain: false # We have some incorrect phpdoc types, but I want to address them later excludePaths: analyseAndScan: - ../../lib/Config/PopulatorData/Templates # analysis of templates is extremely slow, let's skip them for now - ../../tests/_support/_generated + - ../../tests/integration/Models # Old models are deprecated and will be removed soon - ../../tests/unit/Entities/SubscriberEntityTest.php - vendor/php-stubs/wordpress-stubs/wordpress-stubs.php # does not yet offer support for PHP 8.1 includes: diff --git a/mailpoet/tests/_support/woo_cot_helper_plugin.php b/mailpoet/tests/_support/woo_cot_helper_plugin.php index 9ed9e4e664..a98b048283 100644 --- a/mailpoet/tests/_support/woo_cot_helper_plugin.php +++ b/mailpoet/tests/_support/woo_cot_helper_plugin.php @@ -40,7 +40,6 @@ function mailpoet_create_cot() { $dataSynchronizer = wc_get_container()->get(DataSynchronizer::class); } catch (\Exception $e) { WP_CLI::error('DataSynchronizer for COT not found. Does installed WooCommerce version support COT? ' . $e->getMessage()); - return; } $dataSynchronizer->create_database_tables(); WP_CLI::success('Database tables for COT feature created.'); diff --git a/mailpoet/tests/acceptance/Newsletters/ReceiveScheduledEmailCest.php b/mailpoet/tests/acceptance/Newsletters/ReceiveScheduledEmailCest.php index a35863042b..b1465a77c9 100644 --- a/mailpoet/tests/acceptance/Newsletters/ReceiveScheduledEmailCest.php +++ b/mailpoet/tests/acceptance/Newsletters/ReceiveScheduledEmailCest.php @@ -23,7 +23,9 @@ class ReceiveScheduledEmailCest { public function receiveScheduledEmail(\AcceptanceTester $i) { $i->wantTo('Receive a scheduled standard newsletter as a subscriber'); $this->settings->withCronTriggerMethod('Action Scheduler'); - $currentDateTime = new \DateTime(strval($i->executeJS('return window.mailpoet_current_date_time'))); + /** @var string $value - for PHPStan because strval() doesn't accept a value of mixed */ + $value = $i->executeJS('return window.mailpoet_current_date_time'); + $currentDateTime = new \DateTime(strval($value)); $newsletterTitle = 'Scheduled Test Newsletter'; $standardTemplate = '[data-automation-id="select_template_0"]'; diff --git a/mailpoet/tests/acceptance/Newsletters/ScheduleNewsletterCest.php b/mailpoet/tests/acceptance/Newsletters/ScheduleNewsletterCest.php index e2f657de71..17c923d136 100644 --- a/mailpoet/tests/acceptance/Newsletters/ScheduleNewsletterCest.php +++ b/mailpoet/tests/acceptance/Newsletters/ScheduleNewsletterCest.php @@ -44,7 +44,9 @@ class ScheduleNewsletterCest { $newsletter = $newsletterFactory->withSubject($newsletterTitle) ->create(); $segmentName = $i->createListWithSubscriber(); - $currentDateTime = new \DateTime(strval($i->executeJS('return window.mailpoet_current_date_time'))); + /** @var string $value - for PHPStan because strval() doesn't accept a value of mixed */ + $value = $i->executeJS('return window.mailpoet_current_date_time'); + $currentDateTime = new \DateTime(strval($value)); // step 2 - Go to newsletter send page $i->login(); diff --git a/mailpoet/tests/acceptance/Subscribers/SubscriberCookieCest.php b/mailpoet/tests/acceptance/Subscribers/SubscriberCookieCest.php index f653db33b3..413bd1057c 100644 --- a/mailpoet/tests/acceptance/Subscribers/SubscriberCookieCest.php +++ b/mailpoet/tests/acceptance/Subscribers/SubscriberCookieCest.php @@ -53,7 +53,9 @@ class SubscriberCookieCest { $i->click(Locator::contains('a', 'wp-activate.php')); $i->switchToNextTab(); $i->waitForText('Your account is now active'); - $password = str_replace([' ', 'Password:'], '', strval($i->grabTextFrom("//div[@id='signup-welcome'] /p[2]"))); + /** @var string $text - for PHPStan because strval() doesn't accept a value of mixed */ + $text = $i->grabTextFrom("//div[@id='signup-welcome'] /p[2]"); + $password = str_replace([' ', 'Password:'], '', strval($text)); $i->click('Log in'); $i->wait(1);// this needs to be here, Username is not filled properly without this line $i->fillField('Username', 'mutestuser'); diff --git a/mailpoet/tests/integration/API/JSON/ResponseBuilders/SubscribersResponseBuilderTest.php b/mailpoet/tests/integration/API/JSON/ResponseBuilders/SubscribersResponseBuilderTest.php index 016cc708d4..ceb1419f03 100644 --- a/mailpoet/tests/integration/API/JSON/ResponseBuilders/SubscribersResponseBuilderTest.php +++ b/mailpoet/tests/integration/API/JSON/ResponseBuilders/SubscribersResponseBuilderTest.php @@ -100,6 +100,7 @@ class SubscribersResponseBuilderTest extends \MailPoetTest { $this->assertCount(2, $response); foreach ($subscribers as $key => $subscriber) { + /** @var array $item - for PHPStan */ $item = $response[$key]; $this->assertEquals($subscriber->getId(), $item['id']); $this->assertEquals($subscriber->getFirstName(), $item['first_name']); diff --git a/mailpoet/tests/integration/API/JSON/v1/SubscribersTest.php b/mailpoet/tests/integration/API/JSON/v1/SubscribersTest.php index 2bad1a85d4..85de95d3b3 100644 --- a/mailpoet/tests/integration/API/JSON/v1/SubscribersTest.php +++ b/mailpoet/tests/integration/API/JSON/v1/SubscribersTest.php @@ -313,7 +313,8 @@ class SubscribersTest extends \MailPoetTest { verify($response->data)->equals( $this->responseBuilder->build($this->subscriber2) ); - verify($this->subscriber2->getSubscriberSegments()->filter(function (SubscriberSegmentEntity $subscriberSegment) { + verify($this->subscriber2->getSubscriberSegments()->filter(function (SubscriberSegmentEntity $subscriberSegment = null) { + if (!$subscriberSegment) return false; return $subscriberSegment->getStatus() === SubscriberEntity::STATUS_SUBSCRIBED; })->count())->equals(0); } diff --git a/mailpoet/tests/integration/Automation/Engine/Control/StepHandlerTest.php b/mailpoet/tests/integration/Automation/Engine/Control/StepHandlerTest.php index 671a4b8c88..1fc0b8def1 100644 --- a/mailpoet/tests/integration/Automation/Engine/Control/StepHandlerTest.php +++ b/mailpoet/tests/integration/Automation/Engine/Control/StepHandlerTest.php @@ -55,7 +55,9 @@ class StepHandlerTest extends \MailPoetTest { // run step $stepHandler = $this->getServiceWithOverrides(StepHandler::class, ['registry' => $registry]); $automation = $this->createAutomation(); + $this->assertInstanceOf(Automation::class, $automation); $run = $this->tester->createAutomationRun($automation); + $this->assertInstanceOf(AutomationRun::class, $run); $stepHandler->handle(['automation_run_id' => $run->getId(), 'step_id' => 'a1', 'run_number' => 1]); } @@ -68,7 +70,9 @@ class StepHandlerTest extends \MailPoetTest { $stepHandler = $this->getServiceWithOverrides(StepHandler::class, ['registry' => $registry]); $automation = $this->createAutomation(); + $this->assertInstanceOf(Automation::class, $automation); $run = $this->tester->createAutomationRun($automation); + $this->assertInstanceOf(AutomationRun::class, $run); // create start log and modify "updated_at" to an older date $oldDate = new DateTimeImmutable('2000-01-01 00:00:00'); @@ -100,7 +104,9 @@ class StepHandlerTest extends \MailPoetTest { $stepHandler = $this->getServiceWithOverrides(StepHandler::class, ['registry' => $registry]); $automation = $this->createAutomation(); + $this->assertInstanceOf(Automation::class, $automation); $run = $this->tester->createAutomationRun($automation); + $this->assertInstanceOf(AutomationRun::class, $run); // create start log and modify "updated_at" to an older date $oldDate = new DateTimeImmutable('2000-01-01 00:00:00'); diff --git a/mailpoet/tests/integration/Automation/Engine/Control/StepRunLoggerTest.php b/mailpoet/tests/integration/Automation/Engine/Control/StepRunLoggerTest.php index c08ab5431b..5405b2c443 100644 --- a/mailpoet/tests/integration/Automation/Engine/Control/StepRunLoggerTest.php +++ b/mailpoet/tests/integration/Automation/Engine/Control/StepRunLoggerTest.php @@ -126,15 +126,13 @@ class StepRunLoggerTest extends MailPoetTest { $logger->logSuccess(); - /** @var int $runs PHPStan thinks $runs === 0 from the previous assert */ - $this->assertSame(1, $runs); + $this->assertSame(1, $runs); // @phpstan-ignore-line - PHPStan thinks $runs === 0 from the previous assert $this->assertNotNull($lastLog); $this->assertLogData($lastLog, ['step_key' => 'step-key', 'status' => 'complete', 'data' => '{"test":"value"}']); $error = new Exception('test error'); $logger->logFailure($error); - /** @var int $runs PHPStan thinks $runs === 1 from the previous assert */ $this->assertSame(2, $runs); $this->assertNotNull($lastLog); $this->assertLogData($lastLog, ['step_key' => 'step-key', 'status' => 'failed', 'data' => '{"test":"value"}', 'error' => $error]); @@ -159,8 +157,7 @@ class StepRunLoggerTest extends MailPoetTest { $logger->logSuccess(); - /** @var int $runs PHPStan thinks $runs === 0 from the previous assert */ - $this->assertSame(1, $runs); + $this->assertSame(1, $runs); // @phpstan-ignore-line - PHPStan thinks $runs === 0 from the previous assert $logs = $this->storage->getLogsForAutomationRun(1); $this->assertCount(1, $logs); diff --git a/mailpoet/tests/integration/Automation/Engine/Control/StepSchedulerTest.php b/mailpoet/tests/integration/Automation/Engine/Control/StepSchedulerTest.php index 61a34ee326..5cb3db027c 100644 --- a/mailpoet/tests/integration/Automation/Engine/Control/StepSchedulerTest.php +++ b/mailpoet/tests/integration/Automation/Engine/Control/StepSchedulerTest.php @@ -7,6 +7,8 @@ use ActionScheduler_SimpleSchedule; use ActionScheduler_Store; use DateTimeImmutable; use MailPoet\Automation\Engine\Control\StepScheduler; +use MailPoet\Automation\Engine\Data\Automation; +use MailPoet\Automation\Engine\Data\AutomationRun; use MailPoet\Automation\Engine\Data\NextStep; use MailPoet\Automation\Engine\Data\Step; use MailPoet\Automation\Engine\Data\StepRunArgs; @@ -141,7 +143,9 @@ class StepSchedulerTest extends MailPoetTest { new Step('a1', Step::TYPE_ACTION, 'test:action', [], [new NextStep('a2')]), new Step('a2', Step::TYPE_ACTION, 'test:action', [], []) ); + $this->assertInstanceOf(Automation::class, $automation); $run = $this->tester->createAutomationRun($automation); + $this->assertInstanceOf(AutomationRun::class, $run); return new StepRunArgs($automation, $run, $automation->getSteps()['a1'], [], 1); } diff --git a/mailpoet/tests/integration/Automation/Engine/Control/TriggerHandlerTest.php b/mailpoet/tests/integration/Automation/Engine/Control/TriggerHandlerTest.php index 7f5da35678..18955ef94b 100644 --- a/mailpoet/tests/integration/Automation/Engine/Control/TriggerHandlerTest.php +++ b/mailpoet/tests/integration/Automation/Engine/Control/TriggerHandlerTest.php @@ -205,7 +205,9 @@ class TriggerHandlerTest extends \MailPoetTest { public function testItLogs(): void { $trigger = $this->diContainer->get(SomeoneSubscribesTrigger::class); $automation1 = $this->tester->createAutomation('Test 1', new Step('trigger-1', Step::TYPE_TRIGGER, $trigger->getKey(), [], [])); + $this->assertInstanceOf(Automation::class, $automation1); $automation2 = $this->tester->createAutomation('Test 2', new Step('trigger-2', Step::TYPE_TRIGGER, $trigger->getKey(), [], [])); + $this->assertInstanceOf(Automation::class, $automation2); $segmentSubject = new Subject(SegmentSubject::KEY, ['segment_id' => $this->segments['segment_1']->getId()]); $this->testee->processTrigger($trigger, [$segmentSubject]); diff --git a/mailpoet/tests/integration/Automation/Engine/Data/AutomationTest.php b/mailpoet/tests/integration/Automation/Engine/Data/AutomationTest.php index 8900603c79..0598717970 100644 --- a/mailpoet/tests/integration/Automation/Engine/Data/AutomationTest.php +++ b/mailpoet/tests/integration/Automation/Engine/Data/AutomationTest.php @@ -16,6 +16,7 @@ class AutomationTest extends \MailPoetTest { public function testMetaDataIsStored() { $automation = $this->tester->createAutomation('test'); + $this->assertInstanceOf(Automation::class, $automation); $automation->setMeta('foo', 'bar'); $this->assertEquals('bar', $automation->getMeta('foo')); @@ -30,6 +31,7 @@ class AutomationTest extends \MailPoetTest { public function testMetaDataIsDeleted() { $automation = $this->tester->createAutomation('test'); + $this->assertInstanceOf(Automation::class, $automation); $automation->setMeta('foo', 'bar'); $automation->deleteMeta('foo'); @@ -47,6 +49,8 @@ class AutomationTest extends \MailPoetTest { public function testAutomationComparisonWorks() { $automation = $this->tester->createAutomation('test'); + $this->assertInstanceOf(Automation::class, $automation); + $automation2 = clone $automation; $automation2->setMeta('foo', 'bar'); $this->assertFalse($automation->equals($automation2)); @@ -59,6 +63,7 @@ class AutomationTest extends \MailPoetTest { */ public function testFullValidationWorks($status, $expected) { $automation = $this->tester->createAutomation('test'); + $this->assertInstanceOf(Automation::class, $automation); $automation->setStatus($status); $this->assertEquals($expected, $automation->needsFullValidation()); } diff --git a/mailpoet/tests/integration/Automation/Engine/Storage/AutomationStatisticsStorageTest.php b/mailpoet/tests/integration/Automation/Engine/Storage/AutomationStatisticsStorageTest.php index 7be81788e4..ea9ff3fbde 100644 --- a/mailpoet/tests/integration/Automation/Engine/Storage/AutomationStatisticsStorageTest.php +++ b/mailpoet/tests/integration/Automation/Engine/Storage/AutomationStatisticsStorageTest.php @@ -28,11 +28,11 @@ class AutomationStatisticsStorageTest extends \MailPoetTest { $this->automationRunStorage = $this->diContainer->get(AutomationRunStorage::class); $this->testee = $this->diContainer->get(AutomationStatisticsStorage::class); - $this->automations = [ - $this->tester->createAutomation('1')->getId(), - $this->tester->createAutomation('2')->getId(), - $this->tester->createAutomation('3')->getId(), - ]; + for ($i = 1; $i <= 3; $i++) { + $automation = $this->tester->createAutomation((string)$i); + $this->assertInstanceOf(Automation::class, $automation); + $this->automations[] = $automation->getId(); + } } /** diff --git a/mailpoet/tests/integration/Automation/Integrations/MailPoet/Actions/SendEmailActionTest.php b/mailpoet/tests/integration/Automation/Integrations/MailPoet/Actions/SendEmailActionTest.php index 183213e163..85511974a7 100644 --- a/mailpoet/tests/integration/Automation/Integrations/MailPoet/Actions/SendEmailActionTest.php +++ b/mailpoet/tests/integration/Automation/Integrations/MailPoet/Actions/SendEmailActionTest.php @@ -334,13 +334,6 @@ class SendEmailActionTest extends \MailPoetTest { ]; } - private function getSubjects(): array { - return [ - $this->segmentSubject, - $this->subscriberSubject, - ]; - } - private function getSubjectData(SubscriberEntity $subscriber, SegmentEntity $segment): array { return [ new Subject('mailpoet:segment', ['segment_id' => $segment->getId()]), diff --git a/mailpoet/tests/integration/Automation/Integrations/MailPoet/Analytics/Controller/AutomationTimeSpanControllerTest.php b/mailpoet/tests/integration/Automation/Integrations/MailPoet/Analytics/Controller/AutomationTimeSpanControllerTest.php index a3b65ba33c..094de592d1 100644 --- a/mailpoet/tests/integration/Automation/Integrations/MailPoet/Analytics/Controller/AutomationTimeSpanControllerTest.php +++ b/mailpoet/tests/integration/Automation/Integrations/MailPoet/Analytics/Controller/AutomationTimeSpanControllerTest.php @@ -30,6 +30,7 @@ class AutomationTimeSpanControllerTest extends \MailPoetTest { public function testItReturnsNoEmailWhenNoEmailStepExist() { $automation = $this->tester->createAutomation('test'); + $this->assertInstanceOf(Automation::class, $automation); $this->createEmail(); $emails = $this->testee->getEmailsFromAutomations([$automation]); $this->assertEmpty($emails); @@ -66,6 +67,7 @@ class AutomationTimeSpanControllerTest extends \MailPoetTest { [] ); $automation = $this->tester->createAutomation('test', $trigger, $firstEmail, $secondEmail); + $this->assertInstanceOf(Automation::class, $automation); $emails = $this->testee->getEmailsFromAutomations([$automation]); $this->assertCount(2, $emails); @@ -81,6 +83,7 @@ class AutomationTimeSpanControllerTest extends \MailPoetTest { $after = new \DateTimeImmutable('2022-01-01 00:00:00'); $before = new \DateTimeImmutable('2022-02-02 00:00:00'); $automation = $this->tester->createAutomation('test'); + $this->assertInstanceOf(Automation::class, $automation); $emailBefore = $this->createEmail('emailBefore'); $emailInTimeSpan = $this->createEmail('emailInTimeSpan'); $emailInTimeSpan2 = $this->createEmail('emailInTimeSpan2'); diff --git a/mailpoet/tests/integration/Automation/Integrations/MailPoet/Fields/SubscriberAutomationFieldsFactoryTest.php b/mailpoet/tests/integration/Automation/Integrations/MailPoet/Fields/SubscriberAutomationFieldsFactoryTest.php index cc828a8365..c2a88759d5 100644 --- a/mailpoet/tests/integration/Automation/Integrations/MailPoet/Fields/SubscriberAutomationFieldsFactoryTest.php +++ b/mailpoet/tests/integration/Automation/Integrations/MailPoet/Fields/SubscriberAutomationFieldsFactoryTest.php @@ -71,6 +71,7 @@ class SubscriberAutomationFieldsFactoryTest extends MailPoetTest { private function createAutomation(string $name, string $status): Automation { $automation = $this->tester->createAutomation($name); + $this->assertInstanceOf(Automation::class, $automation); $automation->setStatus($status); $this->diContainer->get(AutomationStorage::class)->updateAutomation($automation); return $automation; @@ -78,6 +79,7 @@ class SubscriberAutomationFieldsFactoryTest extends MailPoetTest { private function createAutomationRun(Automation $automation, string $status, array $subjects): AutomationRun { $run = $this->tester->createAutomationRun($automation, $subjects); + $this->assertInstanceOf(AutomationRun::class, $run); $this->diContainer->get(AutomationRunStorage::class)->updateStatus($run->getId(), $status); return $run; } diff --git a/mailpoet/tests/integration/Config/ShortcodesTest.php b/mailpoet/tests/integration/Config/ShortcodesTest.php index fe337bb72b..eb036f0b08 100644 --- a/mailpoet/tests/integration/Config/ShortcodesTest.php +++ b/mailpoet/tests/integration/Config/ShortcodesTest.php @@ -6,6 +6,7 @@ use Helper\WordPress; use MailPoet\DI\ContainerWrapper; use MailPoet\Entities\NewsletterEntity; use MailPoet\Entities\SendingQueueEntity; +use MailPoet\Entities\SubscriberEntity; use MailPoet\Newsletter\Url; use MailPoet\Router\Router; use MailPoet\Subscribers\SubscribersRepository; @@ -52,6 +53,7 @@ class ShortcodesTest extends \MailPoetTest { $this->queue = $this->newsletter->getLatestQueue(); $shortcodes = ContainerWrapper::getInstance()->get(Shortcodes::class); WordPress::interceptFunction('apply_filters', function() use($shortcodes) { + /** @var array{0: string, 1:NewsletterEntity, 2:SubscriberEntity|null, 3:SendingQueueEntity|null} $args */ $args = func_get_args(); $filterName = array_shift($args); switch ($filterName) { @@ -243,6 +245,7 @@ class ShortcodesTest extends \MailPoetTest { $this->entityManager->flush(); WordPress::interceptFunction('apply_filters', function() use($shortcodes) { + /** @var array{0: string, 1:NewsletterEntity, 2:SubscriberEntity|null, 3:SendingQueueEntity|null} $args */ $args = func_get_args(); $filterName = array_shift($args); switch ($filterName) { @@ -285,6 +288,7 @@ class ShortcodesTest extends \MailPoetTest { $this->entityManager->flush(); WordPress::interceptFunction('apply_filters', function() use($shortcodes) { + /** @var array{0: string, 1:NewsletterEntity, 2:SubscriberEntity|null, 3:SendingQueueEntity|null} $args */ $args = func_get_args(); $filterName = array_shift($args); switch ($filterName) { diff --git a/mailpoet/tests/integration/Cron/Workers/SendingQueue/SendingQueueTest.php b/mailpoet/tests/integration/Cron/Workers/SendingQueue/SendingQueueTest.php index abcb84f15b..d618057b1f 100644 --- a/mailpoet/tests/integration/Cron/Workers/SendingQueue/SendingQueueTest.php +++ b/mailpoet/tests/integration/Cron/Workers/SendingQueue/SendingQueueTest.php @@ -107,20 +107,28 @@ class SendingQueueTest extends \MailPoetTest { $populator->up(); $this->wp = $this->diContainer->get(WPFunctions::class); $this->subscriber = $this->createSubscriber('john@doe.com', 'John', 'Doe'); - $this->segment = Segment::create(); + /** @var Segment $segment */ + $segment = Segment::create(); + $this->segment = $segment; $this->segment->name = 'segment'; $this->segment->save(); - $this->subscriberSegment = SubscriberSegment::create(); + /** @var SubscriberSegment $subscriberSegment */ + $subscriberSegment = SubscriberSegment::create(); + $this->subscriberSegment = $subscriberSegment; $this->subscriberSegment->subscriberId = (int)$this->subscriber->getId(); $this->subscriberSegment->segmentId = (int)$this->segment->id; $this->subscriberSegment->save(); - $this->newsletter = Newsletter::create(); + /** @var Newsletter $newsletter */ + $newsletter = Newsletter::create(); + $this->newsletter = $newsletter; $this->newsletter->type = Newsletter::TYPE_STANDARD; $this->newsletter->status = Newsletter::STATUS_ACTIVE; $this->newsletter->subject = Fixtures::get('newsletter_subject_template'); $this->newsletter->body = Fixtures::get('newsletter_body_template'); $this->newsletter->save(); - $this->newsletterSegment = NewsletterSegment::create(); + /** @var NewsletterSegment $newsletterSegment */ + $newsletterSegment = NewsletterSegment::create(); + $this->newsletterSegment = $newsletterSegment; $this->newsletterSegment->newsletterId = $this->newsletter->id; $this->newsletterSegment->segmentId = (int)$this->segment->id; $this->newsletterSegment->save(); @@ -1311,6 +1319,7 @@ class SendingQueueTest extends \MailPoetTest { public function testCampaignIdsAreTheSameForDifferentSubscribers() { $mailerTaskCampaignIds = []; $secondSubscriber = $this->createSubscriber('sub2@example.com', 'Subscriber', 'Two'); + /** @var SubscriberSegment $segment2 */ $segment2 = SubscriberSegment::create(); $segment2->subscriberId = (int)$secondSubscriber->getId(); $segment2->segmentId = (int)$this->segment->id; diff --git a/mailpoet/tests/integration/Cron/Workers/SendingQueue/Tasks/MailerTest.php b/mailpoet/tests/integration/Cron/Workers/SendingQueue/Tasks/MailerTest.php index 2b07cf86ad..978848deed 100644 --- a/mailpoet/tests/integration/Cron/Workers/SendingQueue/Tasks/MailerTest.php +++ b/mailpoet/tests/integration/Cron/Workers/SendingQueue/Tasks/MailerTest.php @@ -90,6 +90,7 @@ class MailerTest extends \MailPoetTest { } public function testItCanPrepareSubscriberForSending() { + /** @var Subscriber $subscriber */ $subscriber = Subscriber::create(); $subscriber->email = 'test@example.com'; $subscriber->firstName = 'John'; diff --git a/mailpoet/tests/integration/Migrator/StoreTest.php b/mailpoet/tests/integration/Migrator/StoreTest.php index 8411d298a0..1165b02538 100644 --- a/mailpoet/tests/integration/Migrator/StoreTest.php +++ b/mailpoet/tests/integration/Migrator/StoreTest.php @@ -45,6 +45,7 @@ class StoreTest extends MailPoetTest { $migrations = $this->connection->executeQuery("SELECT * FROM {$this->table}")->fetchAllAssociative(); $this->assertCount(1, $migrations); + /** @var array{name:string, started_at:string, completed_at:string|null, error:string|null} $data */ $data = $migrations[0]; $this->assertSame('TestingMigration', $data['name']); $this->assertStringMatchesFormat(self::DATE_TIME_FORMAT, strval($data['started_at'])); @@ -60,6 +61,7 @@ class StoreTest extends MailPoetTest { $migrations = $this->connection->executeQuery("SELECT * FROM {$this->table}")->fetchAllAssociative(); $this->assertCount(1, $migrations); + /** @var array{name:string, started_at:string, completed_at:string|null, error:string|null} $data */ $data = $migrations[0]; $this->assertSame('TestingMigration', $data['name']); $this->assertStringMatchesFormat(self::DATE_TIME_FORMAT, strval($data['started_at'])); @@ -75,6 +77,7 @@ class StoreTest extends MailPoetTest { $migrations = $this->connection->executeQuery("SELECT * FROM {$this->table}")->fetchAllAssociative(); $this->assertCount(1, $migrations); + /** @var array{name:string, started_at:string, completed_at:string|null, error:string|null} $data */ $data = $migrations[0]; $this->assertSame('TestingMigration', $data['name']); $this->assertStringMatchesFormat(self::DATE_TIME_FORMAT, strval($data['started_at'])); diff --git a/mailpoet/tests/integration/Newsletter/NewsletterSaveControllerTest.php b/mailpoet/tests/integration/Newsletter/NewsletterSaveControllerTest.php index 58f1f52a76..558d7ee8fa 100644 --- a/mailpoet/tests/integration/Newsletter/NewsletterSaveControllerTest.php +++ b/mailpoet/tests/integration/Newsletter/NewsletterSaveControllerTest.php @@ -111,7 +111,8 @@ class NewsletterSaveControllerTest extends \MailPoetTest { ], ]; $newsletter = $this->saveController->save($newsletterData); - $scheduleOption = $newsletter->getOptions()->filter(function (NewsletterOptionEntity $newsletterOption) { + $scheduleOption = $newsletter->getOptions()->filter(function (NewsletterOptionEntity $newsletterOption = null) { + if ($newsletterOption === null) return false; // PHPStan $optionField = $newsletterOption->getOptionField(); return $optionField && $optionField->getName() === 'schedule'; })->first(); @@ -123,7 +124,8 @@ class NewsletterSaveControllerTest extends \MailPoetTest { $newsletterData['options']['intervalType'] = PostNotificationScheduler::INTERVAL_IMMEDIATELY; $savedNewsletter = $this->saveController->save($newsletterData); - $scheduleOption = $savedNewsletter->getOptions()->filter(function (NewsletterOptionEntity $newsletterOption) { + $scheduleOption = $savedNewsletter->getOptions()->filter(function (NewsletterOptionEntity $newsletterOption = null) { + if ($newsletterOption === null) return false; // PHPStan $optionField = $newsletterOption->getOptionField(); return $optionField && $optionField->getName() === 'schedule'; })->first(); @@ -166,7 +168,8 @@ class NewsletterSaveControllerTest extends \MailPoetTest { ]; $newsletter = $this->saveController->save($newsletterData); - $scheduleOption = $newsletter->getOptions()->filter(function (NewsletterOptionEntity $newsletterOption) { + $scheduleOption = $newsletter->getOptions()->filter(function (NewsletterOptionEntity $newsletterOption = null) { + if ($newsletterOption === null) return false; // PHPStan $optionField = $newsletterOption->getOptionField(); return $optionField && $optionField->getName() === 'schedule'; })->first(); diff --git a/mailpoet/tests/integration/Newsletter/ShortcodesTest.php b/mailpoet/tests/integration/Newsletter/ShortcodesTest.php index 4fc7410d50..b14d988396 100644 --- a/mailpoet/tests/integration/Newsletter/ShortcodesTest.php +++ b/mailpoet/tests/integration/Newsletter/ShortcodesTest.php @@ -315,6 +315,7 @@ class ShortcodesTest extends \MailPoetTest { $parsedUrlQuery = parse_url($link, PHP_URL_QUERY); $queryData = []; parse_str((string)$parsedUrlQuery, $queryData); + $queryData['data'] = is_string($queryData['data']) ? $queryData['data'] : implode('', $queryData['data']); return $this->newsletterUrl->transformUrlDataObject(json_decode(base64_decode($queryData['data']), true)); } @@ -421,8 +422,12 @@ class ShortcodesTest extends \MailPoetTest { } public function testItCanProcessSiteHomepageLinkShortcode() { - $siteUrl = strval(get_option('home')); - $siteName = strval(get_option('blogname')); + /** @var string $home */ + $home = get_option('home'); + $siteUrl = strval($home); + /** @var string $blogName */ + $blogName = get_option('blogname'); + $siteName = strval($blogName); $shortcode = '[site:homepage_link]'; $shortcodesObject = $this->shortcodesObject; diff --git a/mailpoet/tests/integration/Services/BridgeTest.php b/mailpoet/tests/integration/Services/BridgeTest.php index a0aeb660d0..06fe7f2126 100644 --- a/mailpoet/tests/integration/Services/BridgeTest.php +++ b/mailpoet/tests/integration/Services/BridgeTest.php @@ -236,6 +236,7 @@ class BridgeTest extends \MailPoetTest { } public function testItAllowsChangingRequestTimeout() { + /** @var array $wpRemotePostArgs */ $wpRemotePostArgs = []; $wp = Stub::make(new WPFunctions, [ 'wpRemotePost' => function() use (&$wpRemotePostArgs) { diff --git a/mailpoet/tests/integration/Subscribers/InactiveSubscribersControllerTest.php b/mailpoet/tests/integration/Subscribers/InactiveSubscribersControllerTest.php index 27e405ad4c..02459acfa7 100644 --- a/mailpoet/tests/integration/Subscribers/InactiveSubscribersControllerTest.php +++ b/mailpoet/tests/integration/Subscribers/InactiveSubscribersControllerTest.php @@ -7,7 +7,6 @@ use MailPoet\Entities\NewsletterEntity; use MailPoet\Entities\ScheduledTaskEntity; use MailPoet\Entities\ScheduledTaskSubscriberEntity; use MailPoet\Entities\SendingQueueEntity; -use MailPoet\Entities\SettingEntity; use MailPoet\Entities\StatisticsOpenEntity; use MailPoet\Entities\SubscriberEntity; use MailPoetVendor\Carbon\Carbon; @@ -296,17 +295,4 @@ class InactiveSubscribersControllerTest extends \MailPoetTest { $this->entityManager->flush(); return $opened; } - - private function createSetting($name, $value, $createdAt) { - $tableName = $this->entityManager->getClassMetadata(SettingEntity::class)->getTableName(); - $this->connection->executeStatement( - "INSERT INTO $tableName (name, value, created_at) VALUES (?, ?, ?)", - [$name, $value, $createdAt] - ); - } - - private function removeSetting($name) { - $tableName = $this->entityManager->getClassMetadata(SettingEntity::class)->getTableName(); - $this->connection->executeStatement("DELETE FROM $tableName WHERE name = ?", [$name]); - } } diff --git a/mailpoet/tests/integration/Tasks/SendingTest.php b/mailpoet/tests/integration/Tasks/SendingTest.php index 4fe181f997..9b13b7a207 100644 --- a/mailpoet/tests/integration/Tasks/SendingTest.php +++ b/mailpoet/tests/integration/Tasks/SendingTest.php @@ -316,6 +316,7 @@ class SendingTest extends \MailPoetTest { } public function createNewScheduledTask() { + /** @var ScheduledTask $task - for PHPStan */ $task = ScheduledTask::create(); $task->type = SendingQueueWorker::TASK_TYPE; return $task->save(); @@ -325,6 +326,7 @@ class SendingTest extends \MailPoetTest { $newsletter = isset($args['newsletter']) ? $args['newsletter'] : $this->newsletterFactory->create(); $task = isset($args['task']) ? $args['task'] : $this->createNewScheduledTask(); + /** @var SendingQueue $queue - for PHPStan */ $queue = SendingQueue::create(); $queue->newsletterId = $newsletter->getId(); $queue->taskId = $task->id; diff --git a/mailpoet/tests/integration/WooCommerce/TransactionalEmails/RendererTest.php b/mailpoet/tests/integration/WooCommerce/TransactionalEmails/RendererTest.php index ce58ea0c59..81e7302910 100644 --- a/mailpoet/tests/integration/WooCommerce/TransactionalEmails/RendererTest.php +++ b/mailpoet/tests/integration/WooCommerce/TransactionalEmails/RendererTest.php @@ -117,10 +117,13 @@ class RendererTest extends \MailPoetTest { $renderer->render($this->newsletter, 'Heading Text'); $html = $renderer->getHTMLAfterContent(); - $siteName = strval(get_option('blogname')); + /** @var string $blogName - for PHPStan */ + $blogName = get_option('blogname'); + $siteName = strval($blogName); verify($html)->stringContainsString($siteName); // [site:title] - - $siteUrl = strval(get_option('home')); + /** @var string $home - for PHPStan */ + $home = get_option('home'); + $siteUrl = strval($home); verify($html)->stringContainsString($siteUrl); // [site:homepage_url] verify($html)->stringContainsString(date_i18n('F', WPFunctions::get()->currentTime('timestamp'))); // [date:mtext] diff --git a/mailpoet/tests/integration/_bootstrap.php b/mailpoet/tests/integration/_bootstrap.php index ffdeedaa81..5388cc5848 100644 --- a/mailpoet/tests/integration/_bootstrap.php +++ b/mailpoet/tests/integration/_bootstrap.php @@ -162,6 +162,9 @@ abstract class MailPoetTest extends \Codeception\TestCase\Test { // phpcs:ignore return Stub::copy($instance, $overrides); } + /** + * @param class-string $entityName + */ public function truncateEntity(string $entityName) { $classMetadata = $this->entityManager->getClassMetadata($entityName); $tableName = $classMetadata->getTableName(); @@ -177,6 +180,7 @@ abstract class MailPoetTest extends \Codeception\TestCase\Test { // phpcs:ignore * so it is not possible to set it manually using a setter. */ public function setUpdatedAtForEntity($entity, DateTimeInterface $updatedAt) { + /** @var class-string $className */ $className = (string)get_class($entity); $classMetadata = $this->entityManager->getClassMetadata($className); if (!$classMetadata instanceof ClassMetadata) { diff --git a/mailpoet/tests/unit/WooCommerce/CouponPreProcessorTest.php b/mailpoet/tests/unit/WooCommerce/CouponPreProcessorTest.php index 951214d5af..4789e7f933 100644 --- a/mailpoet/tests/unit/WooCommerce/CouponPreProcessorTest.php +++ b/mailpoet/tests/unit/WooCommerce/CouponPreProcessorTest.php @@ -4,17 +4,12 @@ namespace unit\WooCommerce; use Codeception\Stub; use Helper\WordPress; -use MailPoet\Doctrine\EntityManagerFactory; use MailPoet\Entities\NewsletterEntity; -use MailPoet\Logging\LoggerFactory; -use MailPoet\Logging\LogRepository; use MailPoet\Newsletter\NewslettersRepository; use MailPoet\Newsletter\Renderer\Blocks\Coupon; use MailPoet\NewsletterProcessingException; -use MailPoet\Settings\SettingsController; use MailPoet\WooCommerce\CouponPreProcessor; use MailPoet\WooCommerce\Helper; -use MailPoetVendor\Doctrine\ORM\EntityManager; class CouponPreProcessorTest extends \MailPoetUnitTest { @@ -239,17 +234,4 @@ class CouponPreProcessorTest extends \MailPoetUnitTest { ]) ->getMock(); } - - private function getLoggerFactory(Stub\StubMarshaler $expectedPersistence): LoggerFactory { - $settings = $this->make(SettingsController::class, ['get' => 'errors']); - $repository = $this->makeEmpty(LogRepository::class, ['persist' => $expectedPersistence]); - $entityManager = $this->make(EntityManager::class); - $entityManagerFactory = $this->make(EntityManagerFactory::class, ['createEntityManager' => $entityManager]); - return $this->make(LoggerFactory::class, [ - 'logRepository' => $repository, - 'entityManager' => $entityManager, - 'entityManagerFactory' => $entityManagerFactory, - 'settings' => $settings, - ]); - } }