File tree Expand file tree Collapse file tree 2 files changed +24
-0
lines changed
tests/Feature/Http/Middleware Expand file tree Collapse file tree 2 files changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -21,6 +21,12 @@ public function __construct(private Core $nightwatch)
21
21
22
22
public static function rate (float $ rate ): string
23
23
{
24
+ $ rate = (string ) $ rate ;
25
+
26
+ if ($ rate === '0 ' ) {
27
+ $ rate = '0.0 ' ;
28
+ }
29
+
24
30
return static ::class.': ' .$ rate ;
25
31
}
26
32
Original file line number Diff line number Diff line change 3
3
use Illuminate \Support \Facades \Route ;
4
4
use Laravel \Nightwatch \Facades \Nightwatch ;
5
5
use Laravel \Nightwatch \Http \Middleware \Sample ;
6
+ use PHPUnit \Framework \Attributes \DataProvider ;
6
7
use Tests \TestCase ;
7
8
8
9
class SampleTest extends TestCase
@@ -113,4 +114,21 @@ public function test_it_has_priority(): void
113
114
114
115
$ response ->assertOk ();
115
116
}
117
+
118
+ #[DataProvider('sampleRates ' )]
119
+ public function test_it_can_sample_at_different_rates (float |int $ rate , string $ expected ): void
120
+ {
121
+ $ this ->assertSame (Sample::rate ($ rate ), $ expected );
122
+ }
123
+
124
+ public static function sampleRates (): iterable
125
+ {
126
+ yield [1 , 'Laravel\Nightwatch\Http\Middleware\Sample:1 ' ];
127
+ yield [1.0 , 'Laravel\Nightwatch\Http\Middleware\Sample:1 ' ];
128
+ yield [0.9999 , 'Laravel\Nightwatch\Http\Middleware\Sample:0.9999 ' ];
129
+ yield [0.5 , 'Laravel\Nightwatch\Http\Middleware\Sample:0.5 ' ];
130
+ yield [0.001 , 'Laravel\Nightwatch\Http\Middleware\Sample:0.001 ' ];
131
+ yield [0 , 'Laravel\Nightwatch\Http\Middleware\Sample:0.0 ' ];
132
+ yield [0.0 , 'Laravel\Nightwatch\Http\Middleware\Sample:0.0 ' ];
133
+ }
116
134
}
You can’t perform that action at this time.
0 commit comments