Skip to content

Commit

Permalink
Merge branch '5.5'
Browse files Browse the repository at this point in the history
  • Loading branch information
GrahamCampbell committed Dec 18, 2017
2 parents eadcabe + 1c0a18c commit cfc3b68
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 2 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG-5.5.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
# Release Notes for 5.5.x

## [Unreleased]

### Added
- Support passing collections to `Collection::except()` ([#22399](https://github.com/laravel/framework/pull/22399))
- Made `Command` class macroable ([#22426](https://github.com/laravel/framework/pull/22426), [#22434](https://github.com/laravel/framework/pull/22434))
- Added `ProcessUtils` class for command argument escaping ([#22448](https://github.com/laravel/framework/pull/22448))
- Added array support to `Optional` helper class ([#22417](https://github.com/laravel/framework/pull/22417))

### Changed
- Added "cattle" as an uncountable word ([#22415](https://github.com/laravel/framework/pull/22415))
- Added `Dispatcher` contract on `NotificationFake` and return fake object from `Notification::fake()` ([#22396](https://github.com/laravel/framework/pull/22396))
- Only add value as query binding if it isn't an `Expression` ([#22451](https://github.com/laravel/framework/pull/22451))

### Fixed
- Fixed database queue transactions wrapped in closures ([#22394](https://github.com/laravel/framework/pull/22394))
- Fixed an issue with multiple `dont-discover` packages ([#22443](https://github.com/laravel/framework/pull/22443))
- Fixed incorrect description type in `Console/Parser` ([#22449](https://github.com/laravel/framework/pull/22449))


## v5.5.25 (2017-12-11)

### Added
Expand Down
4 changes: 3 additions & 1 deletion src/Illuminate/Database/Query/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1087,7 +1087,9 @@ protected function addDateBasedWhere($type, $column, $operator, $value, $boolean
{
$this->wheres[] = compact('column', 'type', 'boolean', 'operator', 'value');

$this->addBinding($value, 'where');
if (! $value instanceof Expression) {
$this->addBinding($value, 'where');
}

return $this;
}
Expand Down
53 changes: 52 additions & 1 deletion src/Illuminate/Support/Optional.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@

namespace Illuminate\Support;

class Optional
use ArrayAccess;

class Optional implements ArrayAccess
{
use Traits\Macroable {
__call as macroCall;
Expand Down Expand Up @@ -56,4 +58,53 @@ public function __call($method, $parameters)
return $this->value->{$method}(...$parameters);
}
}

/**
* Determine if an item exists at an offset.
*
* @param mixed $key
* @return bool
*/
public function offsetExists($key)
{
return Arr::accessible($this->value) && Arr::exists($this->value, $key);
}

/**
* Get an item at a given offset.
*
* @param mixed $key
* @return mixed
*/
public function offsetGet($key)
{
return Arr::get($this->value, $key);
}

/**
* Set the item at a given offset.
*
* @param mixed $key
* @param mixed $value
* @return void
*/
public function offsetSet($key, $value)
{
if (Arr::accessible($this->value)) {
$this->value[$key] = $value;
}
}

/**
* Unset the item at a given offset.
*
* @param string $key
* @return void
*/
public function offsetUnset($key)
{
if (Arr::accessible($this->value)) {
unset($this->value[$key]);
}
}
}
7 changes: 7 additions & 0 deletions tests/Database/DatabaseQueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -293,6 +293,13 @@ public function testDateBasedWheresAcceptsTwoArguments()
$this->assertEquals('select * from `users` where year(`created_at`) = ?', $builder->toSql());
}

public function testDateBasedWheresExpressionIsNotBound()
{
$builder = $this->getBuilder();
$builder->select('*')->from('users')->whereDate('created_at', new Raw('NOW()'))->where('admin', true);
$this->assertEquals([true], $builder->getBindings());
}

public function testWhereDayMySql()
{
$builder = $this->getMySqlBuilder();
Expand Down
7 changes: 7 additions & 0 deletions tests/Support/SupportHelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,13 @@ public function something()
})->something());
}

public function testOptionalWithArray()
{
$this->assertNull(optional(null)['missing']);

$this->assertEquals('here', optional(['present' => 'here'])['present']);
}

public function testOptionalIsMacroable()
{
Optional::macro('present', function () {
Expand Down

0 comments on commit cfc3b68

Please sign in to comment.