CounterTest   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 4
eloc 9
c 1
b 0
f 0
dl 0
loc 38
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A can_add_hit() 0 6 1
A resets_in_cannot_be_negative() 0 3 1
A add_hit_is_immutable() 0 6 1
A resets_at_cannot_be_in_the_past() 0 3 1
1
<?php
2
3
namespace Zenstruck\Governator\Tests\Unit;
4
5
use PHPUnit\Framework\TestCase;
6
use Zenstruck\Governator\Counter;
7
8
/**
9
 * @group time-sensitive
10
 *
11
 * @author Kevin Bond <[email protected]>
12
 */
13
final class CounterTest extends TestCase
14
{
15
    /**
16
     * @test
17
     */
18
    public function resets_in_cannot_be_negative(): void
19
    {
20
        $this->assertSame(0, (new Counter(10, time() - 10))->resetsIn());
21
    }
22
23
    /**
24
     * @test
25
     */
26
    public function resets_at_cannot_be_in_the_past(): void
27
    {
28
        $this->assertSame(time(), (new Counter(10, time() - 10))->resetsAt());
29
    }
30
31
    /**
32
     * @test
33
     */
34
    public function can_add_hit(): void
35
    {
36
        $counter = new Counter(10, time());
37
38
        $this->assertSame(10, $counter->hits());
39
        $this->assertSame(11, $counter->addHit()->hits());
40
    }
41
42
    /**
43
     * @test
44
     */
45
    public function add_hit_is_immutable(): void
46
    {
47
        $counter = new Counter(10, 3);
48
        $newCounter = $counter->addHit();
49
50
        $this->assertNotSame(\spl_object_id($counter), \spl_object_id($newCounter));
51
    }
52
}
53