Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/5.3' into 5.3
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Sep 6, 2016
2 parents 0730ec5 + 2bfef8b commit 72f5a1d
Show file tree
Hide file tree
Showing 15 changed files with 203 additions and 30 deletions.
8 changes: 2 additions & 6 deletions src/Illuminate/Console/Scheduling/Event.php
Original file line number Diff line number Diff line change
Expand Up @@ -639,14 +639,10 @@ public function unlessBetween($startTime, $endTime)
*/
private function inTimeInterval($startTime, $endTime)
{
$startTime = str_replace(':', '', $startTime);

$endTime = str_replace(':', '', $endTime);

return function () use ($startTime, $endTime) {
$now = Carbon::now()->format('Hi');
$now = Carbon::now()->timestamp;

return $now >= $startTime && $now <= $endTime;
return $now >= strtotime($startTime) && $now <= strtotime($endTime);
};
}

Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Eloquent/Model.php
Original file line number Diff line number Diff line change
Expand Up @@ -650,7 +650,7 @@ public function fresh($with = [])

$key = $this->getKeyName();

return static::with($with)->where($key, $this->getKey())->first();
return static::newQueryWithoutScopes()->with($with)->where($key, $this->getKey())->first();
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ public function addEagerConstraints(array $models)
{
$table = $this->parent->getTable();

$this->query->whereIn($table.'.'.$this->firstKey, $this->getKeys($models));
$this->query->whereIn($table.'.'.$this->firstKey, $this->getKeys($models, $this->localKey));
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -582,7 +582,7 @@ protected function invalidOperatorAndValue($operator, $value)
/**
* Add an "or where" clause to the query.
*
* @param string|\Closure $column
* @param \Closure|string $column
* @param string $operator
* @param mixed $value
* @return \Illuminate\Database\Query\Builder|static
Expand Down
6 changes: 3 additions & 3 deletions src/Illuminate/Filesystem/FilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,16 @@ public function url($path)
{
$adapter = $this->driver->getAdapter();

if ($adapter instanceof AwsS3Adapter) {
if (method_exists($adapter, 'getUrl')) {
return $adapter->getUrl($path);
} elseif ($adapter instanceof AwsS3Adapter) {
$path = $adapter->getPathPrefix().$path;

return $adapter->getClient()->getObjectUrl($adapter->getBucket(), $path);
} elseif ($adapter instanceof LocalAdapter) {
$path = '/storage/'.$path;

return Str::contains($path, '/storage/public') ? Str::replaceFirst('/public', '', $path) : $path;
} elseif (method_exists($adapter, 'getUrl')) {
return $adapter->getUrl($path);
} else {
throw new RuntimeException('This driver does not support retrieving URLs.');
}
Expand Down
24 changes: 12 additions & 12 deletions src/Illuminate/Notifications/ChannelManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
class ChannelManager extends Manager implements DispatcherContract, FactoryContract
{
/**
* The default channels used to deliver messages.
* The default channel used to deliver messages.
*
* @var array
* @var string
*/
protected $defaultChannels = ['mail', 'database'];
protected $defaultChannel = 'mail';

/**
* Send the given notification to the given notifiable entities.
Expand Down Expand Up @@ -206,33 +206,33 @@ protected function createDriver($driver)
}

/**
* Get the default channel driver names.
* Get the default channel driver name.
*
* @return array
* @return string
*/
public function getDefaultDriver()
{
return $this->defaultChannels;
return $this->defaultChannel;
}

/**
* Get the default channel driver names.
* Get the default channel driver name.
*
* @return array
* @return string
*/
public function deliversVia()
{
return $this->getDefaultDriver();
}

/**
* Set the default channel driver names.
* Set the default channel driver name.
*
* @param array|string $channels
* @param string $channel
* @return void
*/
public function deliverVia($channels)
public function deliverVia($channel)
{
$this->defaultChannels = (array) $channels;
$this->defaultChannel = $channel;
}
}
23 changes: 20 additions & 3 deletions src/Illuminate/Queue/Queue.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use DateTime;
use Illuminate\Support\Arr;
use InvalidArgumentException;
use Illuminate\Container\Container;

