Skip to content

Commit

Permalink
Merge branch laravel/5.4 into features/fresh-on-collection
Browse files Browse the repository at this point in the history
* commit '05060b183dd09cee6dce498da5afde9e66fd1a29':
  Apply fixes from StyleCI (laravel#19659)
  [5.4] Add ability to remove a global scope with another global scope (laravel#19657)
  [5.4] Add fresh method on Eloquent\Collection. (laravel#19616)
  support multiple fields to validateDifferent (laravel#19637)
  escape default value of yield blade directive (laravel#19643)
  [5.4] Add "avg" and "average" to higher order proxy. (laravel#19628)
  tagged v5.4.27 release notes
  version
  Add missing dependency. (laravel#19623)
  update timestamp on soft delete only when its used (laravel#19627)
  Add new `diffAssoc()` method to collection (laravel#19604)
  Fix tests code coverage config. (laravel#19609)

# Conflicts:
#	src/Illuminate/Database/Eloquent/Collection.php
  • Loading branch information
mathieutu committed Jun 19, 2017
2 parents 0d58b25 + 05060b1 commit 7f9c0f1
Show file tree
Hide file tree
Showing 13 changed files with 105 additions and 13 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG-5.4.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
# Release Notes for 5.4.x

## v5.4.27 (2017-06-15)

### Added
- Added `Collection::diffAssoc()` method ([#19604](https://github.com/laravel/framework/pull/19604))

### Changed
- Updated PHPUnit whitelist ([#19609](https://github.com/laravel/framework/pull/19609))

### Fixed
- Update timestamps on soft delete only when they are used ([#19627](https://github.com/laravel/framework/pull/19627))


## v5.4.26 (2017-06-13)

### Added
Expand Down
3 changes: 1 addition & 2 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,7 @@
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
<exclude>
<directory>./src/Illuminate/Pagination/resources/views</directory>
<file>./src/Illuminate/Foundation/Console/Optimize/config.php</file>
<directory suffix=".blade.php">./src/</directory>
</exclude>
</whitelist>
</filter>
Expand Down
1 change: 1 addition & 0 deletions src/Illuminate/Auth/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"php": ">=5.6.4",
"illuminate/contracts": "5.4.*",
"illuminate/http": "5.4.*",
"illuminate/queue": "5.4.*",
"illuminate/support": "5.4.*",
"nesbot/carbon": "~1.20"
},
Expand Down
6 changes: 5 additions & 1 deletion src/Illuminate/Database/Eloquent/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -887,7 +887,11 @@ public function applyScopes()

$builder = clone $this;

foreach ($this->scopes as $scope) {
foreach ($this->scopes as $identifier => $scope) {
if (! isset($builder->scopes[$identifier])) {
continue;
}

$builder->callScope(function (Builder $builder) use ($scope) {
// If the scope is a Closure we will just go ahead and call the scope with the
// builder instance. The "callScope" method will properly group the clauses
Expand Down
14 changes: 9 additions & 5 deletions src/Illuminate/Database/Eloquent/SoftDeletes.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,13 +62,17 @@ protected function runSoftDelete()

$time = $this->freshTimestamp();

$columns = [$this->getDeletedAtColumn() => $this->fromDateTime($time)];

$this->{$this->getDeletedAtColumn()} = $time;
$this->{$this->getUpdatedAtColumn()} = $time;

$query->update([
$this->getDeletedAtColumn() => $this->fromDateTime($time),
$this->getUpdatedAtColumn() => $this->fromDateTime($time),
]);
if ($this->timestamps) {
$this->{$this->getUpdatedAtColumn()} = $time;

$columns[$this->getUpdatedAtColumn()] = $this->fromDateTime($time);
}

$query->update($columns);
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/Foundation/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class Application extends Container implements ApplicationContract, HttpKernelIn
*
* @var string
*/
const VERSION = '5.4.26';
const VERSION = '5.4.27';

/**
* The base path for the Laravel installation.
Expand Down
13 changes: 12 additions & 1 deletion src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Collection implements ArrayAccess, Arrayable, Countable, IteratorAggregate
* @var array
*/
protected static $proxies = [
'contains', 'each', 'every', 'filter', 'first', 'flatMap',
'average', 'avg', 'contains', 'each', 'every', 'filter', 'first', 'flatMap',
'map', 'partition', 'reject', 'sortBy', 'sortByDesc', 'sum',
];

Expand Down Expand Up @@ -254,6 +254,17 @@ public function diff($items)
return new static(array_diff($this->items, $this->getArrayableItems($items)));
}

/**
* Get the items in the collection whose keys and values are not present in the given items.
*
* @param mixed $items
* @return static
*/
public function diffAssoc($items)
{
return new static(array_diff_assoc($this->items, $this->getArrayableItems($items)));
}

/**
* Get the items in the collection whose keys are not present in the given items.
*
Expand Down
10 changes: 8 additions & 2 deletions src/Illuminate/Validation/Concerns/ValidatesAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -375,9 +375,15 @@ protected function validateDifferent($attribute, $value, $parameters)
{
$this->requireParameterCount(1, $parameters, 'different');

$other = Arr::get($this->data, $parameters[0]);
foreach ($parameters as $parameter) {
$other = Arr::get($this->data, $parameter);

if (is_null($other) || $value === $other) {
return false;
}
}

return isset($other) && $value !== $other;
return true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Illuminate/View/Concerns/ManagesLayouts.php
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ protected function extendSection($section, $content)
*/
public function yieldContent($section, $default = '')
{
$sectionContent = $default;
$sectionContent = e($default);

if (isset($this->sections[$section])) {
$sectionContent = $this->sections[$section];
Expand Down
36 changes: 36 additions & 0 deletions tests/Database/DatabaseEloquentIntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@

use Exception;
use PHPUnit\Framework\TestCase;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Database\Capsule\Manager as DB;
use Illuminate\Database\Eloquent\Relations\Pivot;
use Illuminate\Database\Eloquent\Model as Eloquent;
use Illuminate\Database\Eloquent\SoftDeletingScope;
use Illuminate\Database\Eloquent\Relations\Relation;
use Illuminate\Pagination\AbstractPaginator as Paginator;

Expand Down Expand Up @@ -90,6 +92,14 @@ protected function createSchema()
$table->string('name');
$table->timestamps();
});

$this->schema($connection)->create('soft_deleted_users', function ($table) {
$table->increments('id');
$table->string('name')->nullable();
$table->string('email');
$table->timestamps();
$table->softDeletes();
});
}

$this->schema($connection)->create('non_incrementing_users', function ($table) {
Expand Down Expand Up @@ -1012,6 +1022,14 @@ public function testModelIgnoredByGlobalScopeCanBeRefreshed()
$this->assertNotNull($user->fresh());
}

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

$this->assertNotNull(EloquentTestUserWithGlobalScopeRemovingOtherScope::find($user->id));
}

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

class EloquentTestUserWithGlobalScopeRemovingOtherScope extends Eloquent
{
use SoftDeletes;

protected $table = 'soft_deleted_users';

protected $guarded = [];

public static function boot()
{
static::addGlobalScope(function ($builder) {
$builder->withoutGlobalScope(SoftDeletingScope::class);
});

parent::boot();
}
}

class EloquentTestPost extends Eloquent
{
protected $table = 'posts';
Expand Down
1 change: 1 addition & 0 deletions tests/Database/DatabaseSoftDeletingTraitTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ class DatabaseSoftDeletingTraitStub
use \Illuminate\Database\Eloquent\SoftDeletes;
public $deleted_at;
public $updated_at;
public $timestamps = true;

public function newQuery()
{
Expand Down
9 changes: 9 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -532,6 +532,13 @@ public function testDiffKeys()
$this->assertEquals(['first_word' => 'Hello'], $c1->diffKeys($c2)->all());
}

public function testDiffAssoc()
{
$c1 = new Collection(['id' => 1, 'first_word' => 'Hello', 'not_affected' => 'value']);
$c2 = new Collection(['id' => 123, 'foo_bar' => 'Hello', 'not_affected' => 'value']);
$this->assertEquals(['id' => 1, 'first_word' => 'Hello'], $c1->diffAssoc($c2)->all());
}

public function testEach()
{
$c = new Collection($original = [1, 2, 'foo' => 'bar', 'bam' => 'baz']);
Expand Down Expand Up @@ -1665,9 +1672,11 @@ public function testGettingAvgItemsFromCollection()
return $item->foo;
}));
$this->assertEquals(15, $c->avg('foo'));
$this->assertEquals(15, $c->avg->foo);

$c = new Collection([['foo' => 10], ['foo' => 20]]);
$this->assertEquals(15, $c->avg('foo'));
$this->assertEquals(15, $c->avg->foo);

$c = new Collection([1, 2, 3, 4, 5]);
$this->assertEquals(3, $c->avg());
Expand Down
9 changes: 9 additions & 0 deletions tests/Validation/ValidationValidatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1012,6 +1012,15 @@ public function testValidateDifferent()

$v = new Validator($trans, ['foo' => '1e2', 'baz' => '100'], ['foo' => 'Different:baz']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['foo' => 'bar', 'fuu' => 'baa', 'baz' => 'boom'], ['foo' => 'Different:fuu,baz']);
$this->assertTrue($v->passes());

$v = new Validator($trans, ['foo' => 'bar', 'baz' => 'boom'], ['foo' => 'Different:fuu,baz']);
$this->assertFalse($v->passes());

$v = new Validator($trans, ['foo' => 'bar', 'fuu' => 'bar', 'baz' => 'boom'], ['foo' => 'Different:fuu,baz']);
$this->assertFalse($v->passes());
}

public function testValidateAccepted()
Expand Down

0 comments on commit 7f9c0f1

Please sign in to comment.