Skip to content

Commit

Permalink
make request guard param optional
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Apr 28, 2017
2 parents 6a2b893 + 2ed668f commit d7f0b26
Show file tree
Hide file tree
Showing 15 changed files with 101 additions and 88 deletions.
13 changes: 11 additions & 2 deletions CHANGELOG-5.4.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,32 @@
# Release Notes for 5.4.x

## [Unreleased]
## v5.4.20 (2017-04-27)

### Added
- Added higher order tap ([3abc4fb](https://github.com/laravel/framework/commit/3abc4fb90fe59a90c2d8cccd27e310b20e5e2631))
- Added `Collection::mapToGroups()` ([#18949](https://github.com/laravel/framework/pull/18949))
- Added `FactoryBuilder::lazy()` method ([#18823](https://github.com/laravel/framework/pull/18823))
- Support Redis Sentinel configuration ([#18850](https://github.com/laravel/framework/pull/18850))
- Added queue prefix option ([#18860](https://github.com/laravel/framework/pull/18860))
- Added `queue.prefix` option ([#18860](https://github.com/laravel/framework/pull/18860), [8510bf9](https://github.com/laravel/framework/commit/8510bf9986fffd8af58d288a297de573e78d97a5))
- Allow `getDisplayableAttribute()` to be used in custom replacers ([#18895](https://github.com/laravel/framework/pull/18895))
- Added `resourceMethodsWithoutModels()` method to `AuthorizesRequests` ([#18916](https://github.com/laravel/framework/pull/18916), [#18964](https://github.com/laravel/framework/pull/18964))
- Added name to `home` route ([#18942](https://github.com/laravel/framework/pull/18942))

### Changed
- Return `PendingDispatch` for `Kernel::queue()` ([51647eb](https://github.com/laravel/framework/commit/51647eb701307e7682f7489b605a146e750abf0f))
- Made `RedisManager::resolve()` public ([#18830](https://github.com/laravel/framework/pull/18830), [eb9b99d](https://github.com/laravel/framework/commit/eb9b99dfe80ca266bf675e8aaa3fdfdf6c4a69f3))
- Changed email body color to match wrapper color ([#18824](https://github.com/laravel/framework/pull/18824))
- Break and hyphenate long words in emails ([#18827](https://github.com/laravel/framework/pull/18827))
- Force database migration to use the write PDO ([#18898](https://github.com/laravel/framework/pull/18898))
- Support `JSON_PARTIAL_OUTPUT_ON_ERROR` on `JsonResponse` ([#18917](https://github.com/laravel/framework/pull/18917), [db5f011](https://github.com/laravel/framework/commit/db5f011d8ba9d0bcb5d768bea9d94688739f5b4c))

### Fixed
- Set connection on model factory ([#18846](https://github.com/laravel/framework/pull/18846), [95a0663](https://github.com/laravel/framework/commit/95a06638633359965961a11ab05967d32351cfdf))
- Fixed route parameter binding for routes with leading slashes ([#18855](https://github.com/laravel/framework/pull/18855))
- Don't call `cleanParameterBag()` twice during JSON request ([#18840](https://github.com/laravel/framework/pull/18840))
- Prevent exception in `getActualClassNameForMorph()` when morph map is `null` ([#18921](https://github.com/laravel/framework/pull/18921))
- Use protocol-relative URL in `mix()` helper ([#18943](https://github.com/laravel/framework/pull/18943))
- Cast `$viaChannels` to array ([#18960](https://github.com/laravel/framework/pull/18960))


## v5.4.19 (2017-04-16)
Expand Down
4 changes: 2 additions & 2 deletions src/Illuminate/Auth/RequestGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ class RequestGuard implements Guard
*
* @param callable $callback
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Contracts\Auth\UserProvider $provider
* @param \Illuminate\Contracts\Auth\UserProvider|null $provider
* @return void
*/
public function __construct(callable $callback, Request $request, UserProvider $provider)
public function __construct(callable $callback, Request $request, UserProvider $provider = null)
{
$this->request = $request;
$this->callback = $callback;
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Cache/RedisStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public function many(array $keys)
}, $keys));

foreach ($values as $index => $value) {
$results[$keys[$index]] = $this->unserialize($value);
$results[$keys[$index]] = ! is_null($value) ? $this->unserialize($value) : null;
}

return $results;
Expand Down
16 changes: 15 additions & 1 deletion src/Illuminate/Events/Dispatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,21 @@ protected function parseEventAndPayload($event, $payload)
*/
protected function shouldBroadcast(array $payload)
{
return isset($payload[0]) && $payload[0] instanceof ShouldBroadcast;
return isset($payload[0]) &&
$payload[0] instanceof ShouldBroadcast &&
$this->broadcastWhen($payload[0]);
}

/**
* Check if event should be broadcasted by condition.
*
* @param mixed $event
* @return bool
*/
protected function broadcastWhen($event)
{
return method_exists($event, 'broadcastWhen')
? $event->broadcastWhen() : true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/BeanstalkdQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public function deleteMessage($queue, $id)
*/
public function getQueue($queue)
{
return $this->getQueuePrefix().($queue ?: $this->default);
return $queue ?: $this->default;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Illuminate/Queue/Console/ListenCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,9 @@ protected function getQueue($connection)
{
$connection = $connection ?: $this->laravel['config']['queue.default'];

$queue = $this->input->getOption('queue') ?: $this->laravel['config']->get(
return $this->input->getOption('queue') ?: $this->laravel['config']->get(
"queue.connections.{$connection}.queue", 'default'
);

return $this->laravel['config']->get('queue.prefix').$queue;
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/Illuminate/Queue/Console/WorkCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -196,11 +196,9 @@ protected function logFailedJob(JobFailed $event)
*/
protected function getQueue($connection)
{
$queue = $this->option('queue') ?: $this->laravel['config']->get(
return $this->option('queue') ?: $this->laravel['config']->get(
"queue.connections.{$connection}.queue", 'default'
);

return $this->laravel['config']->get('queue.prefix').$queue;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/DatabaseQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ public function deleteReserved($queue, $id)
*/
public function getQueue($queue)
{
return $this->getQueuePrefix().($queue ?: $this->default);
return $queue ?: $this->default;
}

/**
Expand Down
30 changes: 0 additions & 30 deletions src/Illuminate/Queue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ abstract class Queue
*/
protected $connectionName;

/**
* The queue prefix.
*
* @var string
*/
protected $queuePrefix;

/**
* Push a new job onto the queue.
*
Expand Down Expand Up @@ -183,29 +176,6 @@ public function setConnectionName($name)
return $this;
}

/**
* Set the queue name prefix.
*
* @param string $prefix
* @return $this
*/
public function setQueuePrefix($prefix = null)
{
$this->queuePrefix = $prefix;

return $this;
}

/**
* Get the queue name prefix.
*
* @return string
*/
public function getQueuePrefix()
{
return $this->queuePrefix;
}

/**
* Set the IoC container instance.
*
Expand Down
13 changes: 1 addition & 12 deletions src/Illuminate/Queue/QueueManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ protected function resolve($name)

return $this->getConnector($config['driver'])
->connect($config)
->setConnectionName($name)
->setQueuePrefix($this->getQueuePrefix());
->setConnectionName($name);
}

/**
Expand Down Expand Up @@ -244,16 +243,6 @@ public function getName($connection = null)
return $connection ?: $this->getDefaultDriver();
}

/**
* Get the queue name prefix.
*
* @return string
*/
public function getQueuePrefix()
{
return $this->app['config']->get('queue.prefix');
}

/**
* Determine if the application is in maintenance mode.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/RedisQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ protected function getRandomId()
*/
public function getQueue($queue)
{
return 'queues:'.$this->getQueuePrefix().($queue ?: $this->default);
return 'queues:'.($queue ?: $this->default);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Queue/SqsQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ public function pop($queue = null)
*/
public function getQueue($queue)
{
$queue = $this->getQueuePrefix().($queue ?: $this->default);
$queue = $queue ?: $this->default;

return filter_var($queue, FILTER_VALIDATE_URL) === false
? rtrim($this->prefix, '/').'/'.$queue : $queue;
Expand Down
17 changes: 9 additions & 8 deletions tests/Cache/CacheRedisStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,20 @@ public function testRedisMultipleValuesAreReturned()
{
$redis = $this->getRedis();
$redis->getRedis()->shouldReceive('connection')->once()->with('default')->andReturn($redis->getRedis());
$redis->getRedis()->shouldReceive('mget')->once()->with(['prefix:foo', 'prefix:fizz', 'prefix:norf'])
$redis->getRedis()->shouldReceive('mget')->once()->with(['prefix:foo', 'prefix:fizz', 'prefix:norf', 'prefix:null'])
->andReturn([
serialize('bar'),
serialize('buzz'),
serialize('quz'),
null,
]);
$this->assertEquals([
'foo' => 'bar',
'fizz' => 'buzz',
'norf' => 'quz',
], $redis->many([
'foo', 'fizz', 'norf',
]));

$results = $redis->many(['foo', 'fizz', 'norf', 'null']);

$this->assertEquals('bar', $results['foo']);
$this->assertEquals('buzz', $results['fizz']);
$this->assertEquals('quz', $results['norf']);
$this->assertNull($results['null']);
}

public function testRedisValueIsReturnedForNumerics()
Expand Down
44 changes: 44 additions & 0 deletions tests/Events/EventsDispatcherTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Mockery as m;
use PHPUnit\Framework\TestCase;
use Illuminate\Events\Dispatcher;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class EventsDispatcherTest extends TestCase
{
Expand Down Expand Up @@ -222,6 +223,28 @@ public function testBothClassesAndInterfacesWork()
$this->assertSame('fooo', $_SERVER['__event.test1']);
$this->assertSame('baar', $_SERVER['__event.test2']);
}

public function testShouldBroadcastSuccess()
{
$d = m::mock(Dispatcher::class);

$d->makePartial()->shouldAllowMockingProtectedMethods();

$event = new BroadcastEvent();

$this->assertTrue($d->shouldBroadcast([$event]));
}

public function testShouldBroadcastFail()
{
$d = m::mock(Dispatcher::class);

$d->makePartial()->shouldAllowMockingProtectedMethods();

$event = new BroadcastFalseCondition();

$this->assertFalse($d->shouldBroadcast([$event]));
}
}

class TestDispatcherQueuedHandler implements \Illuminate\Contracts\Queue\ShouldQueue
Expand Down Expand Up @@ -257,3 +280,24 @@ class AnotherEvent implements SomeEventInterface
{
//
}

class BroadcastEvent implements ShouldBroadcast
{
public function broadcastOn()
{
return ['test-channel'];
}

public function broadcastWhen()
{
return true;
}
}

class BroadcastFalseCondition extends BroadcastEvent
{
public function broadcastWhen()
{
return false;
}
}
34 changes: 12 additions & 22 deletions tests/Queue/QueueManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use Mockery as m;
use PHPUnit\Framework\TestCase;
use Illuminate\Config\Repository;
use Illuminate\Queue\QueueManager;

class QueueManagerTest extends TestCase
Expand All @@ -16,47 +15,41 @@ public function tearDown()

public function testDefaultConnectionCanBeResolved()
{
$config = new Repository([
'queue.default' => 'sync',
'queue.connections.sync' => ['driver' => 'sync'],
]);

$app = [
'config' => $config,
'config' => [
'queue.default' => 'sync',
'queue.connections.sync' => ['driver' => 'sync'],
],
'encrypter' => $encrypter = m::mock('Illuminate\Contracts\Encryption\Encrypter'),
];

$manager = new QueueManager($app);
$connector = m::mock('StdClass');
$queue = m::mock('StdClass');
$queue->shouldReceive('setConnectionName')->once()->with('sync')->andReturnSelf();
$queue->shouldReceive('setQueuePrefix')->once()->with('')->andReturnSelf();
$connector->shouldReceive('connect')->once()->with(['driver' => 'sync'])->andReturn($queue);
$manager->addConnector('sync', function () use ($connector) {
return $connector;
});
$queue->shouldReceive('setContainer')->once()->with($app);

$queue->shouldReceive('setContainer')->once()->with($app);
$this->assertSame($queue, $manager->connection('sync'));
}

public function testOtherConnectionCanBeResolved()
{
$config = new Repository([
'queue.default' => 'sync',
'queue.connections.foo' => ['driver' => 'bar'],
]);

$app = [
'config' => $config,
'config' => [
'queue.default' => 'sync',
'queue.connections.foo' => ['driver' => 'bar'],
],
'encrypter' => $encrypter = m::mock('Illuminate\Contracts\Encryption\Encrypter'),
];

$manager = new QueueManager($app);
$connector = m::mock('StdClass');
$queue = m::mock('StdClass');
$queue->shouldReceive('setConnectionName')->once()->with('foo')->andReturnSelf();
$queue->shouldReceive('setQueuePrefix')->once()->with('')->andReturnSelf();
$connector->shouldReceive('connect')->once()->with(['driver' => 'bar'])->andReturn($queue);
$manager->addConnector('bar', function () use ($connector) {
return $connector;
Expand All @@ -68,20 +61,17 @@ public function testOtherConnectionCanBeResolved()

public function testNullConnectionCanBeResolved()
{
$config = new Repository([
'queue.default' => 'null',
]);

$app = [
'config' => $config,
'config' => [
'queue.default' => 'null',
],
'encrypter' => $encrypter = m::mock('Illuminate\Contracts\Encryption\Encrypter'),
];

$manager = new QueueManager($app);
$connector = m::mock('StdClass');
$queue = m::mock('StdClass');
$queue->shouldReceive('setConnectionName')->once()->with('null')->andReturnSelf();
$queue->shouldReceive('setQueuePrefix')->once()->with('')->andReturnSelf();
$connector->shouldReceive('connect')->once()->with(['driver' => 'null'])->andReturn($queue);
$manager->addConnector('null', function () use ($connector) {
return $connector;
Expand Down

0 comments on commit d7f0b26

Please sign in to comment.