Skip to content

Commit f0761ca

Browse files
WebMambafabpot
authored andcommitted
Ban DateTime from the codebase
1 parent 7c182b9 commit f0761ca

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

Tests/OptionsResolverTest.php

+11-11
Original file line numberDiff line numberDiff line change
@@ -777,11 +777,11 @@ public function testFailIfSetAllowedTypesFromLazyOption()
777777
public function testResolveFailsIfInvalidTypedArray()
778778
{
779779
$this->expectException(InvalidOptionsException::class);
780-
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[]", but one of the elements is of type "DateTime".');
780+
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[]", but one of the elements is of type "DateTimeImmutable".');
781781
$this->resolver->setDefined('foo');
782782
$this->resolver->setAllowedTypes('foo', 'int[]');
783783

784-
$this->resolver->resolve(['foo' => [new \DateTime()]]);
784+
$this->resolver->resolve(['foo' => [new \DateTimeImmutable()]]);
785785
}
786786

787787
public function testResolveFailsWithNonArray()
@@ -797,13 +797,13 @@ public function testResolveFailsWithNonArray()
797797
public function testResolveFailsIfTypedArrayContainsInvalidTypes()
798798
{
799799
$this->expectException(InvalidOptionsException::class);
800-
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[]", but one of the elements is of type "stdClass|array|DateTime".');
800+
$this->expectExceptionMessage('The option "foo" with value array is expected to be of type "int[]", but one of the elements is of type "stdClass|array|DateTimeImmutable".');
801801
$this->resolver->setDefined('foo');
802802
$this->resolver->setAllowedTypes('foo', 'int[]');
803803
$values = range(1, 5);
804804
$values[] = new \stdClass();
805805
$values[] = [];
806-
$values[] = new \DateTime();
806+
$values[] = new \DateTimeImmutable();
807807
$values[] = 123;
808808

809809
$this->resolver->resolve(['foo' => $values]);
@@ -893,12 +893,12 @@ public function testResolveSucceedsIfInstanceOfClass()
893893
public function testResolveSucceedsIfTypedArray()
894894
{
895895
$this->resolver->setDefault('foo', null);
896-
$this->resolver->setAllowedTypes('foo', ['null', 'DateTime[]']);
896+
$this->resolver->setAllowedTypes('foo', ['null', 'DateTimeImmutable[]']);
897897

898898
$data = [
899899
'foo' => [
900-
new \DateTime(),
901-
new \DateTime(),
900+
new \DateTimeImmutable(),
901+
new \DateTimeImmutable(),
902902
],
903903
];
904904
$result = $this->resolver->resolve($data);
@@ -2467,18 +2467,18 @@ public function testGetInfoOnUndefinedOption2()
24672467
public function testInfoOnInvalidValue()
24682468
{
24692469
$this->expectException(InvalidOptionsException::class);
2470-
$this->expectExceptionMessage('The option "expires" with value DateTime is invalid. Info: A future date time.');
2470+
$this->expectExceptionMessage('The option "expires" with value DateTimeImmutable is invalid. Info: A future date time.');
24712471

24722472
$this->resolver
24732473
->setRequired('expires')
24742474
->setInfo('expires', 'A future date time')
2475-
->setAllowedTypes('expires', \DateTime::class)
2475+
->setAllowedTypes('expires', \DateTimeImmutable::class)
24762476
->setAllowedValues('expires', static function ($value) {
2477-
return $value >= new \DateTime('now');
2477+
return $value >= new \DateTimeImmutable('now');
24782478
})
24792479
;
24802480

2481-
$this->resolver->resolve(['expires' => new \DateTime('-1 hour')]);
2481+
$this->resolver->resolve(['expires' => new \DateTimeImmutable('-1 hour')]);
24822482
}
24832483

24842484
public function testInvalidValueForPrototypeDefinition()

0 commit comments

Comments
 (0)