activitypub-php/test/TestUtils/TestDateTimeProvider.php

33 lines
748 B
PHP
Raw Normal View History

2019-02-14 03:27:47 +00:00
<?php /** @noinspection PhpUnhandledExceptionInspection */
2018-12-11 16:56:23 +00:00
namespace ActivityPub\Test\TestUtils;
use ActivityPub\Utils\DateTimeProvider;
2019-02-16 17:51:24 +00:00
use DateTime;
2018-12-11 16:56:23 +00:00
/**
* A DateTimeProvider that returns fixed values for create and update times
*/
class TestDateTimeProvider implements DateTimeProvider
{
protected $context;
2018-12-11 16:56:23 +00:00
/**
* @param array $context An array mapping context strings to DateTime instances
*/
public function __construct( $context )
2018-12-11 16:56:23 +00:00
{
$this->context = $context;
2018-12-11 16:56:23 +00:00
}
2019-02-16 17:51:24 +00:00
2018-12-11 16:56:23 +00:00
public function getTime( $context = '' )
{
2019-02-16 17:51:24 +00:00
if ( array_key_exists( $context, $this->context ) ) {
return $this->context[$context];
2018-12-11 16:56:23 +00:00
} else {
return new DateTime( 'now' );
}
}
}