abstract class Queue
Expand Down Expand Up @@ -71,20 +72,28 @@ public function bulk($jobs, $data = '', $queue = null)
* @param mixed $data
* @param string $queue
* @return string
*
* @throws \InvalidArgumentException
*/
protected function createPayload($job, $data = '', $queue = null)
{
if (is_object($job)) {
return json_encode([
$payload = json_encode([
'job' => 'Illuminate\Queue\CallQueuedHandler@call',
'data' => [
'commandName' => get_class($job),
'command' => serialize(clone $job),
],
]);
} else {
$payload = json_encode($this->createPlainPayload($job, $data));
}

if (JSON_ERROR_NONE !== json_last_error()) {
throw new InvalidArgumentException('Unable to create payload: '.json_last_error_msg());
}

return json_encode($this->createPlainPayload($job, $data));
return $payload;
}

/**
Expand All @@ -106,12 +115,20 @@ protected function createPlainPayload($job, $data)
* @param string $key
* @param string $value
* @return string
*
* @throws \InvalidArgumentException
*/
protected function setMeta($payload, $key, $value)
{
$payload = json_decode($payload, true);

return json_encode(Arr::set($payload, $key, $value));
$payload = json_encode(Arr::set($payload, $key, $value));

if (JSON_ERROR_NONE !== json_last_error()) {
throw new InvalidArgumentException('Unable to create payload: '.json_last_error_msg());
}

return $payload;
}

/**
Expand Down
3 changes: 2 additions & 1 deletion src/Illuminate/Queue/Worker.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,8 @@ public function daemon($connectionName, $queue, WorkerOptions $options)
*/
protected function daemonShouldRun()
{
return ! $this->manager->isDownForMaintenance();
return $this->manager->isDownForMaintenance()
? false : $this->events->until('illuminate.queue.looping') !== false;
}

/**
Expand Down
17 changes: 17 additions & 0 deletions src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -920,6 +920,23 @@ public function slice($offset, $length = null)
return new static(array_slice($this->items, $offset, $length, true));
}

/**
* Split a collection into a certain number of groups.
*
* @param int $numberOfGroups
* @return static
*/
public function split($numberOfGroups)
{
if ($this->isEmpty()) {
return new static;
}

$groupSize = ceil($this->count() / $numberOfGroups);

return $this->chunk($groupSize);
}

/**
* Chunk the underlying collection array.
*
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/View/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ public function doneRendering()
/**
* Add new loop to the stack.
*
* @param array|\Countable $data
* @param \Countable|array $data
* @return void
*/
public function addLoop($data)
Expand Down
2 changes: 1 addition & 1 deletion tests/Console/ConsoleScheduledEventTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public function testTimeBetweenChecks()
$app = m::mock('Illuminate\Foundation\Application[isDownForMaintenance,environment]');
$app->shouldReceive('isDownForMaintenance')->andReturn(false);
$app->shouldReceive('environment')->andReturn('production');
Carbon::setTestNow(Carbon::create(2015, 1, 1, 9, 0, 0));
Carbon::setTestNow(Carbon::now()->startOfDay()->addHours(9));

$event = new Event('php foo');
$this->assertTrue($event->between('8:00', '10:00')->filtersPass($app));
Expand Down
30 changes: 30 additions & 0 deletions tests/Database/DatabaseEloquentHasManyThroughTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,36 @@ public function testEagerConstraintsAreProperlyAdded()
$relation->addEagerConstraints([$model1, $model2]);
}

public function testEagerConstraintsAreProperlyAddedWithCustomKey()
{
$builder = m::mock('Illuminate\Database\Eloquent\Builder');
$builder->shouldReceive('join')->once()->with('users', 'users.id', '=', 'posts.user_id');
$builder->shouldReceive('where')->with('users.country_id', '=', 1);

$country = m::mock('Illuminate\Database\Eloquent\Model');
$country->shouldReceive('getKeyName')->andReturn('id');
$country->shouldReceive('offsetGet')->andReturn(1);
$country->shouldReceive('getForeignKey')->andReturn('country_id');

$user = m::mock('Illuminate\Database\Eloquent\Model');
$user->shouldReceive('getTable')->andReturn('users');
$user->shouldReceive('getQualifiedKeyName')->andReturn('users.id');
$post = m::mock('Illuminate\Database\Eloquent\Model');
$post->shouldReceive('getTable')->andReturn('posts');

$builder->shouldReceive('getModel')->andReturn($post);

$relation = new HasManyThrough($builder, $country, $user, 'country_id', 'user_id', 'not_id');
$relation->getQuery()->shouldReceive('whereIn')->once()->with('users.country_id', [3, 4]);
$model1 = new EloquentHasManyThroughModelStub;
$model1->id = 1;
$model1->not_id = 3;
$model2 = new EloquentHasManyThroughModelStub;
$model2->id = 2;
$model2->not_id = 4;
$relation->addEagerConstraints([$model1, $model2]);
}

public function testModelsAreProperlyMatchedToParents()
{
$relation = $this->getRelation();
Expand Down
19 changes: 19 additions & 0 deletions tests/Database/DatabaseEloquentIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,13 @@ public function testRelationsArePreloadedInGlobalScope()
$this->assertCount(1, $result->getRelations());
}

public function testModelIgnoredByGlobalScopeCanBeRefreshed()
{
$user = EloquentTestUserWithOmittingGlobalScope::create(['id' => 1, 'email' => 'taylorotwell@gmail.com']);

$this->assertNotNull($user->fresh());
}

public function testForPageAfterIdCorrectlyPaginates()
{
EloquentTestUser::create(['id' => 1, 'email' => 'taylorotwell@gmail.com']);
Expand Down Expand Up @@ -978,6 +985,18 @@ public static function boot()
}
}

