feat(expect): fixes to contain with strings

This commit is contained in:
Nuno Maduro
2020-07-15 00:57:31 +02:00
parent e2deaae6c9
commit 2751bc9674
3 changed files with 10 additions and 5 deletions

View File

@ -147,7 +147,7 @@ final class Expectation
*/
public function toContain($value): Expectation
{
if (is_string($value)) {
if (is_string($this->value)) {
Assert::assertStringContainsString($value, $this->value);
} else {
Assert::assertContains($value, $this->value);

View File

@ -119,7 +119,8 @@
✓ not failures
PASS Tests\Expect\toContain
✓ passes
✓ passes strings
✓ passes arrays
✓ failures
✓ not failures
@ -308,5 +309,5 @@
WARN Tests\Visual\Success
- visual snapshot of test suite on success
Tests: 6 skipped, 181 passed
Time: 5.70s
Tests: 6 skipped, 182 passed
Time: 5.72s

View File

@ -2,10 +2,14 @@
use PHPUnit\Framework\ExpectationFailedException;
test('passes', function () {
test('passes strings', function () {
expect([1, 2, 42])->toContain(42);
});
test('passes arrays', function () {
expect('Nuno')->toContain('Nu');
});
test('failures', function () {
expect([1, 2, 42])->toContain(3);
})->throws(ExpectationFailedException::class);