CounterTest::resets_in_cannot_be_negative()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
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