8
8
use DateTimeZone ;
9
9
use PhpOffice \PhpSpreadsheet \Document \Properties ;
10
10
use PhpOffice \PhpSpreadsheet \Shared \Date ;
11
+ use PHPUnit \Framework \Attributes \DataProvider ;
11
12
use PHPUnit \Framework \TestCase ;
12
13
13
14
class PropertiesTest extends TestCase
@@ -16,7 +17,7 @@ class PropertiesTest extends TestCase
16
17
17
18
private float $ startTime ;
18
19
19
- protected function setup (): void
20
+ protected function setUp (): void
20
21
{
21
22
do {
22
23
// loop to avoid rare situation where timestamp changes
@@ -44,12 +45,19 @@ public function testSetCreator(): void
44
45
self ::assertSame ($ creator , $ this ->properties ->getCreator ());
45
46
}
46
47
47
- #[\ PHPUnit \ Framework \ Attributes \ DataProvider('providerCreationTime ' )]
48
+ #[DataProvider('providerCreationTime ' )]
48
49
public function testSetCreated (null |int $ expectedCreationTime , null |int |string $ created ): void
49
50
{
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
+ }
53
61
self ::assertEquals ($ expectedCreationTime , $ this ->properties ->getCreated ());
54
62
}
55
63
@@ -71,12 +79,19 @@ public function testSetModifier(): void
71
79
self ::assertSame ($ creator , $ this ->properties ->getLastModifiedBy ());
72
80
}
73
81
74
- #[\ PHPUnit \ Framework \ Attributes \ DataProvider('providerModifiedTime ' )]
82
+ #[DataProvider('providerModifiedTime ' )]
75
83
public function testSetModified (mixed $ expectedModifiedTime , null |int |string $ modified ): void
76
84
{
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
+ }
80
95
self ::assertEquals ($ expectedModifiedTime , $ this ->properties ->getModified ());
81
96
}
82
97
@@ -146,7 +161,7 @@ public function testSetManager(): void
146
161
self ::assertSame ($ manager , $ this ->properties ->getManager ());
147
162
}
148
163
149
- #[\ PHPUnit \ Framework \ Attributes \ DataProvider('providerCustomProperties ' )]
164
+ #[DataProvider('providerCustomProperties ' )]
150
165
public function testSetCustomProperties (mixed $ expectedType , mixed $ expectedValue , string $ propertyName , null |bool |float |int |string $ propertyValue , ?string $ propertyType = null ): void
151
166
{
152
167
if ($ propertyType === null ) {
0 commit comments