Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
automatic_updates-3406812
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Issue forks
automatic_updates-3406812
Commits
dcadb858
"src/git@git.drupal.org:issue/salesforce-3257058.git" did not exist on "c846d1023b41661bbb03f4f8733df3a5250f6b9d"
Commit
dcadb858
authored
2 years ago
by
Adam G-H
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3293422
by phenaproxima: Don't allow cron updates if Xdebug is enabled
parent
1a4c3132
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Validator/XdebugValidator.php
+16
-5
16 additions, 5 deletions
src/Validator/XdebugValidator.php
tests/src/Kernel/ReadinessValidation/XdebugValidatorTest.php
+69
-0
69 additions, 0 deletions
tests/src/Kernel/ReadinessValidation/XdebugValidatorTest.php
with
85 additions
and
5 deletions
src/Validator/XdebugValidator.php
+
16
−
5
View file @
dcadb858
...
...
@@ -2,8 +2,11 @@
namespace
Drupal\automatic_updates\Validator
;
use
Drupal\automatic_updates
\CronUpdater
;
use
Drupal\automatic_updates
\Event\ReadinessCheckEvent
;
use
Drupal\Core\StringTranslation\StringTranslationTrait
;
use
Drupal\package_manager
\Event\PreCreateEvent
;
use
Drupal\package_manager
\Event\PreOperationStageEvent
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
/**
...
...
@@ -21,14 +24,21 @@ final class XdebugValidator implements EventSubscriberInterface {
/**
* Flags a warning if Xdebug is enabled.
*
* @param \Drupal\
automatic_updates\Event\ReadinessCheck
Event $event
* @param \Drupal\
package_manager\Event\PreOperationStage
Event $event
* The event object.
*/
public
function
checkForXdebug
(
ReadinessCheck
Event
$event
):
void
{
if
(
extension_loaded
(
'xdebug'
))
{
$
event
->
addWarning
(
[
public
function
checkForXdebug
(
PreOperationStage
Event
$event
):
void
{
if
(
function_exists
(
'xdebug
_break
'
))
{
$
messages
=
[
$this
->
t
(
'Xdebug is enabled, which may cause timeout errors.'
),
]);
];
if
(
$event
->
getStage
()
instanceof
CronUpdater
&&
$event
instanceof
PreCreateEvent
)
{
$event
->
addError
(
$messages
);
}
else
{
$event
->
addWarning
(
$messages
);
}
}
}
...
...
@@ -38,6 +48,7 @@ final class XdebugValidator implements EventSubscriberInterface {
public
static
function
getSubscribedEvents
()
{
return
[
ReadinessCheckEvent
::
class
=>
'checkForXdebug'
,
PreCreateEvent
::
class
=>
'checkForXdebug'
,
];
}
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/ReadinessValidation/XdebugValidatorTest.php
0 → 100644
+
69
−
0
View file @
dcadb858
<?php
namespace
Drupal\Tests\automatic_updates\Kernel\ReadinessValidation
;
use
Drupal\automatic_updates
\CronUpdater
;
use
Drupal\Core\Logger\RfcLogLevel
;
use
Drupal\package_manager
\ValidationResult
;
use
Drupal\Tests\automatic_updates
\Kernel\AutomaticUpdatesKernelTestBase
;
use
Drupal\Tests\package_manager
\Traits\PackageManagerBypassTestTrait
;
use
Psr\Log\Test\TestLogger
;
/**
* @covers \Drupal\automatic_updates\Validator\XdebugValidator
*
* @group automatic_updates
*/
class
XdebugValidatorTest
extends
AutomaticUpdatesKernelTestBase
{
use
PackageManagerBypassTestTrait
;
/**
* {@inheritdoc}
*/
protected
static
$modules
=
[
'automatic_updates'
];
/**
* {@inheritdoc}
*/
protected
function
setUp
():
void
{
// Ensure the validator will think Xdebug is enabled.
if
(
!
function_exists
(
'xdebug_break'
))
{
// @codingStandardsIgnoreLine
eval
(
'function xdebug_break() {}'
);
}
parent
::
setUp
();
// The parent class unconditionally disables the Xdebug validator we're
// testing, so undo that here.
$validator
=
$this
->
container
->
get
(
'automatic_updates.validator.xdebug'
);
$this
->
container
->
get
(
'event_dispatcher'
)
->
addSubscriber
(
$validator
);
}
/**
* Tests warnings and/or errors if Xdebug is enabled.
*/
public
function
testXdebugValidation
():
void
{
$message
=
'Xdebug is enabled, which may cause timeout errors.'
;
$result
=
ValidationResult
::
createWarning
([
$message
]);
$this
->
assertCheckerResultsFromManager
([
$result
],
TRUE
);
// The parent class' setUp() method simulates an available security update,
// so ensure that the cron updater will try to update to it.
$this
->
config
(
'automatic_updates.settings'
)
->
set
(
'cron'
,
CronUpdater
::
SECURITY
)
->
save
();
// Trying to do the update during cron should fail with an error.
$logger
=
new
TestLogger
();
$this
->
container
->
get
(
'logger.factory'
)
->
get
(
'automatic_updates'
)
->
addLogger
(
$logger
);
$this
->
container
->
get
(
'cron'
)
->
run
();
$this
->
assertUpdateStagedTimes
(
0
);
$this
->
assertTrue
(
$logger
->
hasRecordThatMatches
(
"/
$message
/"
,
RfcLogLevel
::
ERROR
));
}
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment