Skip to content

Commit b33af71

Browse files
authored
Merge pull request #1157 from ExeQue/2.x
[2.x] Added `toBeList` expectation
2 parents 303f4c0 + 3c6c89a commit b33af71

File tree

2 files changed

+33
-0
lines changed

2 files changed

+33
-0
lines changed

src/Mixins/Expectation.php

+12
Original file line numberDiff line numberDiff line change
@@ -467,6 +467,18 @@ public function toBeArray(string $message = ''): self
467467
return $this;
468468
}
469469

470+
/**
471+
* Asserts that the value is a list.
472+
*
473+
* @return self<TValue>
474+
*/
475+
public function toBeList(string $message = ''): self
476+
{
477+
Assert::assertIsList($this->value, $message);
478+
479+
return $this;
480+
}
481+
470482
/**
471483
* Asserts that the value is of type bool.
472484
*

tests/Features/Expect/toBeList.php

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
3+
use PHPUnit\Framework\ExpectationFailedException;
4+
5+
test('pass', function () {
6+
expect([1, 2, 3])->toBeList();
7+
expect(['a' => 1, 'b' => 2, 'c' => 3])->not->toBeList();
8+
expect('1, 2, 3')->not->toBeList();
9+
});
10+
11+
test('failures', function () {
12+
expect(null)->toBeList();
13+
})->throws(ExpectationFailedException::class);
14+
15+
test('failures with custom message', function () {
16+
expect(null)->toBeList('oh no!');
17+
})->throws(ExpectationFailedException::class, 'oh no!');
18+
19+
test('not failures', function () {
20+
expect(['a', 'b', 'c'])->not->toBeList();
21+
})->throws(ExpectationFailedException::class);

0 commit comments

Comments
 (0)