ThrottleTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 2
eloc 10
c 2
b 0
f 0
dl 0
loc 22
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A negative_block_has_same_effect_as_zero() 0 17 2
1
<?php
2
3
namespace Zenstruck\Governator\Tests\Unit;
4
5
use PHPUnit\Framework\TestCase;
6
use Zenstruck\Governator\Exception\QuotaExceeded;
7
use Zenstruck\Governator\Key;
8
use Zenstruck\Governator\Store\MemoryStore;
9
use Zenstruck\Governator\Throttle;
10
11
/**
12
 * @author Kevin Bond <[email protected]>
13
 */
14
final class ThrottleTest extends TestCase
15
{
16
    /**
17
     * @test
18
     */
19
    public function negative_block_has_same_effect_as_zero(): void
20
    {
21
        $throttle = new Throttle(new MemoryStore(), new Key('foo', 1, 10));
22
23
        $throttle->acquire();
24
25
        $start = time();
26
27
        try {
28
            $throttle->acquire(-20);
29
        } catch (QuotaExceeded $e) {
30
            $this->assertSame(time(), $start);
31
32
            return;
33
        }
34
35
        $this->fail('Exception not thrown.');
36
    }
37
}
38