Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[11.x] Reverts 49764 #49811

Merged
merged 1 commit into from
Jan 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
"league/commonmark": "^2.2.1",
"league/flysystem": "^3.8.0",
"monolog/monolog": "^3.0",
"nesbot/carbon": "^3.0.0-beta.3@beta",
"nesbot/carbon": "^2.67",
"nunomaduro/termwind": "^2.0",
"psr/container": "^1.1.1|^2.0.1",
"psr/log": "^1.0|^2.0|^3.0",
Expand Down
10 changes: 10 additions & 0 deletions src/Illuminate/Support/Carbon.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Illuminate\Support;

use Carbon\Carbon as BaseCarbon;
use Carbon\CarbonImmutable as BaseCarbonImmutable;
use Illuminate\Support\Traits\Conditionable;
use Illuminate\Support\Traits\Dumpable;
use Ramsey\Uuid\Uuid;
Expand All @@ -12,6 +13,15 @@ class Carbon extends BaseCarbon
{
use Conditionable, Dumpable;

/**
* {@inheritdoc}
*/
public static function setTestNow($testNow = null)
{
BaseCarbon::setTestNow($testNow);
BaseCarbonImmutable::setTestNow($testNow);
}

/**
* Create a Carbon instance from a given ordered UUID or ULID.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Sleep.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ public static function assertInsomniac()
}

foreach (static::$sequence as $duration) {
PHPUnit::assertSame(0, (int) $duration->totalMicroseconds, vsprintf('Unexpected sleep duration of [%s] found.', [
PHPUnit::assertSame(0, $duration->totalMicroseconds, vsprintf('Unexpected sleep duration of [%s] found.', [
$duration->cascade()->forHumans([
'options' => 0,
'minimumUnit' => 'microsecond',
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Support/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"illuminate/conditionable": "^11.0",
"illuminate/contracts": "^11.0",
"illuminate/macroable": "^11.0",
"nesbot/carbon": "^3.0.0-beta.3@beta",
"nesbot/carbon": "^2.67",
"voku/portable-ascii": "^2.0"
},
"conflict": {
Expand Down
42 changes: 21 additions & 21 deletions tests/Support/SleepTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public function testItCanSpecifyMinutes()

$sleep = Sleep::for(1.5)->minutes();

$this->assertSame((float) $sleep->duration->totalMicroseconds, 90_000_000.0);
$this->assertSame($sleep->duration->totalMicroseconds, 90_000_000);
}

public function testItCanSpecifyMinute()
Expand All @@ -65,7 +65,7 @@ public function testItCanSpecifyMinute()

$sleep = Sleep::for(1)->minute();

$this->assertSame((float) $sleep->duration->totalMicroseconds, 60_000_000.0);
$this->assertSame($sleep->duration->totalMicroseconds, 60_000_000);
}

public function testItCanSpecifySeconds()
Expand All @@ -74,7 +74,7 @@ public function testItCanSpecifySeconds()

$sleep = Sleep::for(1.5)->seconds();

$this->assertSame((float) $sleep->duration->totalMicroseconds, 1_500_000.0);
$this->assertSame($sleep->duration->totalMicroseconds, 1_500_000);
}

public function testItCanSpecifySecond()
Expand All @@ -83,7 +83,7 @@ public function testItCanSpecifySecond()

$sleep = Sleep::for(1)->second();

$this->assertSame((float) $sleep->duration->totalMicroseconds, 1_000_000.0);
$this->assertSame($sleep->duration->totalMicroseconds, 1_000_000);
}

public function testItCanSpecifyMilliseconds()
Expand All @@ -92,7 +92,7 @@ public function testItCanSpecifyMilliseconds()

$sleep = Sleep::for(1.5)->milliseconds();

$this->assertSame((float) $sleep->duration->totalMicroseconds, 1_500.0);
$this->assertSame($sleep->duration->totalMicroseconds, 1_500);
}

public function testItCanSpecifyMillisecond()
Expand All @@ -101,7 +101,7 @@ public function testItCanSpecifyMillisecond()

$sleep = Sleep::for(1)->millisecond();

$this->assertSame((float) $sleep->duration->totalMicroseconds, 1_000.0);
$this->assertSame($sleep->duration->totalMicroseconds, 1_000);
}

public function testItCanSpecifyMicroseconds()
Expand All @@ -111,7 +111,7 @@ public function testItCanSpecifyMicroseconds()
$sleep = Sleep::for(1.5)->microseconds();

// rounded as microseconds is the smallest unit supported...
$this->assertSame((float) $sleep->duration->totalMicroseconds, 1.0);
$this->assertSame($sleep->duration->totalMicroseconds, 1);
}

public function testItCanSpecifyMicrosecond()
Expand All @@ -120,7 +120,7 @@ public function testItCanSpecifyMicrosecond()

$sleep = Sleep::for(1)->microsecond();

$this->assertSame((float) $sleep->duration->totalMicroseconds, 1.0);
$this->assertSame($sleep->duration->totalMicroseconds, 1);
}

public function testItCanChainDurations()
Expand All @@ -130,7 +130,7 @@ public function testItCanChainDurations()
$sleep = Sleep::for(1)->second()
->and(500)->microseconds();

$this->assertSame((float) $sleep->duration->totalMicroseconds, 1000500.0);
$this->assertSame($sleep->duration->totalMicroseconds, 1000500);
}

public function testItCanUseDateInterval()
Expand All @@ -139,7 +139,7 @@ public function testItCanUseDateInterval()

$sleep = Sleep::for(CarbonInterval::seconds(1)->addMilliseconds(5));

$this->assertSame((float) $sleep->duration->totalMicroseconds, 1_005_000.0);
$this->assertSame($sleep->duration->totalMicroseconds, 1_005_000);
}

public function testItThrowsForUnknownTimeUnit()
Expand Down Expand Up @@ -425,17 +425,17 @@ public function testAssertSlept()

Sleep::for(5)->seconds();

Sleep::assertSlept(fn (CarbonInterval $duration) => (float) $duration->totalSeconds === 5.0);
Sleep::assertSlept(fn (CarbonInterval $duration) => $duration->totalSeconds === 5);

try {
Sleep::assertSlept(fn (CarbonInterval $duration) => (float) $duration->totalSeconds === 5.0, 2);
Sleep::assertSlept(fn (CarbonInterval $duration) => $duration->totalSeconds === 5, 2);
$this->fail();
} catch (AssertionFailedError $e) {
$this->assertSame("The expected sleep was found [1] times instead of [2].\nFailed asserting that 1 is identical to 2.", $e->getMessage());
}

try {
Sleep::assertSlept(fn (CarbonInterval $duration) => (float) $duration->totalSeconds === 6.0);
Sleep::assertSlept(fn (CarbonInterval $duration) => $duration->totalSeconds === 6);
$this->fail();
} catch (AssertionFailedError $e) {
$this->assertSame("The expected sleep was found [0] times instead of [1].\nFailed asserting that 0 is identical to 1.", $e->getMessage());
Expand All @@ -462,15 +462,15 @@ public function testItCanCreateMacrosViaMacroable()

// A static macro can be referenced
$sleep = Sleep::forSomeConfiguredAmountOfTime();
$this->assertSame((float) $sleep->duration->totalMicroseconds, 3000000.0);
$this->assertSame($sleep->duration->totalMicroseconds, 3000000);

// A macro can specify a new duration
$sleep = $sleep->useSomeOtherAmountOfTime();
$this->assertSame((float) $sleep->duration->totalMicroseconds, 1234000.0);
$this->assertSame($sleep->duration->totalMicroseconds, 1234000);

// A macro can supplement an existing duration
$sleep = $sleep->andSomeMoreGranularControl();
$this->assertSame((float) $sleep->duration->totalMicroseconds, 1234567.0);
$this->assertSame($sleep->duration->totalMicroseconds, 1234567);
}

public function testItCanReplacePreviouslyDefinedDurations()
Expand All @@ -482,13 +482,13 @@ public function testItCanReplacePreviouslyDefinedDurations()
});

$sleep = Sleep::for(1)->second();
$this->assertSame((float) $sleep->duration->totalMicroseconds, 1000000.0);
$this->assertSame($sleep->duration->totalMicroseconds, 1000000);

$sleep->setDuration(2)->second();
$this->assertSame((float) $sleep->duration->totalMicroseconds, 2000000.0);
$this->assertSame($sleep->duration->totalMicroseconds, 2000000);

$sleep->setDuration(500)->milliseconds();
$this->assertSame((float) $sleep->duration->totalMicroseconds, 500000.0);
$this->assertSame($sleep->duration->totalMicroseconds, 500000);
}

public function testItCanSleepConditionallyWhen()
Expand Down Expand Up @@ -549,8 +549,8 @@ public function testItCanRegisterCallbacksToRunInTests()
Sleep::for(2)->millisecond(),
]);

$this->assertSame(3.0, (float) $countA);
$this->assertSame(3.0, (float) $countB);
$this->assertSame(3, $countA);
$this->assertSame(3, $countB);
}

public function testItDoesntRunCallbacksWhenNotFaking()
Expand Down
Loading