From 173ff7b936674b42e2c976f489577bb29ef90a5b Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Wed, 15 Jan 2025 01:50:39 -0800 Subject: [PATCH] Tweak One Test Fluke failure in CI push. --- .../Document/PropertiesTest.php | 28 ++++++++++++++----- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/tests/PhpSpreadsheetTests/Document/PropertiesTest.php b/tests/PhpSpreadsheetTests/Document/PropertiesTest.php index 7d491d25e6..9a3f787888 100644 --- a/tests/PhpSpreadsheetTests/Document/PropertiesTest.php +++ b/tests/PhpSpreadsheetTests/Document/PropertiesTest.php @@ -16,7 +16,7 @@ class PropertiesTest extends TestCase private float $startTime; - protected function setup(): void + protected function setUp(): void { do { // loop to avoid rare situation where timestamp changes @@ -49,9 +49,16 @@ public function testSetCreator(): void */ public function testSetCreated(null|int $expectedCreationTime, null|int|string $created): void { - $expectedCreationTime = $expectedCreationTime ?? $this->startTime; - - $this->properties->setCreated($created); + if ($expectedCreationTime === null) { + do { + // loop to avoid rare situation where timestamp changes + $expectedCreationTime = (float) (new DateTime())->format('U'); + $this->properties->setCreated($created); + $endTime = (float) (new DateTime())->format('U'); + } while ($expectedCreationTime !== $endTime); + } else { + $this->properties->setCreated($created); + } self::assertEquals($expectedCreationTime, $this->properties->getCreated()); } @@ -78,9 +85,16 @@ public function testSetModifier(): void */ public function testSetModified(mixed $expectedModifiedTime, null|int|string $modified): void { - $expectedModifiedTime = $expectedModifiedTime ?? $this->startTime; - - $this->properties->setModified($modified); + if ($expectedModifiedTime === null) { + do { + // loop to avoid rare situation where timestamp changes + $expectedModifiedTime = (float) (new DateTime())->format('U'); + $this->properties->setModified($modified); + $endTime = (float) (new DateTime())->format('U'); + } while ($expectedModifiedTime !== $endTime); + } else { + $this->properties->setModified($modified); + } self::assertEquals($expectedModifiedTime, $this->properties->getModified()); }