mirror of
https://github.com/Sylius/Sylius.git
synced 2026-07-05 20:57:12 +00:00
Use DateTimeImmutable in model constructors for DBAL 4.x compatibility
(cherry picked from commit bbb6d00e2f)
This commit is contained in:
parent
07409b4b80
commit
f92ec2b52b
42 changed files with 59 additions and 59 deletions
|
|
@ -54,7 +54,7 @@ class Address implements AddressInterface
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTime();
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
public function getId()
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class Attribute implements AttributeInterface, \Stringable
|
|||
{
|
||||
$this->initializeTranslationsCollection();
|
||||
|
||||
$this->createdAt = new \DateTime();
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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'],
|
||||
];
|
||||
|
||||
|
|
|
|||
|
|
@ -40,7 +40,7 @@ class Channel implements ChannelInterface, \Stringable
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTime();
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class Currency implements CurrencyInterface, \Stringable
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTime();
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class ExchangeRate implements ExchangeRateInterface
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTime();
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
public function getId()
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ class Customer implements CustomerInterface, \Stringable
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTime();
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ class Locale implements LocaleInterface, \Stringable
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTime();
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class Payment implements PaymentInterface
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTime();
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
$this->paymentRequests = new ArrayCollection();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -44,7 +44,7 @@ class PaymentMethod implements PaymentMethodInterface, \Stringable
|
|||
{
|
||||
$this->initializeTranslationsCollection();
|
||||
|
||||
$this->createdAt = new \DateTime();
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ class Review implements ReviewInterface
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTime();
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
public function getId()
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ class ShipmentUnit implements ShipmentUnitInterface, \Stringable
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTime();
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@ class ShippingCategory implements ShippingCategoryInterface, \Stringable
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTime();
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
public function __toString(): string
|
||||
|
|
|
|||
|
|
@ -63,7 +63,7 @@ class ShippingMethod implements ShippingMethodInterface, \Stringable
|
|||
{
|
||||
$this->initializeTranslationsCollection();
|
||||
|
||||
$this->createdAt = new \DateTime();
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
$this->rules = new ArrayCollection();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ class TaxRate implements TaxRateInterface
|
|||
|
||||
public function __construct()
|
||||
{
|
||||
$this->createdAt = new \DateTime();
|
||||
$this->createdAt = new \DateTimeImmutable();
|
||||
}
|
||||
|
||||
public function getId()
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue