Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
automatic_updates-3328600
Manage
Activity
Members
Labels
Plan
Custom issue tracker
Code
Merge requests
0
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-3328600
Commits
b683ad5f
Commit
b683ad5f
authored
2 years ago
by
Yash Rode
Browse files
Options
Downloads
Patches
Plain Diff
Added test coverage
parent
66e783f2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/CronUpdater.php
+1
-1
1 addition, 1 deletion
src/CronUpdater.php
tests/src/Kernel/CronUpdaterTest.php
+68
-1
68 additions, 1 deletion
tests/src/Kernel/CronUpdaterTest.php
with
69 additions
and
2 deletions
src/CronUpdater.php
+
1
−
1
View file @
b683ad5f
...
...
@@ -165,7 +165,7 @@ class CronUpdater extends Updater {
private
function
performUpdate
(
string
$target_version
,
?int
$timeout
):
void
{
$project_info
=
new
ProjectInfo
(
'drupal'
);
// Delete the existing stag
e
if not available and the site is currently on an insecure version.
// Delete the existing stag
ing area
if not available and the site is currently on an insecure version.
if
(
!
$project_info
->
isInstalledVersionSafe
()
&&
!
$this
->
isAvailable
()
&&
!
$this
->
isApplying
())
{
$this
->
destroy
(
TRUE
);
}
...
...
This diff is collapsed.
Click to expand it.
tests/src/Kernel/CronUpdaterTest.php
+
68
−
1
View file @
b683ad5f
...
...
@@ -18,6 +18,7 @@ use Drupal\package_manager\Event\PreApplyEvent;
use
Drupal\package_manager
\Event\PreDestroyEvent
;
use
Drupal\package_manager
\Event\PreRequireEvent
;
use
Drupal\package_manager
\Event\PreCreateEvent
;
use
Drupal\package_manager
\Event\StageEvent
;
use
Drupal\package_manager
\Exception\StageValidationException
;
use
Drupal\package_manager
\ValidationResult
;
use
Drupal\package_manager_bypass
\Committer
;
...
...
@@ -28,6 +29,7 @@ use Drupal\update\UpdateSettingsForm;
use
ColinODell\PsrTestLogger\TestLogger
;
use
Prophecy\Argument
;
use
Symfony\Component\EventDispatcher\EventDispatcherInterface
;
use
Symfony\Component\EventDispatcher\EventSubscriberInterface
;
/**
* @covers \Drupal\automatic_updates\CronUpdater
...
...
@@ -35,7 +37,7 @@ use Symfony\Component\EventDispatcher\EventDispatcherInterface;
* @group automatic_updates
* @internal
*/
class
CronUpdaterTest
extends
AutomaticUpdatesKernelTestBase
{
class
CronUpdaterTest
extends
AutomaticUpdatesKernelTestBase
implements
EventSubscriberInterface
{
use
EmailNotificationsTestTrait
;
use
PackageManagerBypassTestTrait
;
...
...
@@ -57,6 +59,27 @@ class CronUpdaterTest extends AutomaticUpdatesKernelTestBase {
*/
private
$logger
;
/**
* The new stage ID.
*
* @var string
*/
private
$new_stage_id
;
/**
* The events that were fired, in the order they were fired.
*
* @var string[]
*/
private
$events
=
[];
/**
* The stage under test.
*
* @var \Drupal\package_manager\Stage
*/
private
$stage
;
/**
* {@inheritdoc}
*/
...
...
@@ -347,6 +370,32 @@ class CronUpdaterTest extends AutomaticUpdatesKernelTestBase {
}
}
/**
* Tests stage is destroyed if not available and site is on insecure version.
*/
public
function
testStageDestroyedIfNotAvailable
():
void
{
$this
->
container
->
get
(
'event_dispatcher'
)
->
addSubscriber
(
$this
);
$stage
=
$this
->
createStage
();
$stage_id
=
$stage
->
create
();
$temp_store
=
$this
->
container
->
get
(
'tempstore.shared'
);
$listener
=
function
(
PreApplyEvent
$event
)
use
(
$temp_store
):
void
{
// @see \Drupal\package_manager\Stage::TEMPSTORE_LOCK_KEY
$this
->
new_stage_id
=
$temp_store
->
get
(
'package_manager_stage'
)
->
get
(
'lock'
)[
0
];
};
$this
->
container
->
get
(
'event_dispatcher'
)
->
addListener
(
PreApplyEvent
::
class
,
$listener
,
PHP_INT_MAX
);
$this
->
container
->
get
(
'cron'
)
->
run
();
// To demonstrate these events are called in order.
$this
->
assertSame
(
$this
->
events
,
[
PreDestroyEvent
::
class
,
PostDestroyEvent
::
class
,
PreApplyEvent
::
class
,
]);
$this
->
assertNotEquals
(
$stage_id
,
$this
->
new_stage_id
);
}
/**
* Tests that CronUpdater::begin() unconditionally throws an exception.
*/
...
...
@@ -498,4 +547,22 @@ END;
$this
->
assertSame
(
'setLogger'
,
$updater_method_calls
[
0
][
0
]);
}
/**
* Handles a staging area life cycle event.
*
* @param \Drupal\package_manager\Event\StageEvent $event
* The event object.
*/
public
function
handleEvent
(
StageEvent
$event
):
void
{
array_push
(
$this
->
events
,
get_class
(
$event
));
}
public
static
function
getSubscribedEvents
():
array
{
return
[
PreDestroyEvent
::
class
=>
'handleEvent'
,
PostDestroyEvent
::
class
=>
'handleEvent'
,
PreApplyEvent
::
class
=>
'handleEvent'
,
];
}
}
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