Skip to content
Snippets Groups Projects
Commit f1f29b26 authored by Lucas Hedding's avatar Lucas Hedding Committed by Lucas Hedding
Browse files

Issue #3053712 by heddn, eiriksm, catch, mbaynton: Provide context of how checker service is run

parent 16af2f04
No related branches found
No related tags found
No related merge requests found
......@@ -91,3 +91,9 @@ services:
- '@extension.list.theme'
tags:
- { name: readiness_checker, category: warning}
automatic_updates.php_sapi:
class: Drupal\automatic_updates\ReadinessChecker\PhpSapi
arguments:
- '@state'
tags:
- { name: readiness_checker, category: warning}
<?php
namespace Drupal\automatic_updates\ReadinessChecker;
use Drupal\Core\State\StateInterface;
use Drupal\Core\StringTranslation\StringTranslationTrait;
/**
* Warn if PHP SAPI changes between checker executions.
*/
class PhpSapi implements ReadinessCheckerInterface {
use StringTranslationTrait;
/**
* The state service.
*
* @var \Drupal\Core\State\StateInterface
*/
protected $state;
/**
* PhpSapi constructor.
*
* @param \Drupal\Core\State\StateInterface $state
* The state service.
*/
public function __construct(StateInterface $state) {
$this->state = $state;
}
/**
* {@inheritdoc}
*/
public function run() {
$messages = [];
$php_sapi = $this->state->get('automatic_updates.php_sapi', PHP_SAPI);
if ($php_sapi !== PHP_SAPI) {
$messages[] = $this->t('PHP changed from running as "@previous" to "@current". This can lead to inconsistent and misleading results.', ['@previous' => $php_sapi, '@current' => PHP_SAPI]);
}
return $messages;
}
}
<?php
namespace Drupal\Tests\automatic_updates\Kernel\ReadinessChecker;
use Drupal\KernelTests\KernelTestBase;
/**
* Tests what happens when PHP SAPI changes from one value to another.
*
* @group automatic_updates
*/
class PhpSapiTest extends KernelTestBase {
/**
* {@inheritdoc}
*/
public static $modules = [
'automatic_updates',
];
/**
* Tests the functionality of supported PHP version readiness checks.
*/
public function testSupportedPhpVersion() {
$messages = $this->container->get('automatic_updates.php_sapi')->run();
$this->assertEmpty($messages);
$messages = $this->container->get('automatic_updates.php_sapi')->run();
$this->assertEmpty($messages);
$this->container->get('state')->set('automatic_updates.php_sapi', 'foo');
$messages = $this->container->get('automatic_updates.php_sapi')->run();
$this->assertEquals('PHP changed from running as "foo" to "cli". This can lead to inconsistent and misleading results.', $messages[0]);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment