File tree 2 files changed +30
-1
lines changed
src/Symfony/Component/Stopwatch
2 files changed +30
-1
lines changed Original file line number Diff line number Diff line change @@ -154,7 +154,15 @@ public function getPeriods()
154
154
*/
155
155
public function getStartTime ()
156
156
{
157
- return isset ($ this ->periods [0 ]) ? $ this ->periods [0 ]->getStartTime () : 0 ;
157
+ if (isset ($ this ->periods [0 ])) {
158
+ return $ this ->periods [0 ]->getStartTime ();
159
+ }
160
+
161
+ if ($ this ->started ) {
162
+ return $ this ->started [0 ];
163
+ }
164
+
165
+ return 0 ;
158
166
}
159
167
160
168
/**
Original file line number Diff line number Diff line change @@ -152,6 +152,27 @@ public function testStartTime()
152
152
$ this ->assertEqualsWithDelta (0 , $ event ->getStartTime (), self ::DELTA );
153
153
}
154
154
155
+ public function testStartTimeWhenStartedLater ()
156
+ {
157
+ $ event = new StopwatchEvent (microtime (true ) * 1000 );
158
+ usleep (100000 );
159
+ $ this ->assertLessThanOrEqual (0.5 , $ event ->getStartTime ());
160
+
161
+ $ event = new StopwatchEvent (microtime (true ) * 1000 );
162
+ usleep (100000 );
163
+ $ event ->start ();
164
+ $ event ->stop ();
165
+ $ this ->assertLessThanOrEqual (101 , $ event ->getStartTime ());
166
+
167
+ $ event = new StopwatchEvent (microtime (true ) * 1000 );
168
+ usleep (100000 );
169
+ $ event ->start ();
170
+ usleep (100000 );
171
+ $ this ->assertEqualsWithDelta (100 , $ event ->getStartTime (), self ::DELTA );
172
+ $ event ->stop ();
173
+ $ this ->assertEqualsWithDelta (100 , $ event ->getStartTime (), self ::DELTA );
174
+ }
175
+
155
176
public function testInvalidOriginThrowsAnException ()
156
177
{
157
178
$ this ->expectException ('InvalidArgumentException ' );
You can’t perform that action at this time.
0 commit comments