Skip to content

Commit

Permalink
[11.x] Upgrade to Carbon v3 (#49764)
Browse files Browse the repository at this point in the history
* Upgrade to Carbon v3

* Use float for Carbon ->total* properties

* Make createFromId accepts Uuid and Ulid as per its doc

* Update nesbot/carbon to ^3@dev in illuminate/support

Signed-off-by: Mior Muhammad Zaki <[email protected]>

* Upgrade to nesbot/carbon ^3.0.0-beta.3@beta

---------

Signed-off-by: Mior Muhammad Zaki <[email protected]>
Co-authored-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
kylekatarnls and crynobone authored Jan 24, 2024
1 parent 43f31a1 commit 1c56736
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 34 deletions.
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": "^2.67",
"nesbot/carbon": "^3.0.0-beta.3@beta",
"nunomaduro/termwind": "^2.0",
"psr/container": "^1.1.1|^2.0.1",
"psr/log": "^1.0|^2.0|^3.0",
Expand Down
10 changes: 0 additions & 10 deletions src/Illuminate/Support/Carbon.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
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 @@ -13,15 +12,6 @@ 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, $duration->totalMicroseconds, vsprintf('Unexpected sleep duration of [%s] found.', [
PHPUnit::assertSame(0, (int) $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": "^2.67",
"nesbot/carbon": "^3.0.0-beta.3@beta",
"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($sleep->duration->totalMicroseconds, 90_000_000);
$this->assertSame((float) $sleep->duration->totalMicroseconds, 90_000_000.0);
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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($sleep->duration->totalMicroseconds, 1);
$this->assertSame((float) $sleep->duration->totalMicroseconds, 1.0);
}

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

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

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

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

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

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

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

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

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

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

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

try {
Sleep::assertSlept(fn (CarbonInterval $duration) => $duration->totalSeconds === 5, 2);
Sleep::assertSlept(fn (CarbonInterval $duration) => (float) $duration->totalSeconds === 5.0, 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) => $duration->totalSeconds === 6);
Sleep::assertSlept(fn (CarbonInterval $duration) => (float) $duration->totalSeconds === 6.0);
$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($sleep->duration->totalMicroseconds, 3000000);
$this->assertSame((float) $sleep->duration->totalMicroseconds, 3000000.0);

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

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

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

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

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

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

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

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

public function testItDoesntRunCallbacksWhenNotFaking()
Expand Down

0 comments on commit 1c56736

Please sign in to comment.