Skip to content

Commit 245fd68

Browse files
authored
Merge pull request #27265 from driesvints/key-written-event-null-minutes
[5.8] Update KeyWritten event with new minutes handling
2 parents 9ed4284 + 060248a commit 245fd68

File tree

3 files changed

+15
-15
lines changed

3 files changed

+15
-15
lines changed

src/Illuminate/Cache/Events/KeyWritten.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class KeyWritten extends CacheEvent
1414
/**
1515
* The number of minutes the key should be valid.
1616
*
17-
* @var int
17+
* @var int|null
1818
*/
1919
public $minutes;
2020

@@ -23,11 +23,11 @@ class KeyWritten extends CacheEvent
2323
*
2424
* @param string $key
2525
* @param mixed $value
26-
* @param int $minutes
26+
* @param int|null $minutes
2727
* @param array $tags
2828
* @return void
2929
*/
30-
public function __construct($key, $value, $minutes, $tags = [])
30+
public function __construct($key, $value, $minutes = null, $tags = [])
3131
{
3232
parent::__construct($key, $tags);
3333

src/Illuminate/Cache/Repository.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,15 +351,15 @@ public function decrement($key, $value = 1)
351351
* Store an item in the cache indefinitely.
352352
*
353353
* @param string $key
354-
* @param mixed $value
354+
* @param mixed $value
355355
* @return bool
356356
*/
357357
public function forever($key, $value)
358358
{
359359
$result = $this->store->forever($this->itemKey($key), $value);
360360

361361
if ($result) {
362-
$this->event(new KeyWritten($key, $value, 0));
362+
$this->event(new KeyWritten($key, $value));
363363
}
364364

365365
return $result;

tests/Cache/CacheEventsTest.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,10 +80,10 @@ public function testPutTriggersEvents()
8080
$dispatcher = $this->getDispatcher();
8181
$repository = $this->getRepository($dispatcher);
8282

83-
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar']));
83+
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => 99]));
8484
$repository->put('foo', 'bar', 99);
8585

86-
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'tags' => ['taylor']]));
86+
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => 99, 'tags' => ['taylor']]));
8787
$repository->tags('taylor')->put('foo', 'bar', 99);
8888
}
8989

@@ -93,11 +93,11 @@ public function testAddTriggersEvents()
9393
$repository = $this->getRepository($dispatcher);
9494

9595
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo']));
96-
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar']));
96+
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => 99]));
9797
$this->assertTrue($repository->add('foo', 'bar', 99));
9898

9999
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo', 'tags' => ['taylor']]));
100-
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'tags' => ['taylor']]));
100+
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => 99, 'tags' => ['taylor']]));
101101
$this->assertTrue($repository->tags('taylor')->add('foo', 'bar', 99));
102102
}
103103

@@ -106,10 +106,10 @@ public function testForeverTriggersEvents()
106106
$dispatcher = $this->getDispatcher();
107107
$repository = $this->getRepository($dispatcher);
108108

109-
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar']));
109+
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => null]));
110110
$repository->forever('foo', 'bar');
111111

112-
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'tags' => ['taylor']]));
112+
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => null, 'tags' => ['taylor']]));
113113
$repository->tags('taylor')->forever('foo', 'bar');
114114
}
115115

@@ -119,13 +119,13 @@ public function testRememberTriggersEvents()
119119
$repository = $this->getRepository($dispatcher);
120120

121121
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo']));
122-
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar']));
122+
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => 99]));
123123
$this->assertEquals('bar', $repository->remember('foo', 99, function () {
124124
return 'bar';
125125
}));
126126

127127
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo', 'tags' => ['taylor']]));
128-
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'tags' => ['taylor']]));
128+
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => 99, 'tags' => ['taylor']]));
129129
$this->assertEquals('bar', $repository->tags('taylor')->remember('foo', 99, function () {
130130
return 'bar';
131131
}));
@@ -137,13 +137,13 @@ public function testRememberForeverTriggersEvents()
137137
$repository = $this->getRepository($dispatcher);
138138

139139
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo']));
140-
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar']));
140+
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => null]));
141141
$this->assertEquals('bar', $repository->rememberForever('foo', function () {
142142
return 'bar';
143143
}));
144144

145145
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo', 'tags' => ['taylor']]));
146-
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'tags' => ['taylor']]));
146+
$dispatcher->shouldReceive('dispatch')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'minutes' => null, 'tags' => ['taylor']]));
147147
$this->assertEquals('bar', $repository->tags('taylor')->rememberForever('foo', function () {
148148
return 'bar';
149149
}));

0 commit comments

Comments
 (0)