Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
datetime_testing-3164966
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
datetime_testing-3164966
Commits
7a23c2b5
Commit
7a23c2b5
authored
4 years ago
by
Antonio De Marco
Committed by
Antonio De Marco
4 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3112309
by ademarco: Provide Drush commands to set, get, freeze and unfreeze time
parent
7b9d168c
No related branches found
Tags
previous/3298889-make-drupalpackagemanagertestapiapicontroller-more/2022-10-21-1
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
drush.services.yml
+6
-0
6 additions, 0 deletions
drush.services.yml
readme.md
+9
-0
9 additions, 0 deletions
readme.md
src/Commands/TestTimeCommands.php
+97
-0
97 additions, 0 deletions
src/Commands/TestTimeCommands.php
with
112 additions
and
0 deletions
drush.services.yml
0 → 100644
+
6
−
0
View file @
7a23c2b5
services
:
oe_theme_mock_request_time.commands
:
class
:
Drupal\datetime_testing\Commands\TestTimeCommands
arguments
:
[
'
@datetime_testing.test_time'
]
tags
:
-
{
name
:
drush.command
}
This diff is collapsed.
Click to expand it.
readme.md
+
9
−
0
View file @
7a23c2b5
...
...
@@ -104,6 +104,15 @@ Drupal\DrupalExtension:
You do not need to declare the subcontext under the
`contexts`
key of behat.yml.
DRUSH COMMANDS
--------------
The module provides the following Drush commands:
-
`datetime-testing:set`
: set test time, must be expressed in the following format
`Y-m-d H:i:s`
.
-
`datetime-testing:get`
: get current time.
-
`datetime-testing:freeze`
: freeze time.
-
`datetime-testing:unfreeze`
: unfreeze time.
MAINTAINERS
-----------
...
...
This diff is collapsed.
Click to expand it.
src/Commands/TestTimeCommands.php
0 → 100644
+
97
−
0
View file @
7a23c2b5
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\datetime_testing\Commands
;
use
Drupal\Core\Datetime\DrupalDateTime
;
use
Drupal\datetime_testing
\TestTimeInterface
;
use
Drush\Commands\DrushCommands
;
/**
* Provide Drush commands for the test time service.
*/
class
TestTimeCommands
extends
DrushCommands
{
/**
* Mock request time manager service.
*
* @var \Drupal\datetime_testing\TestTimeInterface
*/
protected
$testTime
;
/**
* MockRequestTimeCommands constructor.
*
* @param \Drupal\datetime_testing\TestTimeInterface $test_time
* Test time service.
*/
public
function
__construct
(
TestTimeInterface
$test_time
)
{
parent
::
__construct
();
$this
->
testTime
=
$test_time
;
}
/**
* Set test time.
*
* @param string $time
* Date and time to be set, in the following format 'Y-m-d H:i:s'.
*
* @usage datetime-testing:set '2020-01-15 12:00:00'
*
* @command datetime-testing:set
*/
public
function
set
(
string
$time
):
void
{
$timestamp
=
DrupalDateTime
::
createFromFormat
(
DrupalDateTime
::
FORMAT
,
$time
)
->
getTimestamp
();
$this
->
testTime
->
setTime
(
$timestamp
);
$this
->
logger
()
->
success
(
"Time has been set to '
{
$time
}
', timestamp:
{
$timestamp
}
."
);
}
/**
* Get current time.
*
* @usage datetime-testing:get
*
* @command datetime-testing:get
*/
public
function
get
():
void
{
$time
=
$this
->
testTime
->
getCurrentTime
();
$date
=
DrupalDateTime
::
createFromTimestamp
(
$time
)
->
format
(
DrupalDateTime
::
FORMAT
);
$this
->
logger
()
->
success
(
"Current time value is
{
$date
}
, timestamp:
{
$time
}
."
);
}
/**
* Freeze test time.
*
* @command datetime-testing:freeze
*/
public
function
freeze
():
void
{
$this
->
testTime
->
freezeTime
();
$time
=
$this
->
testTime
->
getCurrentTime
();
$date
=
DrupalDateTime
::
createFromTimestamp
(
$time
)
->
format
(
DrupalDateTime
::
FORMAT
);
$this
->
logger
()
->
success
(
"Time is frozen to
{
$date
}
, timestamp:
{
$time
}
."
);
}
/**
* Get current time.
*
* @command datetime-testing:get
*/
public
function
unfreeze
():
void
{
$this
->
testTime
->
freezeTime
();
$this
->
logger
()
->
success
(
"Time has been unfrozen."
);
}
/**
* Reset test time.
*
* @usage datetime-testing:reset
*
* @command datetime-testing:reset
*/
public
function
reset
():
void
{
$this
->
testTime
->
resetTime
();
$this
->
logger
()
->
success
(
"Test time has been reset."
);
}
}
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