class EloquentTestUserWithOmittingGlobalScope extends EloquentTestUser
{
public static function boot()
{
parent::boot();

static::addGlobalScope(function ($builder) {
$builder->where('email', '!=', 'taylorotwell@gmail.com');
});
}
}

class EloquentTestPost extends Eloquent
{
protected $table = 'posts';
Expand Down
45 changes: 45 additions & 0 deletions tests/Queue/QueueDatabaseQueueUnitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,51 @@ public function testDelayedPushProperlyPushesJobOntoDatabase()
$queue->later(10, 'foo', ['data']);
}

public function testFailureToCreatePayloadFromObject()
{
$this->expectException('InvalidArgumentException');

$job = new stdClass();
$job->invalid = "\xc3\x28";

$queue = $this->getMockForAbstractClass('Illuminate\Queue\Queue');
$class = new ReflectionClass('Illuminate\Queue\Queue');

$createPayload = $class->getMethod('createPayload');
$createPayload->setAccessible(true);
$createPayload->invokeArgs($queue, [
$job,
]);
}

public function testFailureToCreatePayloadFromArray()
{
$this->expectException('InvalidArgumentException');

$queue = $this->getMockForAbstractClass('Illuminate\Queue\Queue');
$class = new ReflectionClass('Illuminate\Queue\Queue');

$createPayload = $class->getMethod('createPayload');
$createPayload->setAccessible(true);
$createPayload->invokeArgs($queue, [
["\xc3\x28"],
]);
}

public function testFailureToCreatePayloadAfterAddingMeta()
{
$this->expectException('InvalidArgumentException');

$queue = $this->getMockForAbstractClass('Illuminate\Queue\Queue');
$class = new ReflectionClass('Illuminate\Queue\Queue');

$setMeta = $class->getMethod('setMeta');
$setMeta->setAccessible(true);
$setMeta->invokeArgs($queue, [
json_encode(['valid']), 'key', "\xc3\x28",
]);
}

public function testBulkBatchPushesOntoDatabase()
{
$database = m::mock('Illuminate\Database\Connection');
Expand Down
Loading

0 comments on commit 72f5a1d

Please sign in to comment.