Use DateTimeImmutable in model constructors for DBAL 4.x compatibility

(cherry picked from commit bbb6d00e2f)
This commit is contained in:
Rafikooo 2026-02-06 16:21:16 +01:00 committed by Grzegorz Sadowski
parent 07409b4b80
commit f92ec2b52b
No known key found for this signature in database
GPG key ID: EF87FF4E6E3BD364
42 changed files with 59 additions and 59 deletions

View file

@ -54,7 +54,7 @@ class Address implements AddressInterface
public function __construct()
{
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function getId()

View file

@ -51,7 +51,7 @@ class Attribute implements AttributeInterface, \Stringable
{
$this->initializeTranslationsCollection();
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function __toString(): string

View file

@ -104,7 +104,7 @@ class AttributeTest extends TestCase
public function testCreationDateShouldBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->attribute->setCreatedAt($date);
self::assertSame($date, $this->attribute->getCreatedAt());
}
@ -116,7 +116,7 @@ class AttributeTest extends TestCase
public function testLastUpdateDateShouldBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->attribute->setUpdatedAt($date);
self::assertSame($date, $this->attribute->getUpdatedAt());
}

View file

@ -90,8 +90,8 @@ class AttributeValueTest extends TestCase
'text' => 'Lorem ipsum',
'integer' => 42,
'float' => 6.66,
'datetime' => new \DateTime(),
'date' => new \DateTime(),
'datetime' => new \DateTimeImmutable(),
'date' => new \DateTimeImmutable(),
'json' => ['foo' => 'bar'],
];

View file

@ -40,7 +40,7 @@ class Channel implements ChannelInterface, \Stringable
public function __construct()
{
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function __toString(): string

View file

@ -88,7 +88,7 @@ class ChannelTest extends TestCase
public function testCreationDateShouldBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->channel->setCreatedAt($date);
self::assertSame($date, $this->channel->getCreatedAt());
}
@ -100,7 +100,7 @@ class ChannelTest extends TestCase
public function testLastUpdateDateShouldBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->channel->setUpdatedAt($date);
self::assertSame($date, $this->channel->getUpdatedAt());
}

View file

