diff --git a/src/JWT.php b/src/JWT.php index f6a4772c..843d0ae0 100644 --- a/src/JWT.php +++ b/src/JWT.php @@ -41,6 +41,15 @@ class JWT */ public static $leeway = 0; + /** + * Allow the current timestamp to be specified. + * Useful for fixing a value within unit testing. + * Will default to PHP time() value if null. + * + * @var ?int + */ + public static $timestamp = null; + /** * @var array */ @@ -84,7 +93,7 @@ public static function decode( $keyOrKeyArray ): stdClass { // Validate JWT - $timestamp = \time(); + $timestamp = \is_null(static::$timestamp) ? \time() : static::$timestamp; if (empty($keyOrKeyArray)) { throw new InvalidArgumentException('Key may not be empty');