File tree Expand file tree Collapse file tree
Fails/WithoutComparisonsTest Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55namespace DragonCode \Benchmark ;
66
77use Closure ;
8+ use DragonCode \Benchmark \Exceptions \NoComparisonsException ;
89use DragonCode \Benchmark \Services \AssertService ;
910use DragonCode \Benchmark \Services \CallbacksService ;
1011use DragonCode \Benchmark \Services \CollectorService ;
@@ -133,22 +134,26 @@ public function toData(): array
133134 return $ this ->mapResult ();
134135 }
135136
136- public function toConsole (): static
137+ public function toConsole (): void
137138 {
138- $ table = $ this ->transformer ->toTable (
139- $ this ->toData ()
140- );
139+ if (! $ data = $ this ->toData ()) {
140+ $ this ->view ->line ('[INFO] No comparisons were made. ' );
141141
142- $ this ->view ->table ($ table );
142+ return ;
143+ }
143144
144- return $ this ;
145+ $ this ->view ->table (
146+ $ this ->transformer ->toTable ($ data )
147+ );
145148 }
146149
147150 public function toAssert (): AssertService
148151 {
149- return new AssertService (
150- $ this ->toData ()
151- );
152+ if (! $ data = $ this ->toData ()) {
153+ throw new NoComparisonsException ;
154+ }
155+
156+ return new AssertService ($ data );
152157 }
153158
154159 protected function perform (): void
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace DragonCode \Benchmark \Exceptions ;
6+
7+ use RuntimeException ;
8+
9+ class NoComparisonsException extends RuntimeException
10+ {
11+ public function __construct ()
12+ {
13+ parent ::__construct ('Method "compare" was not called. No comparisons were made. ' );
14+ }
15+ }
Original file line number Diff line number Diff line change @@ -26,6 +26,11 @@ public function progressBar(): ProgressBarView
2626 return $ this ->progressBar ;
2727 }
2828
29+ public function line (string $ text ): void
30+ {
31+ $ this ->line ->line ($ text );
32+ }
33+
2934 public function emptyLine (int $ count = 1 ): void
3035 {
3136 $ this ->line ->newLine ($ count );
Original file line number Diff line number Diff line change 66
77class LineView extends View
88{
9+ public function line (string $ text ): void
10+ {
11+ $ this ->writeLine ($ text );
12+ }
13+
914 public function newLine (int $ count = 1 ): void
1015 {
1116 for ($ i = 0 ; $ i < $ count ; $ i ++) {
Original file line number Diff line number Diff line change 1+
2+ 0 / 1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0 % 1 / 1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100 %
3+
4+
5+ [INFO ] No comparisons were made .
Original file line number Diff line number Diff line change 1+
2+ 0 / 1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0 % 1 / 1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100 %
3+
4+
5+ ┌───────┬────────────────────┬───────────────────┐
6+ │ # │ 0 │ 1 │
7+ ├───────┼────────────────────┼───────────────────┤
8+ │ min │ 16 ms - 202 bytes │ 2 ms - 102 bytes │
9+ │ max │ 113 ms - 209 bytes │ 10 ms - 109 bytes │
10+ │ avg │ 53 ms - 205 bytes │ 6 ms - 105 bytes │
11+ │ total │ 424 ms - 1.61 KB │ 48 ms - 844 bytes │
12+ ├───────┼────────────────────┼───────────────────┤
13+ │ order │ 2 │ 1 │
14+ └───────┴────────────────────┴───────────────────┘
Original file line number Diff line number Diff line change 1+
2+ 0 / 1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0 % 1 / 1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100 %
3+
4+
5+ ┌───────┬───────────────────────┬──────────────────────┐
6+ │ # │ 0 │ 1 │
7+ ├───────┼───────────────────────┼──────────────────────┤
8+ │ min │ 15.68 ms - 202 bytes │ 2.35 ms - 102 bytes │
9+ │ max │ 112.79 ms - 209 bytes │ 9.76 ms - 109 bytes │
10+ │ avg │ 53.03 ms - 205 bytes │ 5.94 ms - 105 bytes │
11+ │ total │ 424.2 ms - 1.61 KB │ 47.54 ms - 844 bytes │
12+ ├───────┼───────────────────────┼──────────────────────┤
13+ │ order │ 2 │ 1 │
14+ └───────┴───────────────────────┴──────────────────────┘
Original file line number Diff line number Diff line change 1+
2+ 0 / 1 [░░░░░░░░░░░░░░░░░░░░░░░░░░░░] 0 % 1 / 1 [▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓] 100 %
3+
4+
5+ ┌───────┬──────────────────────────┬────────────────────────┐
6+ │ # │ 0 │ 1 │
7+ ├───────┼──────────────────────────┼────────────────────────┤
8+ │ min │ 15.6789 ms - 202 bytes │ 2.34568 ms - 102 bytes │
9+ │ max │ 112.78901 ms - 209 bytes │ 9.75679 ms - 109 bytes │
10+ │ avg │ 53.02525 ms - 205 bytes │ 5.9429 ms - 105 bytes │
11+ │ total │ 424.20199 ms - 1.61 KB │ 47.5432 ms - 844 bytes │
12+ ├───────┼──────────────────────────┼────────────────────────┤
13+ │ order │ 2 │ 1 │
14+ └───────┴──────────────────────────┴────────────────────────┘
File renamed without changes.
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ use DragonCode \Benchmark \Exceptions \NoComparisonsException ;
6+
7+ describe ('without comparisons ' , function () {
8+ test ('toData ' , function () {
9+ $ result = benchmark (false )->toData ();
10+
11+ expect ($ result )->toBeEmpty ();
12+ });
13+
14+ test ('toConsole ' , function () {
15+ benchmark (false )->toConsole ();
16+
17+ expectOutputToMatchSnapshot ();
18+ });
19+
20+ test ('toAssert ' , function () {
21+ benchmark (false )->toAssert ();
22+ })->throws (NoComparisonsException::class);
23+ });
You can’t perform that action at this time.
0 commit comments