File tree Expand file tree Collapse file tree 2 files changed +10
-11
lines changed
Expand file tree Collapse file tree 2 files changed +10
-11
lines changed Original file line number Diff line number Diff line change @@ -33,11 +33,7 @@ public function record(Measurable $metric): void
3333 */
3434 public function commit (): int
3535 {
36- $ count = count ($ this ->recorded );
37-
38- $ this ->recorded = [];
39-
40- return $ count ;
36+ return count ($ this ->recorded );
4137 }
4238
4339 /**
Original file line number Diff line number Diff line change 123123 expect ($ recorded ->count ())->toBe (2 );
124124});
125125
126- it ('commit clears recorded metrics ' , function () {
126+ it ('commit returns count of recorded metrics ' , function () {
127127 $ fake = new MetricFake ;
128128
129129 $ fake ->record (new MetricData ('page_views ' ));
130130 $ fake ->record (new MetricData ('api_calls ' ));
131131
132132 expect ($ fake ->recorded ()->count ())->toBe (2 );
133133
134- $ fake ->commit ();
134+ $ count = $ fake ->commit ();
135135
136- expect ($ fake ->recorded ()->count ())->toBe (0 );
136+ expect ($ count )->toBe (2 )
137+ ->and ($ fake ->recorded ()->count ())->toBe (2 );
137138});
138139
139140it ('can start capturing ' , function () {
245246 $ fake = new MetricFake ;
246247
247248 $ fake ->record (new MetricData ('page_views ' ));
248- $ fake ->commit ();
249249
250- expect ($ fake ->recorded ()->count ())->toBe (0 );
250+ $ count = $ fake ->commit ();
251+
252+ expect ($ count )->toBe (1 )
253+ ->and ($ fake ->recorded ()->count ())->toBe (1 );
251254
252255 $ fake ->record (new MetricData ('api_calls ' ));
253256
254- expect ($ fake ->recorded ()->count ())->toBe (1 );
257+ expect ($ fake ->recorded ()->count ())->toBe (2 );
255258});
256259
257260it ('assertion fails when metric not recorded ' , function () {
You can’t perform that action at this time.
0 commit comments