Skip to content

Commit

Permalink
rename method
Browse files Browse the repository at this point in the history
  • Loading branch information
taylorotwell committed Jun 9, 2021
1 parent 4d1cdf4 commit 2d2d108
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 29 deletions.
8 changes: 3 additions & 5 deletions src/Illuminate/Testing/Fluent/Concerns/Matching.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,14 @@ public function whereAllType(array $bindings): self
}

/**
* Asserts that the property matches the expected values.
* Asserts that the property contains the expected values.
*
* @param string $key
* @param array|string $expected
*
* @return $this
*/
public function whereHas(string $key, $expected)
public function whereContains(string $key, $expected)
{
$actual = Collection::make(
$this->prop($key) ?? $this->prop()
Expand All @@ -125,14 +125,12 @@ public function whereHas(string $key, $expected)
return $actual->containsStrict($search);
})->toArray();

$values = array_values($missing);

PHPUnit::assertEmpty(
$missing,
sprintf(
'Property [%s] does not contain [%s].',
$key,
implode(', ', $values)
implode(', ', array_values($missing))
)
);

Expand Down
48 changes: 24 additions & 24 deletions tests/Testing/Fluent/AssertTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -401,17 +401,17 @@ public function testAssertWhereFailsWhenDoesNotMatchValueUsingArrayable()
]);
}

public function testAssertWhereHasFailsWithEmptyValue()
public function testAssertWhereContainsFailsWithEmptyValue()
{
$assert = AssertableJson::fromArray([]);

$this->expectException(AssertionFailedError::class);
$this->expectExceptionMessage('Property [foo] does not contain [1].');

$assert->whereHas('foo', ['1']);
$assert->whereContains('foo', ['1']);
}

public function testAssertWhereHasFailsWithMissingValue()
public function testAssertWhereContainsFailsWithMissingValue()
{
$assert = AssertableJson::fromArray([
'foo' => ['bar', 'baz'],
Expand All @@ -420,10 +420,10 @@ public function testAssertWhereHasFailsWithMissingValue()
$this->expectException(AssertionFailedError::class);
$this->expectExceptionMessage('Property [foo] does not contain [invalid].');

$assert->whereHas('foo', ['bar', 'baz', 'invalid']);
$assert->whereContains('foo', ['bar', 'baz', 'invalid']);
}

public function testAssertWhereHasFailsWithMissingNestedValue()
public function testAssertWhereContainsFailsWithMissingNestedValue()
{
$assert = AssertableJson::fromArray([
['id' => 1],
Expand All @@ -435,10 +435,10 @@ public function testAssertWhereHasFailsWithMissingNestedValue()
$this->expectException(AssertionFailedError::class);
$this->expectExceptionMessage('Property [id] does not contain [5].');

$assert->whereHas('id', [1,2,3,4,5]);
$assert->whereContains('id', [1,2,3,4,5]);
}

public function testAssertWhereHasFailsWhenDoesNotMatchType()
public function testAssertWhereContainsFailsWhenDoesNotMatchType()
{
$assert = AssertableJson::fromArray([
'foo' => [1,2,3,4]
Expand All @@ -447,10 +447,10 @@ public function testAssertWhereHasFailsWhenDoesNotMatchType()
$this->expectException(AssertionFailedError::class);
$this->expectExceptionMessage('Property [foo] does not contain [1].');

$assert->whereHas('foo', ['1']);
$assert->whereContains('foo', ['1']);
}

public function testAssertWhereHasWithNestedValue()
public function testAssertWhereContainsWithNestedValue()
{
$assert = AssertableJson::fromArray([
['id' => 1],
Expand All @@ -459,58 +459,58 @@ public function testAssertWhereHasWithNestedValue()
['id' => 4],
]);

$assert->whereHas('id', 1);
$assert->whereHas('id', [1,2,3,4]);
$assert->whereHas('id', [4,3,2,1]);
$assert->whereContains('id', 1);
$assert->whereContains('id', [1,2,3,4]);
$assert->whereContains('id', [4,3,2,1]);
}

public function testAssertWhereHasWithMatchingType()
public function testAssertWhereContainsWithMatchingType()
{
$assert = AssertableJson::fromArray([
'foo' => [1,2,3,4]
]);

$assert->whereHas('foo', 1);
$assert->whereHas('foo', [1]);
$assert->whereContains('foo', 1);
$assert->whereContains('foo', [1]);
}

public function testAssertWhereHasWithNullValue()
public function testAssertWhereContainsWithNullValue()
{
$assert = AssertableJson::fromArray([
'foo' => null,
]);

$assert->whereHas('foo', null);
$assert->whereHas('foo', [null]);
$assert->whereContains('foo', null);
$assert->whereContains('foo', [null]);
}

public function testAssertWhereHasWithOutOfOrderMatchingType()
public function testAssertWhereContainsWithOutOfOrderMatchingType()
{
$assert = AssertableJson::fromArray([
'foo' => [4,1,7,3]
]);

$assert->whereHas('foo', [1,7,4,3]);
$assert->whereContains('foo', [1,7,4,3]);
}

public function testAssertWhereHasWithOutOfOrderNestedMatchingType()
public function testAssertWhereContainsWithOutOfOrderNestedMatchingType()
{
$assert = AssertableJson::fromArray([
['bar' => 5],
['baz' => 4],
['zal' => 8],
]);

$assert->whereHas('baz', 4);
$assert->whereContains('baz', 4);
}

public function testAssertWhereHasWithNullExpectation()
public function testAssertWhereContainsWithNullExpectation()
{
$assert = AssertableJson::fromArray([
'foo' => 1,
]);

$assert->whereHas('foo', null);
$assert->whereContains('foo', null);
}
public function testAssertNestedWhereMatchesValue()
{
Expand Down

0 comments on commit 2d2d108

Please sign in to comment.