Skip to content

Commit eaf8de1

Browse files
pauljuracourtney-miles
authored andcommitted
chore(deps): allow nesbot/carbon 3.x for Symfony 7 translation support
Carbon 2.x caps symfony/translation at ^6.0, which blocks consumers from upgrading to Symfony 7. Carbon 3.x allows symfony/translation ^7.0 || ^8.0, so widening the constraint to ^2.63.0 || ^3.0 unblocks Symfony 7 upgrades without breaking existing Carbon 2.x consumers. Changes: - composer.json: widen nesbot/carbon to ^2.63.0 || ^3.0 - DateField/DatetimeField/TimeField: reject non-string, non-DateTimeInterface inputs. Carbon 3.x is more permissive than 2.x and treats bool/int values as Unix timestamps, which silently accepted invalid input (e.g. true). DurationField already had this guard. - FieldTypesTest: compare CarbonInterval by spec() instead of whole-object assertEquals. Carbon 3.x changed internal CarbonInterval properties (originalInput) breaking whole-object comparison. The interval values are identical; only the internal Carbon state differs. All 148 tests pass with both Carbon 2.73.0 and Carbon 3.13.1.
1 parent 8410c09 commit eaf8de1

5 files changed

Lines changed: 21 additions & 2 deletions

File tree

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
"ext-mbstring": "*",
88
"ext-json": "*",
99
"justinrainbow/json-schema": "^5.2.10",
10-
"nesbot/carbon": "^2.63.0",
10+
"nesbot/carbon": "^2.63.0 || ^3.0",
1111
"jmikola/geojson": "^1.0"
1212
},
1313
"require-dev": {

src/Fields/DateField.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ class DateField extends BaseField
1111

1212
protected function validateCastValue($val)
1313
{
14+
if (!is_string($val) && !$val instanceof \DateTimeInterface) {
15+
throw $this->getValidationException('must be string or datetime', $val);
16+
}
17+
1418
if ('any' === $this->format()) {
1519
try {
1620
$date = new Carbon($val);

src/Fields/DatetimeField.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ class DatetimeField extends BaseField
99
{
1010
protected function validateCastValue($val)
1111
{
12+
if (!is_string($val) && !$val instanceof \DateTimeInterface) {
13+
throw $this->getValidationException('must be string or datetime', $val);
14+
}
15+
1216
$val = trim($val);
1317
switch ($this->format()) {
1418
case 'default':

src/Fields/TimeField.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ class TimeField extends BaseField
1313
{
1414
protected function validateCastValue($val)
1515
{
16+
if (!is_string($val) && !$val instanceof \DateTimeInterface) {
17+
throw $this->getValidationException('must be string or datetime', $val);
18+
}
19+
1620
switch ($this->format()) {
1721
case 'default':
1822
$time = explode(':', $val);

tests/FieldTypesTest.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -579,7 +579,14 @@ protected function assertFieldTestData($fieldType, $testData): void
579579
if (self::ERROR === $expectedCastValue) {
580580
$this->assertNotEmpty($field->validateValue($inputValue), $assertMessage);
581581
} elseif (is_object($expectedCastValue)) {
582-
$this->assertEquals($expectedCastValue, $field->castValue($inputValue), $assertMessage);
582+
$castValue = $field->castValue($inputValue);
583+
if ($expectedCastValue instanceof CarbonInterval && $castValue instanceof CarbonInterval) {
584+
// Carbon 3.x changed internal CarbonInterval properties (e.g. originalInput),
585+
// breaking whole-object comparison. Compare the ISO 8601 spec instead.
586+
$this->assertEquals($expectedCastValue->spec(), $castValue->spec(), $assertMessage);
587+
} else {
588+
$this->assertEquals($expectedCastValue, $castValue, $assertMessage);
589+
}
583590
} else {
584591
$this->assertSame($expectedCastValue, $field->castValue($inputValue), $assertMessage);
585592
}

0 commit comments

Comments
 (0)