FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

Merge branch '5.2' · JavaDevl/framework@7cadd04 · GitHub

Commit 7cadd04

Browse files
committed
Merge branch '5.2'
2 parents 06edabe + 5100086 commit 7cadd04

8 files changed

Lines changed: 129 additions & 44 deletions

File tree

‎src/Illuminate/Cache/Events/CacheHit.php‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,25 @@ class CacheHit
1818
*/
1919
public $value;
2020

21+
/**
22+
* The tags that were assigned to the key.
23+
*
24+
* @var array
25+
*/
26+
public $tags;
27+
2128
/**
2229
* Create a new event instance.
2330
*
2431
* @param string $key
2532
* @param mixed $value
33+
* @param array $tags
2634
* @return void
2735
*/
28-
public function __construct($key, $value)
36+
public function __construct($key, $value, array $tags = [])
2937
{
3038
$this->key = $key;
39+
$this->tags = $tags;
3140
$this->value = $value;
3241
}
3342
}

‎src/Illuminate/Cache/Events/CacheMissed.php‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,23 @@ class CacheMissed
1111
*/
1212
public $key;
1313

14+
/**
15+
* The tags that were assigned to the key.
16+
*
17+
* @var array
18+
*/
19+
public $tags;
20+
1421
/**
1522
* Create a new event instance.
1623
*
1724
* @param string $event
25+
* @param array $tags
1826
* @return void
1927
*/
20-
public function __construct($key)
28+
public function __construct($key, array $tags = [])
2129
{
2230
$this->key = $key;
31+
$this->tags = $tags;
2332
}
2433
}

‎src/Illuminate/Cache/Events/KeyForgotten.php‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,23 @@ class KeyForgotten
1111
*/
1212
public $key;
1313

14+
/**
15+
* The tags that were assigned to the key.
16+
*
17+
* @var array
18+
*/
19+
public $tags;
20+
1421
/**
1522
* Create a new event instance.
1623
*
1724
* @param string $key
25+
* @param array $tags
1826
* @return void
1927
*/
20-
public function __construct($key)
28+
public function __construct($key, $tags = [])
2129
{
2230
$this->key = $key;
31+
$this->tags = $tags;
2332
}
2433
}

‎src/Illuminate/Cache/Events/KeyWritten.php‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,26 @@ class KeyWritten
2525
*/
2626
public $minutes;
2727

28+
/**
29+
* The tags that were assigned to the key.
30+
*
31+
* @var array
32+
*/
33+
public $tags;
34+
2835
/**
2936
* Create a new event instance.
3037
*
3138
* @param string $key
3239
* @param mixed $value
3340
* @param int $minutes
41+
* @param array $tags
3442
* @return void
3543
*/
36-
public function __construct($key, $value, $minutes)
44+
public function __construct($key, $value, $minutes, $tags = [])
3745
{
3846
$this->key = $key;
47+
$this->tags = $tags;
3948
$this->value = $value;
4049
$this->minutes = $minutes;
4150
}

‎src/Illuminate/Cache/Repository.php‎

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,29 @@ protected function fireCacheEvent($event, $payload)
7676

7777
switch ($event) {
7878
case 'hit':
79-
return $this->events->fire(new Events\CacheHit($payload[0], $payload[1]));
79+
if (count($payload) == 2) {
80+
$payload[] = [];
81+
}
82+
83+
return $this->events->fire(new Events\CacheHit($payload[0], $payload[1], $payload[2]));
8084
case 'missed':
81-
return $this->events->fire(new Events\CacheMissed($payload[0]));
85+
if (count($payload) == 1) {
86+
$payload[] = [];
87+
}
88+
89+
return $this->events->fire(new Events\CacheMissed($payload[0], $payload[1]));
8290
case 'delete':
83-
return $this->events->fire(new Events\KeyForgotten($payload[0]));
91+
if (count($payload) == 1) {
92+
$payload[] = [];
93+
}
94+
95+
return $this->events->fire(new Events\KeyForgotten($payload[0], $payload[1]));
8496
case 'write':
85-
return $this->events->fire(new Events\KeyWritten($payload[0], $payload[1], $payload[2]));
97+
if (count($payload) == 3) {
98+
$payload[] = [];
99+
}
100+
101+
return $this->events->fire(new Events\KeyWritten($payload[0], $payload[1], $payload[2], $payload[3]));
86102
}
87103
}
88104

