From b9da9aaeca682911c425a69a2a7553db829601be Mon Sep 17 00:00:00 2001 From: oleibman <10341515+oleibman@users.noreply.github.com> Date: Wed, 15 Jan 2025 01:47:54 -0800 Subject: [PATCH] Tweak One Test Fluke failure in CI push. --- .../Document/PropertiesTest.php | 27 ++++++++++++++----- 1 file changed, 21 insertions(+), 6 deletions(-) diff --git a/tests/PhpSpreadsheetTests/Document/PropertiesTest.php b/tests/PhpSpreadsheetTests/Document/PropertiesTest.php index c8e10e3817..84cb6d8e66 100644 --- a/tests/PhpSpreadsheetTests/Document/PropertiesTest.php +++ b/tests/PhpSpreadsheetTests/Document/PropertiesTest.php @@ -18,7 +18,7 @@ class PropertiesTest extends TestCase /** @var float */ private $startTime; - protected function setup(): void + protected function setUp(): void { do { // loop to avoid rare situation where timestamp changes @@ -54,9 +54,16 @@ public function testSetCreator(): void */ public function testSetCreated($expectedCreationTime, $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()); } @@ -86,9 +93,17 @@ public function testSetModifier(): void */ public function testSetModified($expectedModifiedTime, $modified): void { - $expectedModifiedTime = $expectedModifiedTime ?? $this->startTime; + 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); + } - $this->properties->setModified($modified); self::assertEquals($expectedModifiedTime, $this->properties->getModified()); }