Skip to content

Commit eacaa25

Browse files
authored
Merge pull request #4321 from oleibman/docprop
Tweak One Test
2 parents 949c799 + d5e69e3 commit eacaa25

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

tests/PhpSpreadsheetTests/Document/PropertiesTest.php

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
use DateTimeZone;
99
use PhpOffice\PhpSpreadsheet\Document\Properties;
1010
use PhpOffice\PhpSpreadsheet\Shared\Date;
11+
use PHPUnit\Framework\Attributes\DataProvider;
1112
use PHPUnit\Framework\TestCase;
1213

1314
class PropertiesTest extends TestCase
@@ -16,7 +17,7 @@ class PropertiesTest extends TestCase
1617

1718
private float $startTime;
1819

19-
protected function setup(): void
20+
protected function setUp(): void
2021
{
2122
do {
2223
// loop to avoid rare situation where timestamp changes
@@ -44,12 +45,19 @@ public function testSetCreator(): void
4445
self::assertSame($creator, $this->properties->getCreator());
4546
}
4647

47-
#[\PHPUnit\Framework\Attributes\DataProvider('providerCreationTime')]
48+
#[DataProvider('providerCreationTime')]
4849
public function testSetCreated(null|int $expectedCreationTime, null|int|string $created): void
4950
{
50-
$expectedCreationTime = $expectedCreationTime ?? $this->startTime;
51-
52-
$this->properties->setCreated($created);
51+
if ($expectedCreationTime === null) {
52+
do {
53+
// loop to avoid rare situation where timestamp changes
54+
$expectedCreationTime = (float) (new DateTime())->format('U');
55+
$this->properties->setCreated($created);
56+
$endTime = (float) (new DateTime())->format('U');
57+
} while ($expectedCreationTime !== $endTime);
58+
} else {
59+
$this->properties->setCreated($created);
60+
}
5361
self::assertEquals($expectedCreationTime, $this->properties->getCreated());
5462
}
5563

@@ -71,12 +79,19 @@ public function testSetModifier(): void
7179
self::assertSame($creator, $this->properties->getLastModifiedBy());
7280
}
7381

74-
#[\PHPUnit\Framework\Attributes\DataProvider('providerModifiedTime')]
82+
#[DataProvider('providerModifiedTime')]
7583
public function testSetModified(mixed $expectedModifiedTime, null|int|string $modified): void
7684
{
77-
$expectedModifiedTime = $expectedModifiedTime ?? $this->startTime;
78-
79-
$this->properties->setModified($modified);
85+
if ($expectedModifiedTime === null) {
86+
do {
87+
// loop to avoid rare situation where timestamp changes
88+
$expectedModifiedTime = (float) (new DateTime())->format('U');
89+
$this->properties->setModified($modified);
90+
$endTime = (float) (new DateTime())->format('U');
91+
} while ($expectedModifiedTime !== $endTime);
92+
} else {
93+
$this->properties->setModified($modified);
94+
}
8095
self::assertEquals($expectedModifiedTime, $this->properties->getModified());
8196
}
8297

@@ -146,7 +161,7 @@ public function testSetManager(): void
146161
self::assertSame($manager, $this->properties->getManager());
147162
}
148163

149-
#[\PHPUnit\Framework\Attributes\DataProvider('providerCustomProperties')]
164+
#[DataProvider('providerCustomProperties')]
150165
public function testSetCustomProperties(mixed $expectedType, mixed $expectedValue, string $propertyName, null|bool|float|int|string $propertyValue, ?string $propertyType = null): void
151166
{
152167
if ($propertyType === null) {

0 commit comments

Comments
 (0)