‎src/Illuminate/Console/Scheduling/Event.php‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -211,12 +211,14 @@ protected function callAfterCallbacks(Container $container)
211211
*/
212212
public function buildCommand()
213213
{
214+
$output = ProcessUtils::escapeArgument($this->output);
215+
214216
$redirect = $this->shouldAppendOutput ? ' >> ' : ' > ';
215217

216218
if ($this->withoutOverlapping) {
217-
$command = '(touch '.$this->mutexPath().'; '.$this->command.'; rm '.$this->mutexPath().')'.$redirect.$this->output.' 2>&1 &';
219+
$command = '(touch '.$this->mutexPath().'; '.$this->command.'; rm '.$this->mutexPath().')'.$redirect.$output.' 2>&1 &';
218220
} else {
219-
$command = $this->command.$redirect.$this->output.' 2>&1 &';
221+
$command = $this->command.$redirect.$output.' 2>&1 &';
220222
}
221223

222224
return $this->user ? 'sudo -u '.$this->user.' '.$command : $command;
@@ -659,7 +661,7 @@ public function skip(Closure $callback)
659661
*/
660662
public function sendOutputTo($location, $append = false)
661663
{
662-
$this->output = ProcessUtils::escapeArgument($location);
664+
$this->output = $location;
663665

664666
$this->shouldAppendOutput = $append;
665667

‎tests/Cache/CacheEventsTest.php‎

Lines changed: 52 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
<?php
22

33
use Mockery as m;
4+
use Illuminate\Cache\Events\CacheHit;
5+
use Illuminate\Cache\Events\KeyWritten;
6+
use Illuminate\Cache\Events\CacheMissed;
7+
use Illuminate\Cache\Events\KeyForgotten;
48

59
class CacheEventTest extends PHPUnit_Framework_TestCase
610
{
@@ -14,17 +18,16 @@ public function testHasTriggersEvents()
1418
$dispatcher = $this->getDispatcher();
1519
$repository = $this->getRepository($dispatcher);
1620

17-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\CacheMissed'));
21+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo']));
1822
$this->assertFalse($repository->has('foo'));
1923

20-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\CacheHit'));
24+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(CacheHit::class, ['key' => 'baz', 'value' => 'qux']));
2125
$this->assertTrue($repository->has('baz'));
2226

23-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\CacheMissed'));
24-
$dispatcher->shouldReceive('fire')->never();
27+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo', 'tags' => ['taylor']]));
2528
$this->assertFalse($repository->tags('taylor')->has('foo'));
2629

27-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\CacheHit'));
30+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(CacheHit::class, ['key' => 'baz', 'value' => 'qux', 'tags' => ['taylor']]));
2831
$this->assertTrue($repository->tags('taylor')->has('baz'));
2932
}
3033

@@ -33,16 +36,16 @@ public function testGetTriggersEvents()
3336
$dispatcher = $this->getDispatcher();
3437
$repository = $this->getRepository($dispatcher);
3538

36-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\CacheMissed'));
39+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo']));
3740
$this->assertNull($repository->get('foo'));
3841

39-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\CacheHit'));
42+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(CacheHit::class, ['key' => 'baz', 'value' => 'qux']));
4043
$this->assertEquals('qux', $repository->get('baz'));
4144

42-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\CacheMissed'));
45+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo', 'tags' => ['taylor']]));
4346
$this->assertNull($repository->tags('taylor')->get('foo'));
4447

45-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\CacheHit'));
48+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(CacheHit::class, ['key' => 'baz', 'value' => 'qux', 'tags' => ['taylor']]));
4649
$this->assertEquals('qux', $repository->tags('taylor')->get('baz'));
4750
}
4851

@@ -51,8 +54,8 @@ public function testPullTriggersEvents()
5154
$dispatcher = $this->getDispatcher();
5255
$repository = $this->getRepository($dispatcher);
5356

54-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\CacheHit'));
55-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\KeyForgotten'));
57+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(CacheHit::class, ['key' => 'baz', 'value' => 'qux']));
58+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(KeyForgotten::class, ['key' => 'baz']));
5659
$this->assertEquals('qux', $repository->pull('baz'));
5760
}
5861

@@ -61,8 +64,8 @@ public function testPullTriggersEventsUsingTags()
6164
$dispatcher = $this->getDispatcher();
6265
$repository = $this->getRepository($dispatcher);
6366

64-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\CacheHit'));
65-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\KeyForgotten'));
67+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(CacheHit::class, ['key' => 'baz', 'value' => 'qux', 'tags' => ['taylor']]));
68+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(KeyForgotten::class, ['key' => 'baz', 'tags' => ['taylor']]));
6669
$this->assertEquals('qux', $repository->tags('taylor')->pull('baz'));
6770
}
6871

@@ -71,10 +74,10 @@ public function testPutTriggersEvents()
7174
$dispatcher = $this->getDispatcher();
7275
$repository = $this->getRepository($dispatcher);
7376

74-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\KeyWritten'));
77+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar']));
7578
$repository->put('foo', 'bar', 99);
7679

77-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\KeyWritten'));
80+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'tags' => ['taylor']]));
7881
$repository->tags('taylor')->put('foo', 'bar', 99);
7982
}
8083

@@ -83,12 +86,12 @@ public function testAddTriggersEvents()
8386
$dispatcher = $this->getDispatcher();
8487
$repository = $this->getRepository($dispatcher);
8588

