class ApiRateLimitCheckTest in CloudFlare 8
Tests that purge_requirements() passes on our diagnostic checks.
@group cloudflarepurger
@covers \Drupal\cloudflarepurger\Plugin\Purge\DiagnosticCheck\ApiRateLimitCheck
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\cloudflarepurger\Unit\DiagnosticCheckTestBase
- class \Drupal\Tests\cloudflarepurger\Unit\ApiRateLimitCheckTest
- class \Drupal\Tests\cloudflarepurger\Unit\DiagnosticCheckTestBase
Expanded class hierarchy of ApiRateLimitCheckTest
File
- modules/
cloudflarepurger/ tests/ src/ Unit/ ApiRateLimitCheckTest.php, line 16
Namespace
Drupal\Tests\cloudflarepurger\UnitView source
class ApiRateLimitCheckTest extends DiagnosticCheckTestBase {
/**
* Tests that ApiRateLimitCheck Responds as expected with test purge rates.
*
* @param int $api_rate
* The currentAPI rate to test.
* @param int $expected_severity
* The expected diagnostic severity.
*
* @dataProvider apiRateLimitProvider
*/
public function testApiRateLimitCheck($api_rate, $expected_severity) {
$this->drupalState
->set(State::API_RATE_COUNT, $api_rate);
$this->drupalState
->set(State::API_RATE_COUNT_START, new \DateTime());
$api_rate_limit_check = new ApiRateLimitCheck([], '23123', 'this is a definition', $this->cloudflareState, $this->composerDependencyStub);
$actual_severity = $api_rate_limit_check
->run();
$this
->assertEquals($expected_severity, $actual_severity);
}
/**
* Data provider for validating ApiRateLimitCheck.
*
* @return array[]
* Returns per data set an array with:
* - count of daily tag purge requests
* - expected status returned by diagnostic check
*/
public function apiRateLimitProvider() {
return [
[
NULL,
DiagnosticCheckInterface::SEVERITY_OK,
],
[
0,
DiagnosticCheckInterface::SEVERITY_OK,
],
[
1,
DiagnosticCheckInterface::SEVERITY_OK,
],
[
500,
DiagnosticCheckInterface::SEVERITY_OK,
],
[
899,
DiagnosticCheckInterface::SEVERITY_OK,
],
[
900,
DiagnosticCheckInterface::SEVERITY_WARNING,
],
[
901,
DiagnosticCheckInterface::SEVERITY_WARNING,
],
[
1199,
DiagnosticCheckInterface::SEVERITY_WARNING,
],
[
1200,
DiagnosticCheckInterface::SEVERITY_ERROR,
],
[
1220,
DiagnosticCheckInterface::SEVERITY_ERROR,
],
];
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
ApiRateLimitCheckTest:: |
public | function | Data provider for validating ApiRateLimitCheck. | |
ApiRateLimitCheckTest:: |
public | function | Tests that ApiRateLimitCheck Responds as expected with test purge rates. | |
DiagnosticCheckTestBase:: |
protected | property | Tracks rate limits associated with CloudFlare Api. | |
DiagnosticCheckTestBase:: |
protected | property | Provides check for composer dependencies. | |
DiagnosticCheckTestBase:: |
protected | property | The dependency injection container. | |
DiagnosticCheckTestBase:: |
protected | property | Tracks Drupal states. | |
DiagnosticCheckTestBase:: |
protected | property | Provides timestamps. | |
DiagnosticCheckTestBase:: |
public | function |
Overrides UnitTestCase:: |
1 |
PhpunitCompatibilityTrait:: |
public | function | Returns a mock object for the specified class using the available method. | |
PhpunitCompatibilityTrait:: |
public | function | Compatibility layer for PHPUnit 6 to support PHPUnit 4 code. | |
UnitTestCase:: |
protected | property | The random generator. | |
UnitTestCase:: |
protected | property | The app root. | 1 |
UnitTestCase:: |
protected | function | Asserts if two arrays are equal by sorting them first. | |
UnitTestCase:: |
protected | function | Mocks a block with a block plugin. | 1 |
UnitTestCase:: |
protected | function | Returns a stub class resolver. | |
UnitTestCase:: |
public | function | Returns a stub config factory that behaves according to the passed array. | |
UnitTestCase:: |
public | function | Returns a stub config storage that returns the supplied configuration. | |
UnitTestCase:: |
protected | function | Sets up a container with a cache tags invalidator. | |
UnitTestCase:: |
protected | function | Gets the random generator for the utility methods. | |
UnitTestCase:: |
public | function | Returns a stub translation manager that just returns the passed string. | |
UnitTestCase:: |
public | function | Generates a unique random string containing letters and numbers. |