Skip to content

Commit

Permalink
[5.7] fix bug when using 'some' alias for the 'contains' method (#26696)
Browse files Browse the repository at this point in the history
* fix bug when using 'some' alias for the 'contains' method

* remove array_filter 'cause it doesnt solve the problem
  • Loading branch information
chapeupreto authored and taylorotwell committed Dec 2, 2018
1 parent bf1fa90 commit 903305b
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Illuminate/Support/Collection.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

/**
Expand Down
38 changes: 38 additions & 0 deletions tests/Support/SupportCollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']);
Expand Down

0 comments on commit 903305b

Please sign in to comment.