class StateTest in CloudFlare 8
Tests functionality of CloudFlareState object.
@group cloudflare
@covers \Drupal\cloudflare\State
Hierarchy
- class \Drupal\Tests\UnitTestCase extends \PHPUnit\Framework\TestCase uses PhpunitCompatibilityTrait
- class \Drupal\Tests\cloudflare\Unit\StateTest
Expanded class hierarchy of StateTest
File
- tests/
src/ Unit/ StateTest.php, line 20
Namespace
Drupal\Tests\cloudflare\UnitView source
class StateTest extends UnitTestCase {
/**
* Tests tag count tracking functionality.
*/
public function testTagPurgeDailyCountIncrements() {
$timestamp_stub = $this
->getMockBuilder('Drupal\\cloudflare\\Timestamp')
->disableOriginalConstructor()
->getMock();
// Configure the stub.
$timestamp_stub
->method('now')
->will($this
->onConsecutiveCalls(new \DateTime('2010-02-01 00:00:00'), new \DateTime('2010-02-01 00:01:00'), new \DateTime('2010-02-01 00:02:00')));
$drupal_state_service = new CoreState(new KeyValueMemoryFactory(), new MemoryBackend('test'), new NullLockBackend());
$cloudflare_state = new CloudFlareState($drupal_state_service, $timestamp_stub);
$initial_count = $cloudflare_state
->getTagDailyCount();
$this
->assertEquals(0, $initial_count, 'Tested state with empty counts');
$cloudflare_state
->incrementTagPurgeDailyCount();
$count = $cloudflare_state
->getTagDailyCount();
$this
->assertEquals(1, $count, 'Tested state with first increment of day');
$cloudflare_state
->incrementTagPurgeDailyCount();
$count = $cloudflare_state
->getTagDailyCount();
$this
->assertEquals(2, $count, 'Tested state with first increment of day');
$cloudflare_state
->incrementTagPurgeDailyCount();
$count = $cloudflare_state
->getTagDailyCount();
$this
->assertEquals(3, $count, 'Tested state with first increment of day');
}
/**
* Tests tag count boundary functionality.
*/
public function testTagPurgeBoundaryIncrements() {
$timestamp_stub = $this
->getMockBuilder('Drupal\\cloudflare\\Timestamp')
->disableOriginalConstructor()
->getMock();
// Configure the stub.
$timestamp_stub
->method('now')
->will($this
->onConsecutiveCalls(new DateTime('2010-02-01 00:00:00'), new DateTime('2010-02-02 00:01:00'), new DateTime('2010-02-03 00:02:00')));
$drupal_state_service = new CoreState(new KeyValueMemoryFactory(), new MemoryBackend('test'), new NullLockBackend());
$cloudflare_state = new CloudFlareState($drupal_state_service, $timestamp_stub);
$initial_count = $cloudflare_state
->getTagDailyCount();
$this
->assertEquals(0, $initial_count, 'Tested state with empty counts');
$cloudflare_state
->incrementTagPurgeDailyCount();
$count = $cloudflare_state
->getTagDailyCount();
$this
->assertEquals(1, $count, 'Tested state with first increment of day');
$cloudflare_state
->incrementTagPurgeDailyCount();
$count = $cloudflare_state
->getTagDailyCount();
$this
->assertEquals(1, $count, 'Tested state with first increment of day');
$cloudflare_state
->incrementTagPurgeDailyCount();
$count = $cloudflare_state
->getTagDailyCount();
$this
->assertEquals(1, $count, 'Tested state with first increment of day');
}
/**
* Tests tag count tracking functionality.
*/
public function testApiRateLimitCountIncrements() {
$timestamp_stub = $this
->getMockBuilder('Drupal\\cloudflare\\Timestamp')
->disableOriginalConstructor()
->getMock();
// Configure the stub.
$timestamp_stub
->method('now')
->will($this
->onConsecutiveCalls(new DateTime('2010-02-01 00:00:00'), new DateTime('2010-02-01 00:01:00'), new DateTime('2010-02-01 00:02:00')));
$drupal_state_service = new CoreState(new KeyValueMemoryFactory(), new MemoryBackend('test'), new NullLockBackend());
$cloudflare_state = new CloudFlareState($drupal_state_service, $timestamp_stub);
$initial_count = $cloudflare_state
->getTagDailyCount();
$this
->assertEquals(0, $initial_count, 'Tested state with empty counts');
$cloudflare_state
->incrementApiRateCount();
$count = $cloudflare_state
->getApiRateCount();
$this
->assertEquals(1, $count, 'Tested state with first increment of day');
$cloudflare_state
->incrementApiRateCount();
$count = $cloudflare_state
->getApiRateCount();
$this
->assertEquals(2, $count, 'Tested state with first increment of day');
$cloudflare_state
->incrementApiRateCount();
$count = $cloudflare_state
->getApiRateCount();
$this
->assertEquals(3, $count, 'Tested state with first increment of day');
}
/**
* Tests tag count boundary functionality.
*/
public function testApiRateLimitBoundaryIncrements() {
$timestamp_stub = $this
->getMockBuilder('Drupal\\cloudflare\\Timestamp')
->disableOriginalConstructor()
->getMock();
// Configure the stub.
$timestamp_stub
->method('now')
->will($this
->onConsecutiveCalls(new DateTime('2010-02-01 00:00:00'), new DateTime('2010-02-02 00:01:00'), new DateTime('2010-02-03 00:02:00'), new DateTime('2010-02-03 00:10:00'), new DateTime('2010-02-03 00:15:00')));
$drupal_state_service = new CoreState(new KeyValueMemoryFactory(), new MemoryBackend('test'), new NullLockBackend());
$cloudflare_state = new CloudFlareState($drupal_state_service, $timestamp_stub);
$initial_count = $cloudflare_state
->getApiRateCount();
$this
->assertEquals(0, $initial_count, 'Tested state with empty counts');
$cloudflare_state
->incrementApiRateCount();
$count = $cloudflare_state
->getApiRateCount();
$this
->assertEquals(1, $count, 'Tested state with first increment of day');
$cloudflare_state
->incrementApiRateCount();
$count = $cloudflare_state
->getApiRateCount();
$this
->assertEquals(1, $count, 'Tested state with first increment of day');
$cloudflare_state
->incrementApiRateCount();
$count = $cloudflare_state
->getApiRateCount();
$this
->assertEquals(1, $count, 'Tested state with first increment of day');
$cloudflare_state
->incrementApiRateCount();
$count = $cloudflare_state
->getApiRateCount();
$this
->assertEquals(1, $count, 'Tested state with first increment of day');
$cloudflare_state
->incrementApiRateCount();
$count = $cloudflare_state
->getApiRateCount();
$this
->assertEquals(1, $count, 'Tested state with first increment of day');
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
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. | |
StateTest:: |
public | function | Tests tag count boundary functionality. | |
StateTest:: |
public | function | Tests tag count tracking functionality. | |
StateTest:: |
public | function | Tests tag count boundary functionality. | |
StateTest:: |
public | function | Tests tag count tracking functionality. | |
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. | |
UnitTestCase:: |
protected | function | 340 |