Remove phpstan errors from the rest of the tests

[MAILPOET-3235]
This commit is contained in:
Jan Lysý
2021-01-13 17:36:50 +01:00
committed by Veljko V
parent cb60c827a2
commit 922c52f7df
11 changed files with 22 additions and 3 deletions

View File

@ -44,7 +44,9 @@ class Newsletter {
* @return Newsletter * @return Newsletter
*/ */
public function loadBodyFrom($filename) { public function loadBodyFrom($filename) {
$this->data['body'] = json_decode(file_get_contents(__DIR__ . '/../_data/' . $filename), true); $body = file_get_contents(__DIR__ . '/../_data/' . $filename);
assert(is_string($body));
$this->data['body'] = json_decode($body, true);
return $this; return $this;
} }

View File

@ -20,6 +20,7 @@ class Database extends \Codeception\Module {
$db = ORM::getDb(); $db = ORM::getDb();
$fullFilename = Env::$path . '/tests/_data/' . $filename . '.sql'; $fullFilename = Env::$path . '/tests/_data/' . $filename . '.sql';
$sql = file_get_contents($fullFilename); $sql = file_get_contents($fullFilename);
assert(is_string($sql));
$sql = preg_replace('/`wp_/', '`' . $wpdb->prefix, $sql); // Use the current database prefix $sql = preg_replace('/`wp_/', '`' . $wpdb->prefix, $sql); // Use the current database prefix
if (!is_string($sql)) { if (!is_string($sql)) {
throw new \RuntimeException('Empty or missing ' . $fullFilename); throw new \RuntimeException('Empty or missing ' . $fullFilename);

View File

@ -28,6 +28,7 @@ class AbandonedCartPageVisitTrackerTest extends \MailPoetTest {
$this->currentTime = Carbon::now(); $this->currentTime = Carbon::now();
Carbon::setTestNow($this->currentTime); Carbon::setTestNow($this->currentTime);
// @phpstan-ignore-next-line
$this->wp = $this->makeEmpty(WPFunctions::class, [ $this->wp = $this->makeEmpty(WPFunctions::class, [
'currentTime' => $this->currentTime->getTimestamp(), 'currentTime' => $this->currentTime->getTimestamp(),
]); ]);

View File

@ -49,6 +49,7 @@ class AbandonedCartTest extends \MailPoetTest {
$this->currentTime = Carbon::createFromTimestamp((new WPFunctions())->currentTime('timestamp')); $this->currentTime = Carbon::createFromTimestamp((new WPFunctions())->currentTime('timestamp'));
Carbon::setTestNow($this->currentTime); Carbon::setTestNow($this->currentTime);
// @phpstan-ignore-next-line
$this->wp = $this->makeEmpty(WPFunctions::class, [ $this->wp = $this->makeEmpty(WPFunctions::class, [
'currentTime' => function ($arg) { 'currentTime' => function ($arg) {
if ($arg === 'timestamp') { if ($arg === 'timestamp') {
@ -63,11 +64,12 @@ class AbandonedCartTest extends \MailPoetTest {
$this->wooCommerceMock = $this->mockWooCommerceClass(WooCommerce::class, []); $this->wooCommerceMock = $this->mockWooCommerceClass(WooCommerce::class, []);
$this->wooCommerceCartMock = $this->mockWooCommerceClass(WC_Cart::class, ['is_empty', 'get_cart']); $this->wooCommerceCartMock = $this->mockWooCommerceClass(WC_Cart::class, ['is_empty', 'get_cart']);
$this->wooCommerceMock->cart = $this->wooCommerceCartMock; $this->wooCommerceMock->cart = $this->wooCommerceCartMock;
// @phpstan-ignore-next-line
$this->wooCommerceHelperMock = $this->make(WooCommerceHelper::class, [ $this->wooCommerceHelperMock = $this->make(WooCommerceHelper::class, [
'isWooCommerceActive' => true, 'isWooCommerceActive' => true,
'WC' => $this->wooCommerceMock, 'WC' => $this->wooCommerceMock,
]); ]);
// @phpstan-ignore-next-line
$this->pageVisitTrackerMock = $this->makeEmpty(AbandonedCartPageVisitTracker::class); $this->pageVisitTrackerMock = $this->makeEmpty(AbandonedCartPageVisitTracker::class);
} }
@ -222,9 +224,11 @@ class AbandonedCartTest extends \MailPoetTest {
expect(ScheduledTask::findMany())->count(2); expect(ScheduledTask::findMany())->count(2);
$completed = ScheduledTask::where('status', ScheduledTask::STATUS_COMPLETED)->findOne(); $completed = ScheduledTask::where('status', ScheduledTask::STATUS_COMPLETED)->findOne();
assert($completed instanceof ScheduledTask);
expect($completed->scheduledAt)->same($scheduledInPast->format('Y-m-d H:i:s')); expect($completed->scheduledAt)->same($scheduledInPast->format('Y-m-d H:i:s'));
$scheduled = ScheduledTask::where('status', ScheduledTask::STATUS_SCHEDULED)->findOne(); $scheduled = ScheduledTask::where('status', ScheduledTask::STATUS_SCHEDULED)->findOne();
assert($scheduled instanceof ScheduledTask);
expect($scheduled->scheduledAt)->same($expectedTime->format('Y-m-d H:i:s')); expect($scheduled->scheduledAt)->same($expectedTime->format('Y-m-d H:i:s'));
} }

View File

@ -19,6 +19,7 @@ class LogHandlerTest extends \MailPoetTest {
]); ]);
$log = Log::where('name', 'name')->orderByDesc('id')->findOne(); $log = Log::where('name', 'name')->orderByDesc('id')->findOne();
assert($log instanceof Log);
expect($log->createdAt)->equals($time->format('Y-m-d H:i:s')); expect($log->createdAt)->equals($time->format('Y-m-d H:i:s'));
} }

View File

@ -483,6 +483,8 @@ class WooCommerceTest extends \MailPoetTest {
$association1AfterUpdate = SubscriberSegment::findOne($association1->id); $association1AfterUpdate = SubscriberSegment::findOne($association1->id);
$association2AfterUpdate = SubscriberSegment::findOne($association2->id); $association2AfterUpdate = SubscriberSegment::findOne($association2->id);
assert($association1AfterUpdate instanceof SubscriberSegment);
assert($association2AfterUpdate instanceof SubscriberSegment);
expect($association1AfterUpdate->status)->equals(Subscriber::STATUS_SUBSCRIBED); expect($association1AfterUpdate->status)->equals(Subscriber::STATUS_SUBSCRIBED);
expect($association2AfterUpdate->status)->equals(Subscriber::STATUS_UNSUBSCRIBED); expect($association2AfterUpdate->status)->equals(Subscriber::STATUS_UNSUBSCRIBED);
} }
@ -525,6 +527,8 @@ class WooCommerceTest extends \MailPoetTest {
$association1AfterUpdate = SubscriberSegment::findOne($association1->id); $association1AfterUpdate = SubscriberSegment::findOne($association1->id);
$association2AfterUpdate = SubscriberSegment::findOne($association2->id); $association2AfterUpdate = SubscriberSegment::findOne($association2->id);
assert($association1AfterUpdate instanceof SubscriberSegment);
assert($association2AfterUpdate instanceof SubscriberSegment);
expect($association1AfterUpdate->status)->equals(Subscriber::STATUS_UNSUBSCRIBED); expect($association1AfterUpdate->status)->equals(Subscriber::STATUS_UNSUBSCRIBED);
expect($association2AfterUpdate->status)->equals(Subscriber::STATUS_SUBSCRIBED); expect($association2AfterUpdate->status)->equals(Subscriber::STATUS_SUBSCRIBED);
} }

View File

@ -71,6 +71,7 @@ class UserFlagsControllerTest extends \MailPoetTest {
'userId' => $this->currentUserId, 'userId' => $this->currentUserId,
'name' => 'flag_1', 'name' => 'flag_1',
]); ]);
assert($flag instanceof UserFlagEntity);
expect($flag->getValue())->equals('updated_value'); expect($flag->getValue())->equals('updated_value');
} }

