Skip to content

Commit 55f6b56

Browse files
author
Morten Harders
committed
Added toBeList expectation
1 parent 303f4c0 commit 55f6b56

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-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

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
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+
});
9+
10+
test('failures', function () {
11+
expect(null)->toBeList();
12+
})->throws(ExpectationFailedException::class);
13+
14+
test('failures with custom message', function () {
15+
expect(null)->toBeList('oh no!');
16+
})->throws(ExpectationFailedException::class, 'oh no!');
17+
18+
test('not failures', function () {
19+
expect(['a', 'b', 'c'])->not->toBeList();
20+
})->throws(ExpectationFailedException::class);

0 commit comments

Comments
 (0)