Skip to content
Snippets Groups Projects
Commit d42386e9 authored by Jaime Perez Crespo's avatar Jaime Perez Crespo
Browse files

Initial test for SimpleSAML\Utils\Time.

parent b3136393
No related branches found
No related tags found
No related merge requests found
...@@ -91,7 +91,8 @@ class Time ...@@ -91,7 +91,8 @@ class Time
} }
// parse the duration. We use a very strict pattern // parse the duration. We use a very strict pattern
$durationRegEx = '#^(-?)P(?:(?:(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)(?:[.,]\d+)?S)?)?)|(?:(\\d+)W))$#D'; $durationRegEx = '#^(-?)P(?:(?:(?:(\\d+)Y)?(?:(\\d+)M)?(?:(\\d+)D)?(?:T(?:(\\d+)H)?(?:(\\d+)M)?(?:(\\d+)'.
'(?:[.,]\d+)?S)?)?)|(?:(\\d+)W))$#D';
if (!preg_match($durationRegEx, $duration, $matches)) { if (!preg_match($durationRegEx, $duration, $matches)) {
throw new \InvalidArgumentException('Invalid ISO 8601 duration: '.$duration); throw new \InvalidArgumentException('Invalid ISO 8601 duration: '.$duration);
} }
...@@ -159,4 +160,4 @@ class Time ...@@ -159,4 +160,4 @@ class Time
return $timestamp; return $timestamp;
} }
} }
\ No newline at end of file
<?php
namespace SimpleSAML\Test\Utils;
use SimpleSAML\Utils\Time;
class TimeTest extends \PHPUnit_Framework_TestCase
{
/**
* Test the SimpleSAML\Utils\Time::generateTimestamp() method.
*/
public function testGenerateTimestamp()
{
// make sure passed timestamps are used
$this->assertEquals('2016-03-03T14:48:05Z', Time::generateTimestamp(1457016485));
// test timestamp generation for current time
$this->assertRegExp('/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}Z$/', Time::generateTimestamp());
}
}
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