From bb49526e3681c429cb1651b59da6ca215a5230a8 Mon Sep 17 00:00:00 2001 From: Benson Lee Date: Thu, 15 Dec 2016 10:17:20 -0800 Subject: [PATCH] Laravel 5.3.28 changes (#29) --- src/Illuminate/Support/Collection.php | 8 ++++++-- tests/Support/SupportCollectionTest.php | 3 +++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index aaadb77..587f62b 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -649,7 +649,9 @@ public function max($callback = null) { $callback = $this->valueRetriever($callback); - return $this->filter()->reduce(function ($result, $item) use ($callback) { + return $this->filter(function ($value) { + return ! is_null($value); + })->reduce(function ($result, $item) use ($callback) { $value = $callback($item); return is_null($result) || $value > $result ? $value : $result; @@ -699,7 +701,9 @@ public function min($callback = null) { $callback = $this->valueRetriever($callback); - return $this->filter()->reduce(function ($result, $item) use ($callback) { + return $this->filter(function ($value) { + return ! is_null($value); + })->reduce(function ($result, $item) use ($callback) { $value = $callback($item); return is_null($result) || $value < $result ? $value : $result; diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 92d53f0..ca84d9b 100644 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -1377,6 +1377,9 @@ public function testGettingMinItemsFromCollection() $c = new Collection([1, null, 3, 4, 5]); $this->assertEquals(1, $c->min()); + $c = new Collection([0, 1, 2, 3, 4]); + $this->assertEquals(0, $c->min()); + $c = new Collection(); $this->assertNull($c->min()); }