Remove AspectMock from CronHelperTest [MAILPOET-2464]
This commit is contained in:
@@ -94,13 +94,17 @@ class CronHelper {
|
||||
return Security::generateRandomString();
|
||||
}
|
||||
|
||||
static function pingDaemon() {
|
||||
static function pingDaemon($wp = null) {
|
||||
if (is_null($wp)) {
|
||||
$wp = new WPFunctions();
|
||||
}
|
||||
$url = self::getCronUrl(
|
||||
CronDaemonEndpoint::ACTION_PING_RESPONSE
|
||||
CronDaemonEndpoint::ACTION_PING_RESPONSE,
|
||||
false,
|
||||
$wp
|
||||
);
|
||||
$result = self::queryCronUrl($url);
|
||||
if (is_wp_error($result)) return $result->get_error_message();
|
||||
$wp = new WPFunctions();
|
||||
$response = $wp->wpRemoteRetrieveBody($result);
|
||||
$response = substr(trim($response), -strlen(DaemonHttpRunner::PING_SUCCESS_RESPONSE)) === DaemonHttpRunner::PING_SUCCESS_RESPONSE ?
|
||||
DaemonHttpRunner::PING_SUCCESS_RESPONSE :
|
||||
@@ -112,7 +116,10 @@ class CronHelper {
|
||||
return $response === DaemonHttpRunner::PING_SUCCESS_RESPONSE;
|
||||
}
|
||||
|
||||
static function accessDaemon($token) {
|
||||
static function accessDaemon($token, $wp = null) {
|
||||
if (is_null($wp)) {
|
||||
$wp = new WPFunctions();
|
||||
}
|
||||
$data = ['token' => $token];
|
||||
$url = self::getCronUrl(
|
||||
CronDaemonEndpoint::ACTION_RUN,
|
||||
@@ -124,8 +131,7 @@ class CronHelper {
|
||||
}
|
||||
$daemon['run_accessed_at'] = time();
|
||||
self::saveDaemon($daemon);
|
||||
$result = self::queryCronUrl($url);
|
||||
$wp = new WPFunctions();
|
||||
$result = self::queryCronUrl($url, $wp);
|
||||
return $wp->wpRemoteRetrieveBody($result);
|
||||
}
|
||||
|
||||
|
@@ -2,7 +2,6 @@
|
||||
|
||||
namespace MailPoet\Test\Cron;
|
||||
|
||||
use AspectMock\Test as Mock;
|
||||
use Codeception\Stub;
|
||||
use MailPoet\Cron\CronHelper;
|
||||
use MailPoet\Cron\DaemonHttpRunner;
|
||||
@@ -102,8 +101,10 @@ class CronHelperTest extends \MailPoetTest {
|
||||
$daemon
|
||||
);
|
||||
$time = time();
|
||||
Mock::double('MailPoet\Cron\CronHelper', ['queryCronUrl' => []]);
|
||||
CronHelper::accessDaemon('some_token');
|
||||
$wp = Stub::make(new WPFunctions, [
|
||||
'wpRemotePost' => [],
|
||||
]);
|
||||
CronHelper::accessDaemon('some_token', $wp);
|
||||
$updated_daemon = CronHelper::getDaemon();
|
||||
expect($updated_daemon['run_accessed_at'])->greaterOrEquals($time);
|
||||
expect($updated_daemon['run_accessed_at'])->lessThan($time + 2);
|
||||
@@ -300,10 +301,10 @@ class CronHelperTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function testItReturnsErrorMessageAsPingResponseWhenCronUrlCannotBeAccessed() {
|
||||
Mock::double('MailPoet\Cron\CronHelper', [
|
||||
'getSiteUrl' => false,
|
||||
$wp = Stub::make(new WPFunctions, [
|
||||
'applyFilters' => false,
|
||||
]);
|
||||
expect(CronHelper::pingDaemon())->equals('A valid URL was not provided.');
|
||||
expect(CronHelper::pingDaemon($wp))->equals('A valid URL was not provided.');
|
||||
}
|
||||
|
||||
function testItPingsDaemon() {
|
||||
@@ -318,7 +319,6 @@ class CronHelperTest extends \MailPoetTest {
|
||||
}
|
||||
|
||||
function _after() {
|
||||
Mock::clean();
|
||||
\ORM::raw_execute('TRUNCATE ' . Setting::$_table);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user