@@ -30,18 +30,29 @@ public function testHitProperlyIncrementsAttemptCount()
30
30
$ cache = m::mock (Cache::class);
31
31
$ cache ->shouldReceive ('add ' )->once ()->with ('key:timer ' , m::type ('int ' ), 1 )->andReturn (true );
32
32
$ cache ->shouldReceive ('add ' )->once ()->with ('key ' , 0 , 1 )->andReturn (true );
33
- $ cache ->shouldReceive ('increment ' )->once ()->with ('key ' )->andReturn (1 );
33
+ $ cache ->shouldReceive ('increment ' )->once ()->with ('key ' , 1 )->andReturn (1 );
34
34
$ rateLimiter = new RateLimiter ($ cache );
35
35
36
36
$ rateLimiter ->hit ('key ' , 1 );
37
37
}
38
38
39
+ public function testIncrementProperlyIncrementsAttemptCount ()
40
+ {
41
+ $ cache = m::mock (Cache::class);
42
+ $ cache ->shouldReceive ('add ' )->once ()->with ('key:timer ' , m::type ('int ' ), 1 )->andReturn (true );
43
+ $ cache ->shouldReceive ('add ' )->once ()->with ('key ' , 0 , 1 )->andReturn (true );
44
+ $ cache ->shouldReceive ('increment ' )->once ()->with ('key ' , 5 )->andReturn (5 );
45
+ $ rateLimiter = new RateLimiter ($ cache );
46
+
47
+ $ rateLimiter ->increment ('key ' , 1 , 5 );
48
+ }
49
+
39
50
public function testHitHasNoMemoryLeak ()
40
51
{
41
52
$ cache = m::mock (Cache::class);
42
53
$ cache ->shouldReceive ('add ' )->once ()->with ('key:timer ' , m::type ('int ' ), 1 )->andReturn (true );
43
54
$ cache ->shouldReceive ('add ' )->once ()->with ('key ' , 0 , 1 )->andReturn (false );
44
- $ cache ->shouldReceive ('increment ' )->once ()->with ('key ' )->andReturn (1 );
55
+ $ cache ->shouldReceive ('increment ' )->once ()->with ('key ' , 1 )->andReturn (1 );
45
56
$ cache ->shouldReceive ('put ' )->once ()->with ('key ' , 1 , 1 );
46
57
$ rateLimiter = new RateLimiter ($ cache );
47
58
@@ -83,7 +94,7 @@ public function testAttemptsCallbackReturnsTrue()
83
94
$ cache ->shouldReceive ('get ' )->once ()->with ('key ' , 0 )->andReturn (0 );
84
95
$ cache ->shouldReceive ('add ' )->once ()->with ('key:timer ' , m::type ('int ' ), 1 );
85
96
$ cache ->shouldReceive ('add ' )->once ()->with ('key ' , 0 , 1 )->andReturns (1 );
86
- $ cache ->shouldReceive ('increment ' )->once ()->with ('key ' )->andReturn (1 );
97
+ $ cache ->shouldReceive ('increment ' )->once ()->with ('key ' , 1 )->andReturn (1 );
87
98
88
99
$ executed = false ;
89
100
@@ -101,7 +112,7 @@ public function testAttemptsCallbackReturnsCallbackReturn()
101
112
$ cache ->shouldReceive ('get ' )->times (6 )->with ('key ' , 0 )->andReturn (0 );
102
113
$ cache ->shouldReceive ('add ' )->times (6 )->with ('key:timer ' , m::type ('int ' ), 1 );
103
114
$ cache ->shouldReceive ('add ' )->times (6 )->with ('key ' , 0 , 1 )->andReturns (1 );
104
- $ cache ->shouldReceive ('increment ' )->times (6 )->with ('key ' )->andReturn (1 );
115
+ $ cache ->shouldReceive ('increment ' )->times (6 )->with ('key ' , 1 )->andReturn (1 );
105
116
106
117
$ rateLimiter = new RateLimiter ($ cache );
107
118
0 commit comments