Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
simplesamlphp
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
Perun
Perun ProxyIdP
v1
simplesamlphp
Commits
64142774
Commit
64142774
authored
9 years ago
by
Jaime Perez Crespo
Browse files
Options
Downloads
Patches
Plain Diff
Add tests for SimpleSAML\Utils\Time::parseDuration().
parent
043edac3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
tests/lib/SimpleSAML/Utils/TimeTest.php
+77
-0
77 additions, 0 deletions
tests/lib/SimpleSAML/Utils/TimeTest.php
with
77 additions
and
0 deletions
tests/lib/SimpleSAML/Utils/TimeTest.php
+
77
−
0
View file @
64142774
...
...
@@ -9,6 +9,8 @@ class TimeTest extends \PHPUnit_Framework_TestCase
/**
* Test the SimpleSAML\Utils\Time::generateTimestamp() method.
*
* @covers SimpleSAML\Utils\Time::generateTimestamp
*/
public
function
testGenerateTimestamp
()
{
...
...
@@ -18,4 +20,79 @@ class TimeTest extends \PHPUnit_Framework_TestCase
// test timestamp generation for current time
$this
->
assertRegExp
(
'/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/'
,
Time
::
generateTimestamp
());
}
/**
* Test the SimpleSAML\Utils\Time::parseDuration() method.
*
* @covers SimpleSAML\Utils\Time::parseDuration
*/
public
function
testParseDuration
()
{
// set up base date and time, and fixed durations from there
$base
=
gmmktime
(
0
,
0
,
0
,
1
,
1
,
2000
);
$second
=
gmmktime
(
0
,
0
,
1
,
1
,
1
,
2000
);
$minute
=
gmmktime
(
0
,
1
,
0
,
1
,
1
,
2000
);
$hour
=
gmmktime
(
1
,
0
,
0
,
1
,
1
,
2000
);
$day
=
gmmktime
(
0
,
0
,
0
,
1
,
2
,
2000
);
$month
=
gmmktime
(
0
,
0
,
0
,
2
,
1
,
2000
);
$year
=
gmmktime
(
0
,
0
,
0
,
1
,
1
,
2001
);
// test valid duration with timestamp and zeroes
$this
->
assertEquals
(
$base
+
(
60
*
60
)
+
60
+
1
,
Time
::
parseDuration
(
'P0Y0M0DT1H1M1S'
,
$base
));
// test seconds
$this
->
assertEquals
(
$second
,
Time
::
parseDuration
(
'PT1S'
,
$base
));
// test minutes
$this
->
assertEquals
(
$minute
,
Time
::
parseDuration
(
'PT1M'
,
$base
));
// test hours
$this
->
assertEquals
(
$hour
,
Time
::
parseDuration
(
'PT1H'
,
$base
));
// test days
$this
->
assertEquals
(
$day
,
Time
::
parseDuration
(
'P1D'
,
$base
));
// test month
$this
->
assertEquals
(
$month
,
Time
::
parseDuration
(
'P1M'
,
$base
));
// test year
$this
->
assertEquals
(
$year
,
Time
::
parseDuration
(
'P1Y'
,
$base
));
// test from current time
$now
=
time
();
$this
->
assertGreaterThanOrEqual
(
$now
+
60
,
Time
::
parseDuration
(
'PT1M'
));
// test invalid input parameters
try
{
// invalid duration
Time
::
parseDuration
(
0
);
$this
->
never
();
}
catch
(
\InvalidArgumentException
$e
)
{
$this
->
assertEquals
(
'Invalid input parameters'
,
$e
->
getMessage
());
}
try
{
// invalid timestamp
Time
::
parseDuration
(
''
,
array
());
$this
->
never
();
}
catch
(
\InvalidArgumentException
$e
)
{
$this
->
assertEquals
(
'Invalid input parameters'
,
$e
->
getMessage
());
}
// test invalid durations
try
{
// invalid string
Time
::
parseDuration
(
'abcdefg'
);
$this
->
never
();
}
catch
(
\InvalidArgumentException
$e
)
{
$this
->
assertStringStartsWith
(
'Invalid ISO 8601 duration: '
,
$e
->
getMessage
());
}
try
{
// missing T
Time
::
parseDuration
(
'P1S'
);
$this
->
never
();
}
catch
(
\InvalidArgumentException
$e
)
{
$this
->
assertStringStartsWith
(
'Invalid ISO 8601 duration: '
,
$e
->
getMessage
());
}
}
}
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