@ -31,7 +31,7 @@ class OrderItemUnit extends BaseOrderItemUnit implements OrderItemUnitInterface
{
parent::__construct($orderItem);
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function getShipment(): ?BaseShipmentInterface

View file

@ -31,7 +31,7 @@ class Taxon extends BaseTaxon implements TaxonInterface, Comparable
{
parent::__construct();
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
$this->images = new ArrayCollection();
}

View file

@ -30,7 +30,7 @@ final class ChannelPricingLogEntryTest extends TestCase
$this->channelPricing = $this->createMock(ChannelPricingInterface::class);
$this->channelPricingLogEntry = new ChannelPricingLogEntry(
$this->channelPricing,
new \DateTime(),
new \DateTimeImmutable(),
1000,
2000,
);
@ -45,7 +45,7 @@ final class ChannelPricingLogEntryTest extends TestCase
{
$this->channelPricingLogEntry = new ChannelPricingLogEntry(
$this->channelPricing,
new \DateTime(),
new \DateTimeImmutable(),
1000,
null,
);

View file

@ -45,7 +45,7 @@ final class OrderItemUnitTest extends TestCase
$this->productVariant = $this->createMock(ProductVariantInterface::class);
$this->nonNeutralTaxAdjustment = $this->createMock(AdjustmentInterface::class);
$this->neutralTaxAdjustment = $this->createMock(AdjustmentInterface::class);
$this->date = new \DateTime();
$this->date = new \DateTimeImmutable();
$this->orderItemUnit = new OrderItemUnit($this->orderItem);
}

View file

@ -28,7 +28,7 @@ class Currency implements CurrencyInterface, \Stringable
public function __construct()
{
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function __toString(): string

View file

@ -33,7 +33,7 @@ class ExchangeRate implements ExchangeRateInterface
public function __construct()
{
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function getId()

View file

@ -67,7 +67,7 @@ final class CurrencyTest extends TestCase
public function testCreationDateShouldBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->currency->setCreatedAt($date);
self::assertSame($date, $this->currency->getCreatedAt());
}
@ -79,7 +79,7 @@ final class CurrencyTest extends TestCase
public function testLastUpdateDateShouldBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->currency->setUpdatedAt($date);
self::assertSame($date, $this->currency->getUpdatedAt());
}

View file

@ -71,7 +71,7 @@ final class ExchangeRateTest extends TestCase
public function testCreationDateShouldBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->exchangeRate->setCreatedAt($date);
self::assertSame($date, $this->exchangeRate->getCreatedAt());
@ -84,7 +84,7 @@ final class ExchangeRateTest extends TestCase
public function testLastUpdateDateShouldBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->exchangeRate->setUpdatedAt($date);
self::assertSame($date, $this->exchangeRate->getUpdatedAt());

View file

@ -51,7 +51,7 @@ class Customer implements CustomerInterface, \Stringable
public function __construct()
{
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function __toString(): string

View file

@ -28,7 +28,7 @@ class Locale implements LocaleInterface, \Stringable
public function __construct()
{
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function __toString(): string

View file

@ -54,13 +54,13 @@ class Adjustment implements AdjustmentInterface
public function __construct()
{
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function __clone()
{
$this->id = null;
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = null;
}

View file

@ -60,7 +60,7 @@ class Order implements OrderInterface
$this->items = new ArrayCollection();
$this->adjustments = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function getId()
@ -85,7 +85,7 @@ class Order implements OrderInterface
public function completeCheckout(): void
{
$this->checkoutCompletedAt = new \DateTime();
$this->checkoutCompletedAt = new \DateTimeImmutable();
}
public function getNumber(): ?string

View file

@ -295,7 +295,7 @@ final class AdjustmentTest extends TestCase
public function testResetsInternalInformationWhileCloning(): void
{
$this->adjustment->setUpdatedAt(new \DateTime());
$this->adjustment->setUpdatedAt(new \DateTimeImmutable());
$new = clone $this->adjustment;
$this->assertNotSame($new->getCreatedAt(), $this->adjustment->getCreatedAt());

View file

@ -44,7 +44,7 @@ class Payment implements PaymentInterface
public function __construct()
{
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
$this->paymentRequests = new ArrayCollection();
}

View file

@ -44,7 +44,7 @@ class PaymentMethod implements PaymentMethodInterface, \Stringable
{
$this->initializeTranslationsCollection();
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function __toString(): string

View file

@ -36,7 +36,7 @@ class PaymentRequest implements PaymentRequestInterface
protected PaymentInterface $payment,
protected PaymentMethodInterface $method,
) {
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function getId(): ?string

View file

@ -52,7 +52,7 @@ class Product implements ProductInterface, \Stringable
{
$this->initializeTranslationsCollection();
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
$this->attributes = new ArrayCollection();
$this->associations = new ArrayCollection();
$this->variants = new ArrayCollection();

View file

@ -35,8 +35,8 @@ class ProductAssociation implements ProductAssociationInterface
public function __construct()
{
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
$this->associatedProducts = new ArrayCollection();
}

View file

@ -38,8 +38,8 @@ class ProductAssociationType implements ProductAssociationTypeInterface, \String
{
$this->initializeTranslationsCollection();
$this->createdAt = new \DateTime();
$this->updatedAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
$this->updatedAt = new \DateTimeImmutable();
}
public function __toString(): string

View file

@ -44,7 +44,7 @@ class ProductOption implements ProductOptionInterface, \Stringable
$this->initializeTranslationsCollection();
$this->values = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function __toString(): string

View file

@ -48,7 +48,7 @@ class ProductVariant implements ProductVariantInterface
$this->initializeTranslationsCollection();
$this->optionValues = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function getId()

View file

@ -83,7 +83,7 @@ class Promotion implements PromotionInterface
{
$this->initializeTranslationsCollection();
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
$this->coupons = new ArrayCollection();
$this->rules = new ArrayCollection();
$this->actions = new ArrayCollection();

View file

@ -107,7 +107,7 @@ class PromotionCoupon implements PromotionCouponInterface
return false;
}
if (null !== $this->expiresAt && $this->expiresAt < new \DateTime()) {
if (null !== $this->expiresAt && $this->expiresAt < new \DateTimeImmutable()) {
return false;
}

View file

@ -139,7 +139,7 @@ final class PromotionTest extends TestCase
public function testShouldStartsAtDateBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->promotion->setStartsAt($date);
@ -148,7 +148,7 @@ final class PromotionTest extends TestCase
public function testShouldEndsAtDateBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->promotion->setEndsAt($date);

View file

@ -42,7 +42,7 @@ class Review implements ReviewInterface
public function __construct()
{
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function getId()

View file

@ -42,7 +42,7 @@ class Shipment implements ShipmentInterface, \Stringable
public function __construct()
{
$this->units = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function __toString(): string

View file

@ -30,7 +30,7 @@ class ShipmentUnit implements ShipmentUnitInterface, \Stringable
public function __construct()
{
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function __toString(): string

View file

@ -33,7 +33,7 @@ class ShippingCategory implements ShippingCategoryInterface, \Stringable
public function __construct()
{
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function __toString(): string

View file

@ -63,7 +63,7 @@ class ShippingMethod implements ShippingMethodInterface, \Stringable
{
$this->initializeTranslationsCollection();
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
$this->rules = new ArrayCollection();
}

View file

@ -137,7 +137,7 @@ final class ShipmentTest extends TestCase
public function testShouldCreationDateBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->shipment->setCreatedAt($date);
@ -151,7 +151,7 @@ final class ShipmentTest extends TestCase
public function testShouldLastUpdateDateBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->shipment->setUpdatedAt($date);

View file

@ -85,7 +85,7 @@ final class ShipmentUnitTest extends TestCase
public function testShouldCreationDateBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->shipmentUnit->setCreatedAt($date);
@ -99,7 +99,7 @@ final class ShipmentUnitTest extends TestCase
public function testShouldLastUpdateDateBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->shipmentUnit->setUpdatedAt($date);

View file

@ -74,7 +74,7 @@ final class ShippingCategoryTest extends TestCase
public function testShouldCreationDateBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->shippingCategory->setCreatedAt($date);
@ -88,7 +88,7 @@ final class ShippingCategoryTest extends TestCase
public function testShouldLastUpdateDateBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->shippingCategory->setUpdatedAt($date);

View file

@ -171,7 +171,7 @@ final class ShippingMethodTest extends TestCase
public function testShouldCreationDateBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->shippingMethod->setCreatedAt($date);
@ -185,7 +185,7 @@ final class ShippingMethodTest extends TestCase
public function testShouldLastUpdateDateBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->shippingMethod->setUpdatedAt($date);
@ -199,7 +199,7 @@ final class ShippingMethodTest extends TestCase
public function testShouldArchivingDateBeMutable(): void
{
$date = new \DateTime();
$date = new \DateTimeImmutable();
$this->shippingMethod->setArchivedAt($date);

View file

@ -39,7 +39,7 @@ class TaxCategory implements TaxCategoryInterface, \Stringable
public function __construct()
{
$this->rates = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function __toString(): string

View file

@ -46,7 +46,7 @@ class TaxRate implements TaxRateInterface
public function __construct()
{
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
}
public function getId()

View file

@ -92,7 +92,7 @@ class User implements UserInterface, \Stringable
{
$this->oauthAccounts = new ArrayCollection();
$this->createdAt = new \DateTime();
$this->createdAt = new \DateTimeImmutable();
// Set here to overwrite default value from trait
$this->enabled = false;
@ -238,7 +238,7 @@ class User implements UserInterface, \Stringable
return false;
}
$threshold = new \DateTime();
$threshold = new \DateTimeImmutable();
$threshold->sub($ttl);
return $threshold <= $this->passwordRequestedAt;