From 6049de68155224fdb088422587720f224328e1f6 Mon Sep 17 00:00:00 2001 From: jerguslejko Date: Wed, 14 Dec 2016 14:02:57 +0000 Subject: [PATCH] Add isNotEmpty() method to Collection class --- src/Illuminate/Support/Collection.php | 10 ++++++++++ tests/Support/SupportCollectionTest.php | 8 ++++++++ 2 files changed, 18 insertions(+) diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index a6ebdbf1511c..b7ba7ab9bc04 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -545,6 +545,16 @@ public function isEmpty() return empty($this->items); } + /** + * Determine if the collection is not empty. + * + * @return bool + */ + public function isNotEmpty() + { + return ! $this->isEmpty(); + } + /** * Determine if the given value is callable, but not a string. * diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index ab256a6b93d8..77553483f474 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -96,6 +96,14 @@ public function testEmptyCollectionIsEmpty() $this->assertTrue($c->isEmpty()); } + public function testEmptyCollectionIsNotEmpty() + { + $c = new Collection(['foo', 'bar']); + + $this->assertFalse($c->isEmpty()); + $this->assertTrue($c->isNotEmpty()); + } + public function testCollectionIsConstructed() { $collection = new Collection('foo');