Skip to content
This repository was archived by the owner on Apr 23, 2023. It is now read-only.

Commit d611041

Browse files
committed
Fix GeneralizedTimeTest on PHP >= 7.1
1 parent d176a1b commit d611041

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

lib/ASN1/AbstractTime.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function __construct($dateTime = null, $dateTimeZone = 'UTC')
3232
}
3333
$dateTime = $dateTimeObject;
3434
} elseif (!$dateTime instanceof DateTime) {
35-
throw new Exception('Invalid first argument for some instance of ASN_AbstractTime constructor');
35+
throw new Exception('Invalid first argument for some instance of AbstractTime constructor');
3636
}
3737

3838
$this->value = $dateTime;

tests/ASN1/Universal/GeneralizedTimeTest.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
namespace FG\Test\ASN1\Universal;
1212

1313
use DateTime;
14+
use DateTimeZone;
1415
use FG\Test\ASN1TestCase;
1516
use FG\ASN1\Identifier;
1617
use FG\ASN1\Universal\GeneralizedTime;
@@ -21,7 +22,7 @@ class GeneralizedTimeTest extends ASN1TestCase
2122

2223
public function setUp()
2324
{
24-
$this->UTC = new \DateTimeZone('UTC');
25+
$this->UTC = new DateTimeZone('UTC');
2526
}
2627

2728
public function testGetType()
@@ -55,7 +56,7 @@ public function testGetContent()
5556

5657
public function testGetObjectLength()
5758
{
58-
$object = new GeneralizedTime();
59+
$object = new GeneralizedTime('1987-01-15 12:12');
5960
$expectedSize = 2 + 15; // Identifier + length + YYYYMMDDHHmmSSZ
6061
$this->assertEquals($expectedSize, $object->getObjectLength());
6162

@@ -70,12 +71,13 @@ public function testGetObjectLength()
7071

7172
public function testGetBinary()
7273
{
74+
$now = new DateTime('1987-01-15 12:12');
75+
$now->setTimezone($this->UTC);
76+
7377
$expectedType = chr(Identifier::GENERALIZED_TIME);
7478
$expectedLength = chr(15); // YYYYMMDDHHmmSSZ
7579

76-
$object = new GeneralizedTime();
77-
$now = new DateTime();
78-
$now->setTimezone($this->UTC);
80+
$object = new GeneralizedTime($now);
7981
$expectedContent = $now->format('YmdHis').'Z';
8082
$this->assertEquals($expectedType.$expectedLength.$expectedContent, $object->getBinary());
8183

0 commit comments

Comments
 (0)