File tree Expand file tree Collapse file tree 2 files changed +21
-6
lines changed
src/Symfony/Component/Stopwatch Expand file tree Collapse file tree 2 files changed +21
-6
lines changed Original file line number Diff line number Diff line change @@ -177,12 +177,10 @@ public function getEndTime()
177177 public function getDuration ()
178178 {
179179 $ periods = $ this ->periods ;
180- $ stopped = \count ($ periods );
181- $ left = \count ($ this ->started ) - $ stopped ;
180+ $ left = \count ($ this ->started );
182181
183- for ($ i = 0 ; $ i < $ left ; ++$ i ) {
184- $ index = $ stopped + $ i ;
185- $ periods [] = new StopwatchPeriod ($ this ->started [$ index ], $ this ->getNow (), $ this ->morePrecision );
182+ for ($ i = $ left - 1 ; $ i >= 0 ; --$ i ) {
183+ $ periods [] = new StopwatchPeriod ($ this ->started [$ i ], $ this ->getNow (), $ this ->morePrecision );
186184 }
187185
188186 $ total = 0 ;
Original file line number Diff line number Diff line change @@ -99,8 +99,25 @@ public function testDurationBeforeStop()
9999 $ event ->stop ();
100100 usleep (50000 );
101101 $ event ->start ();
102- usleep (100000 );
103102 $ this ->assertEqualsWithDelta (100 , $ event ->getDuration (), self ::DELTA );
103+ usleep (100000 );
104+ $ this ->assertEqualsWithDelta (200 , $ event ->getDuration (), self ::DELTA );
105+ }
106+
107+ public function testDurationWithMultipleStarts ()
108+ {
109+ $ event = new StopwatchEvent (microtime (true ) * 1000 );
110+ $ event ->start ();
111+ usleep (100000 );
112+ $ event ->start ();
113+ usleep (100000 );
114+ $ this ->assertEqualsWithDelta (300 , $ event ->getDuration (), self ::DELTA );
115+ $ event ->stop ();
116+ $ this ->assertEqualsWithDelta (300 , $ event ->getDuration (), self ::DELTA );
117+ usleep (100000 );
118+ $ this ->assertEqualsWithDelta (400 , $ event ->getDuration (), self ::DELTA );
119+ $ event ->stop ();
120+ $ this ->assertEqualsWithDelta (400 , $ event ->getDuration (), self ::DELTA );
104121 }
105122
106123 public function testStopWithoutStart ()
You can’t perform that action at this time.
0 commit comments