| Total Complexity | 4 |
| Total Lines | 52 |
| Duplicated Lines | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 11 | class ThrottlingServiceTest extends TestCase |
||
| 12 | { |
||
| 13 | private $service; |
||
| 14 | private $ip = "123"; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @throws \Exception |
||
| 18 | */ |
||
| 19 | public function setUp(): void |
||
| 20 | { |
||
| 21 | parent::setUp(); |
||
| 22 | $config = new Config(__DIR__.'/../../config/config.yml'); |
||
| 23 | Cache::setConfig($config); |
||
| 24 | $this->service = new ThrottlingService(); |
||
| 25 | $this->service->setAllowedRequestsPerSecond(1); |
||
| 26 | $this->service->setIp($this->ip); |
||
| 27 | } |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @test |
||
| 31 | */ |
||
| 32 | public function testInvalidRate() |
||
| 33 | { |
||
| 34 | $this->expectException(ThrottledException::class); |
||
| 35 | $this->service->validateRate(); |
||
| 36 | $this->service->validateRate(); |
||
| 37 | } |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @test |
||
| 41 | */ |
||
| 42 | public function testValidRate() |
||
| 43 | { |
||
| 44 | sleep(1); |
||
| 45 | $this->service->validateRate(); |
||
| 46 | $this->assertTrue(Cache::getCache()->exists(ThrottlingService::PREFIX_THROTTLING.$this->ip)); |
||
| 47 | } |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @test |
||
| 51 | * @throws \Exception |
||
| 52 | */ |
||
| 53 | public function testValidWithFilesCache() |
||
| 63 | } |
||
| 64 | |||
| 65 | } |