View File

@ -91,11 +91,13 @@ class WooCommercePurchasesTest extends \MailPoetTest {
expect(count($purchaseStats))->equals(2); expect(count($purchaseStats))->equals(2);
$stats1 = StatisticsWooCommercePurchases::where('newsletter_id', $this->newsletter->id)->findOne(); $stats1 = StatisticsWooCommercePurchases::where('newsletter_id', $this->newsletter->id)->findOne();
assert($stats1 instanceof StatisticsWooCommercePurchases);
expect($stats1->clickId)->equals($click1->id); expect($stats1->clickId)->equals($click1->id);
expect($stats1->subscriberId)->equals($this->subscriber->id); expect($stats1->subscriberId)->equals($this->subscriber->id);
expect($stats1->queueId)->equals($this->queue->id); expect($stats1->queueId)->equals($this->queue->id);
$stats2 = StatisticsWooCommercePurchases::where('newsletter_id', $newsletter->id)->findOne(); $stats2 = StatisticsWooCommercePurchases::where('newsletter_id', $newsletter->id)->findOne();
assert($stats2 instanceof StatisticsWooCommercePurchases);
expect($stats2->clickId)->equals($click2->id); expect($stats2->clickId)->equals($click2->id);
expect($stats2->subscriberId)->equals($this->subscriber->id); expect($stats2->subscriberId)->equals($this->subscriber->id);
expect($stats2->queueId)->equals($queue->id); expect($stats2->queueId)->equals($queue->id);

View File

@ -149,6 +149,7 @@ class ExportTest extends \MailPoetTest {
public function testItCanGetSubscriberCustomFields() { public function testItCanGetSubscriberCustomFields() {
$source = CustomField::where('name', $this->customFieldsData[0]['name']) $source = CustomField::where('name', $this->customFieldsData[0]['name'])
->findOne(); ->findOne();
assert($source instanceof CustomField);
$target = $this->export->getSubscriberCustomFields(); $target = $this->export->getSubscriberCustomFields();
expect($target)->equals([$source->id => $source->name]); expect($target)->equals([$source->id => $source->name]);
} }

View File

@ -59,6 +59,7 @@ class TransactionalEmailsTest extends \MailPoetTest {
public function testInitCreatesTransactionalEmailAndSavesItsId() { public function testInitCreatesTransactionalEmailAndSavesItsId() {
$this->transactionalEmails->init(); $this->transactionalEmails->init();
$email = $this->newslettersRepository->findOneBy(['type' => Newsletter::TYPE_WC_TRANSACTIONAL_EMAIL]); $email = $this->newslettersRepository->findOneBy(['type' => Newsletter::TYPE_WC_TRANSACTIONAL_EMAIL]);
assert($email instanceof NewsletterEntity);
$id = $this->settings->get(TransactionalEmails::SETTING_EMAIL_ID, null); $id = $this->settings->get(TransactionalEmails::SETTING_EMAIL_ID, null);
expect($email)->notEmpty(); expect($email)->notEmpty();
expect($id)->notNull(); expect($id)->notNull();
@ -89,6 +90,7 @@ class TransactionalEmailsTest extends \MailPoetTest {
$email = $this->newslettersRepository->findOneBy([ $email = $this->newslettersRepository->findOneBy([
'type' => NewsletterEntity::TYPE_WC_TRANSACTIONAL_EMAIL, 'type' => NewsletterEntity::TYPE_WC_TRANSACTIONAL_EMAIL,
]); ]);
assert($email instanceof NewsletterEntity);
expect($email)->notEmpty(); expect($email)->notEmpty();
expect(json_encode($email->getBody()))->stringContainsString('my-awesome-image-url'); expect(json_encode($email->getBody()))->stringContainsString('my-awesome-image-url');
} }

View File

@ -10,7 +10,7 @@ class ReadmeTest extends \MailPoetUnitTest {
public function _before() { public function _before() {
// Sample taken from https://wordpress.org/plugins/about/readme.txt // Sample taken from https://wordpress.org/plugins/about/readme.txt
$this->data = file_get_contents(dirname(__FILE__) . '/ReadmeTestData.txt'); $this->data = (string)file_get_contents(dirname(__FILE__) . '/ReadmeTestData.txt');
} }
public function testItParsesChangelog() { public function testItParsesChangelog() {