Skip to content

Renamed array_contains_assoc to array_has_subset #3

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ Check if an array contains a set of values.

_This function works as expected with nested arrays or an array with objects._

#### array\_contains\_assoc
#### array\_has\_subset

boolean array_contains_assoc(array $array, array $subset, boolean $strict = false)
boolean array_has_subset(array $array, array $subset, boolean $strict = false)

Check if an array contains a set of values with index check.

Expand Down
2 changes: 1 addition & 1 deletion src/array_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function array_contains(array $array, array $subset, $strict = false)
* @param boolean $strict Strict type checking
* @return boolean
*/
function array_contains_assoc(array $array, array $subset, $strict = false)
function array_has_subset(array $array, array $subset, $strict = false)
{
foreach ($subset as $key => $value) {
if (
Expand Down
26 changes: 13 additions & 13 deletions tests/ArrayFunctionsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -127,53 +127,53 @@ public function testArrayContainsWithStrict()


/**
* @covers Jasny\array_contains_assoc
* @covers Jasny\array_has_subset
*/
public function testArrayContainsAssoc()
public function testArrayHasSubset()
{
$this->assertTrue(array_contains_assoc(
$this->assertTrue(array_has_subset(
['foo' => 7, 'bar' => 9, 'baz' => 12, 'top' => 3],
['top' => 3, 'bar' => 9]
));

$this->assertFalse(array_contains_assoc(
$this->assertFalse(array_has_subset(
['foo' => 7, 'bar' => 9, 'baz' => 12, 'top' => 3],
['top' => 3, 'bar' => 7]
));
}

/**
* @covers Jasny\array_contains_assoc
* @covers Jasny\array_has_subset
*/
public function testArrayContainsAssocWithNested()
public function testArrayHasSubsetWithNested()
{
$this->assertTrue(array_contains_assoc(
$this->assertTrue(array_has_subset(
['greet' => ['hello', 'world'], 'x' => 'q', 'item' => (object)['a' => 'b']],
['x' => 'q', 'greet' => ['hello', 'world']]
));

$this->assertTrue(array_contains_assoc(
$this->assertTrue(array_has_subset(
['greet' => ['hello', 'world'], 'x' => 'q', 'item' => (object)['a' => 'b']],
['x' => 'q', 'item' => (object)['a' => 'b']]
));

$this->assertFalse(array_contains_assoc(
$this->assertFalse(array_has_subset(
['greet' => ['hello', 'world'], 'x' => 'q', 'item' => (object)['a' => 'b']],
['x' => 'q', 'greet' => ['hello', 'world', '!']]
));
}

/**
* @covers Jasny\array_contains_assoc
* @covers Jasny\array_has_subset
*/
public function testArrayContainsAssocWithStrict()
public function testArrayHasSubsetWithStrict()
{
$this->assertTrue(array_contains_assoc(
$this->assertTrue(array_has_subset(
['foo' => 7, 'bar' => 9, 'baz' => 12, 'top' => true],
['top' => 1, 'bar' => 9]
));

$this->assertFalse(array_contains_assoc(
$this->assertFalse(array_has_subset(
['foo' => 7, 'bar' => 9, 'baz' => 12, 'top' => true],
['top' => 1, 'bar' => 9],
true
Expand Down