From 7dcd191721ce0a996ed7e8803efdfa7810983483 Mon Sep 17 00:00:00 2001 From: Nuno Maduro Date: Wed, 24 Jan 2024 16:51:42 +0000 Subject: [PATCH] Revert "[11.x] Upgrade to Carbon v3 (#49764)" (#49811) This reverts commit 1c56736552d0ae1f6c756aa6000063e6e46aeb1e. --- composer.json | 2 +- src/Illuminate/Support/Carbon.php | 10 +++++++ src/Illuminate/Support/Sleep.php | 2 +- src/Illuminate/Support/composer.json | 2 +- tests/Support/SleepTest.php | 42 ++++++++++++++-------------- 5 files changed, 34 insertions(+), 24 deletions(-) diff --git a/composer.json b/composer.json index 928413721682..ed7c62f8f35b 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/src/Illuminate/Support/Carbon.php b/src/Illuminate/Support/Carbon.php index f3a9240e75e2..a88a124bb441 100644 --- a/src/Illuminate/Support/Carbon.php +++ b/src/Illuminate/Support/Carbon.php @@ -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; @@ -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. * diff --git a/src/Illuminate/Support/Sleep.php b/src/Illuminate/Support/Sleep.php index 48646cde33f7..cd32d7f479c5 100644 --- a/src/Illuminate/Support/Sleep.php +++ b/src/Illuminate/Support/Sleep.php @@ -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', diff --git a/src/Illuminate/Support/composer.json b/src/Illuminate/Support/composer.json index 007e7706ae7d..91c70ef58dd4 100644 --- a/src/Illuminate/Support/composer.json +++ b/src/Illuminate/Support/composer.json @@ -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": { diff --git a/tests/Support/SleepTest.php b/tests/Support/SleepTest.php index a8d631d4fede..d43b96a0d7f7 100644 --- a/tests/Support/SleepTest.php +++ b/tests/Support/SleepTest.php @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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() @@ -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()); @@ -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() @@ -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() @@ -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()