Aggiornato Composer
This commit is contained in:
32
vendor/nesbot/carbon/src/Carbon/Traits/Test.php
vendored
32
vendor/nesbot/carbon/src/Carbon/Traits/Test.php
vendored
@@ -28,7 +28,7 @@ trait Test
|
||||
/**
|
||||
* A test Carbon instance to be returned when now instances are created.
|
||||
*
|
||||
* @var static
|
||||
* @var Closure|static|null
|
||||
*/
|
||||
protected static $testNow;
|
||||
|
||||
@@ -59,15 +59,13 @@ trait Test
|
||||
*
|
||||
* /!\ Use this method for unit tests only.
|
||||
*
|
||||
* @param Closure|static|string|false|null $testNow real or mock Carbon instance
|
||||
* @param DateTimeInterface|Closure|static|string|false|null $testNow real or mock Carbon instance
|
||||
*/
|
||||
public static function setTestNow($testNow = null)
|
||||
{
|
||||
if ($testNow === false) {
|
||||
$testNow = null;
|
||||
}
|
||||
|
||||
static::$testNow = \is_string($testNow) ? static::parse($testNow) : $testNow;
|
||||
static::$testNow = $testNow instanceof self || $testNow instanceof Closure
|
||||
? $testNow
|
||||
: static::make($testNow);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -87,7 +85,7 @@ trait Test
|
||||
*
|
||||
* /!\ Use this method for unit tests only.
|
||||
*
|
||||
* @param Closure|static|string|false|null $testNow real or mock Carbon instance
|
||||
* @param DateTimeInterface|Closure|static|string|false|null $testNow real or mock Carbon instance
|
||||
*/
|
||||
public static function setTestNowAndTimezone($testNow = null, $tz = null)
|
||||
{
|
||||
@@ -121,16 +119,22 @@ trait Test
|
||||
*
|
||||
* /!\ Use this method for unit tests only.
|
||||
*
|
||||
* @param Closure|static|string|false|null $testNow real or mock Carbon instance
|
||||
* @param Closure|null $callback
|
||||
* @template T
|
||||
*
|
||||
* @return mixed
|
||||
* @param DateTimeInterface|Closure|static|string|false|null $testNow real or mock Carbon instance
|
||||
* @param Closure(): T $callback
|
||||
*
|
||||
* @return T
|
||||
*/
|
||||
public static function withTestNow($testNow = null, $callback = null)
|
||||
public static function withTestNow($testNow, $callback)
|
||||
{
|
||||
static::setTestNow($testNow);
|
||||
$result = $callback();
|
||||
static::setTestNow();
|
||||
|
||||
try {
|
||||
$result = $callback();
|
||||
} finally {
|
||||
static::setTestNow();
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user