86-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\CacheMissed'));
87-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\KeyWritten'));
89+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo']));
90+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar']));
8891
$this->assertTrue($repository->add('foo', 'bar', 99));
8992

90-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\CacheMissed'));
91-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\KeyWritten'));
93+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo', 'tags' => ['taylor']]));
94+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'tags' => ['taylor']]));
9295
$this->assertTrue($repository->tags('taylor')->add('foo', 'bar', 99));
9396
}
9497

@@ -97,10 +100,10 @@ public function testForeverTriggersEvents()
97100
$dispatcher = $this->getDispatcher();
98101
$repository = $this->getRepository($dispatcher);
99102

100-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\KeyWritten'));
103+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar']));
101104
$repository->forever('foo', 'bar');
102105

103-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\KeyWritten'));
106+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'tags' => ['taylor']]));
104107
$repository->tags('taylor')->forever('foo', 'bar');
105108
}
106109

@@ -109,14 +112,14 @@ public function testRememberTriggersEvents()
109112
$dispatcher = $this->getDispatcher();
110113
$repository = $this->getRepository($dispatcher);
111114

112-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\CacheMissed'));
113-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\KeyWritten'));
115+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo']));
116+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar']));
114117
$this->assertEquals('bar', $repository->remember('foo', 99, function () {
115118
return 'bar';
116119
}));
117120

118-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\CacheMissed'));
119-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\KeyWritten'));
121+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo', 'tags' => ['taylor']]));
122+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'tags' => ['taylor']]));
120123
$this->assertEquals('bar', $repository->tags('taylor')->remember('foo', 99, function () {
121124
return 'bar';
122125
}));
@@ -127,14 +130,14 @@ public function testRememberForeverTriggersEvents()
127130
$dispatcher = $this->getDispatcher();
128131
$repository = $this->getRepository($dispatcher);
129132

130-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\CacheMissed'));
131-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\KeyWritten'));
133+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo']));
134+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar']));
132135
$this->assertEquals('bar', $repository->rememberForever('foo', function () {
133136
return 'bar';
134137
}));
135138

136-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\CacheMissed'));
137-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\KeyWritten'));
139+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(CacheMissed::class, ['key' => 'foo', 'tags' => ['taylor']]));
140+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(KeyWritten::class, ['key' => 'foo', 'value' => 'bar', 'tags' => ['taylor']]));
138141
$this->assertEquals('bar', $repository->tags('taylor')->rememberForever('foo', function () {
139142
return 'bar';
140143
}));
@@ -145,11 +148,28 @@ public function testForgetTriggersEvents()
145148
$dispatcher = $this->getDispatcher();
146149
$repository = $this->getRepository($dispatcher);
147150

148-
$dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\KeyForgotten'));
151+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(KeyForgotten::class, ['key' => 'baz']));
149152
$this->assertTrue($repository->forget('baz'));
150153

151-
// $dispatcher->shouldReceive('fire')->once()->with(m::type('Illuminate\Cache\Events\CacheMissed'));
152-
// $this->assertTrue($repository->tags('taylor')->forget('baz'));
154+
$dispatcher->shouldReceive('fire')->once()->with($this->assertEventMatches(KeyForgotten::class, ['key' => 'baz', 'tags' => ['taylor']]));
155+
$this->assertTrue($repository->tags('taylor')->forget('baz'));
156+
}
157+
158+
protected function assertEventMatches($eventClass, $properties = [])
159+
{
160+
return m::on(function ($event) use ($eventClass, $properties) {
161+
if (! $event instanceof $eventClass) {
162+
return false;
163+
}
164+
165+
foreach ($properties as $name => $value) {
166+
if ($event->$name != $value) {
167+
return false;
168+
}
169+
}
170+
171+
return true;
172+
});
153173
}
154174

155175
protected function getDispatcher()

‎tests/Console/Scheduling/EventTest.php‎

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public function testBuildCommand()
99
$event = new Event('php -i');
1010

1111
$defaultOutput = (DIRECTORY_SEPARATOR == '\\') ? 'NUL' : '/dev/null';
12-
$this->assertSame("php -i > {$defaultOutput} 2>&1 &", $event->buildCommand());
12+
$this->assertSame("php -i > '{$defaultOutput}' 2>&1 &", $event->buildCommand());
1313
}
1414

1515
public function testBuildCommandSendOutputTo()
@@ -32,4 +32,15 @@ public function testBuildCommandAppendOutput()
3232
$event->appendOutputTo('/dev/null');
3333
$this->assertSame("php -i >> '/dev/null' 2>&1 &", $event->buildCommand());
3434
}
35+
36+
/**
37+
* @expectedException LogicException
38+
*/
39+
public function testEmailOutputToThrowsExceptionIfOutputFileWasNotSpecified()
40+
{
41+
$event = new Event('php -i');
42+
$event->emailOutputTo('foo@example.com');
43+
44+
$event->buildCommand();
45+
}
3546
}

0 commit comments

Comments
 (0)

Back | FazBrowse Home | New Git URL