Files
piratepoet/mailpoet/tests/integration/Config/UpdaterTest.php
Rodrigo Primo a54e1f3c01 Replace expect()->greaterOrEquals() with verify()->greaterThanOrEqual()
codeception/verify 2.1 removed support for expect()->greaterOrEquals() so we need
to replace it with verify()->greaterThanOrEqual().

[MAILPOET-5664]
2023-10-24 08:58:22 +03:00

122 lines
4.1 KiB
PHP

<?php declare(strict_types = 1);
namespace MailPoet\Test\Config;
use Codeception\Stub;
use Codeception\Stub\Expected;
use MailPoet\Config\Updater;
class UpdaterTest extends \MailPoetTest {
/** @var Updater */
public $updater;
/** @var string */
public $version;
/** @var string */
public $slug;
/** @var string */
public $pluginName;
public function _before() {
parent::_before();
$this->pluginName = 'some-plugin/some-plugin.php';
$this->slug = 'some-plugin';
$this->version = '0.1';
$this->updater = new Updater(
$this->pluginName,
$this->slug,
$this->version
);
}
public function testItInitializes() {
$updater = Stub::make(
$this->updater,
[
'checkForUpdate' => Expected::once(),
],
$this
);
$updater->init();
apply_filters('pre_set_site_transient_update_plugins', null);
}
public function testItChecksForUpdates() {
$updateTransient = new \stdClass;
$updateTransient->last_checked = time(); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
$updater = Stub::construct(
$this->updater,
[
$this->pluginName,
$this->slug,
$this->version,
],
[
'getLatestVersion' => function () {
return (object)[
'id' => 76630,
'slug' => $this->slug,
'plugin' => $this->pluginName,
'new_version' => $this->version . 1,
'url' => 'https://www.mailpoet.com/wordpress-newsletter-plugin-premium/',
'package' => home_url() . '/wp-content/uploads/mailpoet-premium.zip',
];
},
],
$this
);
$result = $updater->checkForUpdate($updateTransient);
verify($result->last_checked)->greaterThanOrEqual($updateTransient->last_checked); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
verify($result->checked[$this->pluginName])->equals($this->version);
verify($result->response[$this->pluginName]->slug)->equals($this->slug);
verify($result->response[$this->pluginName]->plugin)->equals($this->pluginName);
verify(version_compare(
$this->version,
$result->response[$this->pluginName]->new_version,
'<'
))->true();
verify($result->response[$this->pluginName]->package)->notEmpty();
}
public function testItSetsNoupdateKeyIfNoUpdateAvailable() {
$updateTransient = new \stdClass;
$updateTransient->last_checked = time(); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
$updater = Stub::construct(
$this->updater,
[
$this->pluginName,
$this->slug,
$this->version,
],
[
'getLatestVersion' => function () {
return (object)[
'id' => 76630,
'slug' => $this->slug,
'plugin' => $this->pluginName,
'new_version' => $this->version,
'url' => 'https://www.mailpoet.com/wordpress-newsletter-plugin-premium/',
'package' => home_url() . '/wp-content/uploads/mailpoet-premium.zip',
];
},
],
$this
);
$result = $updater->checkForUpdate($updateTransient);
verify($result->last_checked)->greaterThanOrEqual($updateTransient->last_checked); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
verify($result->checked[$this->pluginName])->equals($this->version);
verify($result->no_update[$this->pluginName]->slug)->equals($this->slug); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
verify($result->no_update[$this->pluginName]->plugin)->equals($this->pluginName); // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
verify(version_compare(
$this->version,
$result->no_update[$this->pluginName]->new_version, // phpcs:ignore Squiz.NamingConventions.ValidVariableName.MemberNotCamelCaps
'='
))->true();
}
public function testItReturnsObjectIfPassedNonObjectWhenCheckingForUpdates() {
$result = $this->updater->checkForUpdate(null);
verify($result instanceof \stdClass)->true();
}
}