From 903305b9ccbc350b0f6d3806a2cb1710442dbe00 Mon Sep 17 00:00:00 2001 From: Rod Elias Date: Sun, 2 Dec 2018 14:46:16 -0200 Subject: [PATCH] [5.7] fix bug when using 'some' alias for the 'contains' method (#26696) * fix bug when using 'some' alias for the 'contains' method * remove array_filter 'cause it doesnt solve the problem --- src/Illuminate/Support/Collection.php | 2 +- tests/Support/SupportCollectionTest.php | 38 +++++++++++++++++++++++++ 2 files changed, 39 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Support/Collection.php b/src/Illuminate/Support/Collection.php index a4dc2a792445..b60ec672ef84 100644 --- a/src/Illuminate/Support/Collection.php +++ b/src/Illuminate/Support/Collection.php @@ -248,7 +248,7 @@ public function collapse() */ public function some($key, $operator = null, $value = null) { - return $this->contains($key, $operator, $value); + return $this->contains(...func_get_args()); } /** diff --git a/tests/Support/SupportCollectionTest.php b/tests/Support/SupportCollectionTest.php index 06fff7a0e22b..17bed1c1efd1 100755 --- a/tests/Support/SupportCollectionTest.php +++ b/tests/Support/SupportCollectionTest.php @@ -1842,6 +1842,44 @@ public function testContains() })); } + public function testSome() + { + $c = new Collection([1, 3, 5]); + + $this->assertTrue($c->some(1)); + $this->assertFalse($c->some(2)); + $this->assertTrue($c->some(function ($value) { + return $value < 5; + })); + $this->assertFalse($c->some(function ($value) { + return $value > 5; + })); + + $c = new Collection([['v' => 1], ['v' => 3], ['v' => 5]]); + + $this->assertTrue($c->some('v', 1)); + $this->assertFalse($c->some('v', 2)); + + $c = new Collection(['date', 'class', (object) ['foo' => 50]]); + + $this->assertTrue($c->some('date')); + $this->assertTrue($c->some('class')); + $this->assertFalse($c->some('foo')); + + $c = new Collection([['a' => false, 'b' => false], ['a' => true, 'b' => false]]); + + $this->assertTrue($c->some->a); + $this->assertFalse($c->some->b); + + $c = new Collection([ + null, 1, 2, + ]); + + $this->assertTrue($c->some(function ($value) { + return is_null($value); + })); + } + public function testContainsStrict() { $c = new Collection([1, 3, 5, '02']);