Skip to content
Snippets Groups Projects
Commit b8f74ffe authored by Wim Leers's avatar Wim Leers Committed by Ted Bowman
Browse files

Issue #3320782 by Wim Leers, tedbow, yash.rode, phenaproxima: xdebug being...

Issue #3320782 by Wim Leers, tedbow, yash.rode, phenaproxima: xdebug being enabled causes tests to fail without clear indication that it is the problem
parent 9dccd0e8
No related branches found
No related tags found
No related merge requests found
......@@ -4,6 +4,7 @@ declare(strict_types = 1);
namespace Drupal\package_manager\Validator;
use Drupal\Component\FileSystem\FileSystem as DrupalFilesystem;
use Drupal\Core\StringTranslation\StringTranslationTrait;
use Drupal\package_manager\Event\StatusCheckEvent;
use Symfony\Component\EventDispatcher\EventSubscriberInterface;
......@@ -40,6 +41,15 @@ class XdebugValidator implements EventSubscriberInterface {
* Returns an array of warnings or null if Xdebug isn't detected.
*/
protected function checkForXdebug(): ?array {
// Xdebug is allowed to be enabled while running tests, for debugging
// purposes. It's just not allowed to be enabled while using Package Manager
// in a real environment. Except when specifically testing this validator.
// @see \Drupal\Tests\package_manager\Kernel\XdebugValidatorTest::testXdebugValidation()
// @see \Drupal\Tests\automatic_updates\Kernel\StatusCheck\XdebugValidatorTest::simulateXdebugEnabled()
if (self::insideTest() && !function_exists('xdebug_break_TESTED')) {
return NULL;
}
if (function_exists('xdebug_break')) {
return [
$this->t('Xdebug is enabled, which may have a negative performance impact on Package Manager and any modules that use it.'),
......@@ -48,6 +58,21 @@ class XdebugValidator implements EventSubscriberInterface {
return NULL;
}
/**
* Whether this validator is running inside a test.
*
* @return bool
*/
private static function insideTest(): bool {
// @see \Drupal\Core\CoreServiceProvider::registerTest()
$in_functional_test = drupal_valid_test_ua();
// @see \Drupal\Core\DependencyInjection\DependencySerializationTrait::__wakeup()
$in_kernel_test = isset($GLOBALS['__PHPUNIT_BOOTSTRAP']);
// @see \Drupal\BuildTests\Framework\BuildTestBase::setUp()
$in_build_test = str_contains(__FILE__, DrupalFilesystem::getOsTemporaryDirectory() . '/build_workspace_');
return $in_functional_test || $in_kernel_test || $in_build_test;
}
/**
* {@inheritdoc}
*/
......
......@@ -21,6 +21,9 @@ class XdebugValidatorTest extends PackageManagerKernelTestBase {
if (!function_exists('xdebug_break')) {
// @codingStandardsIgnoreLine
eval('function xdebug_break() {}');
// @see \Drupal\package_manager\Validator\XdebugValidator::checkForXdebug()
// @codingStandardsIgnoreLine
eval('function xdebug_break_TESTED() {}');
}
$result = ValidationResult::createWarning([
......
......@@ -44,8 +44,6 @@ abstract class AutomaticUpdatesFunctionalTestBase extends BrowserTestBase {
// package_manager_bypass is disabling those operations.
// @todo https://www.drupal.org/project/automatic_updates/issues/3320755.
'package_manager.validator.composer_executable',
// Always allow tests to run with Xdebug on.
'package_manager.validator.xdebug',
];
/**
......
......@@ -50,8 +50,6 @@ abstract class AutomaticUpdatesKernelTestBase extends PackageManagerKernelTestBa
if (in_array('package_manager.validator.symlink', $this->disableValidators, TRUE)) {
$this->disableValidators[] = 'automatic_updates.validator.symlink';
}
// Always disable the Xdebug validator to allow test to run with Xdebug on.
$this->disableValidators[] = 'package_manager.validator.xdebug';
parent::setUp();
// Enable cron updates, which will eventually be the default.
// @todo Remove in https://www.drupal.org/project/automatic_updates/issues/3284443
......
......@@ -29,18 +29,6 @@ class XdebugValidatorTest extends AutomaticUpdatesKernelTestBase {
*/
protected static $modules = ['automatic_updates'];
/**
* {@inheritdoc}
*/
protected function setUp(): void {
parent::setUp();
// The parent class unconditionally disables the Xdebug validator we're
// testing, so undo that here.
$validator = $this->container->get('package_manager.validator.xdebug');
$this->container->get('event_dispatcher')->addSubscriber($validator);
}
/**
* Tests warnings and/or errors if Xdebug is enabled.
*/
......@@ -121,6 +109,9 @@ class XdebugValidatorTest extends AutomaticUpdatesKernelTestBase {
if (!function_exists('xdebug_break')) {
// @codingStandardsIgnoreLine
eval('function xdebug_break() {}');
// @see \Drupal\package_manager\Validator\XdebugValidator::checkForXdebug()
// @codingStandardsIgnoreLine
eval('function xdebug_break_TESTED() {}');
}
}
......
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