Skip to content

Commit

Permalink
Merge pull request #1157 from ExeQue/2.x
Browse files Browse the repository at this point in the history
[2.x] Added `toBeList` expectation
  • Loading branch information
nunomaduro authored May 27, 2024
2 parents 303f4c0 + 3c6c89a commit b33af71
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Mixins/Expectation.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,6 +467,18 @@ public function toBeArray(string $message = ''): self
return $this;
}

/**
* Asserts that the value is a list.
*
* @return self<TValue>
*/
public function toBeList(string $message = ''): self
{
Assert::assertIsList($this->value, $message);

return $this;
}

/**
* Asserts that the value is of type bool.
*
Expand Down
21 changes: 21 additions & 0 deletions tests/Features/Expect/toBeList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

use PHPUnit\Framework\ExpectationFailedException;

test('pass', function () {
expect([1, 2, 3])->toBeList();
expect(['a' => 1, 'b' => 2, 'c' => 3])->not->toBeList();
expect('1, 2, 3')->not->toBeList();
});

test('failures', function () {
expect(null)->toBeList();
})->throws(ExpectationFailedException::class);

test('failures with custom message', function () {
expect(null)->toBeList('oh no!');
})->throws(ExpectationFailedException::class, 'oh no!');

test('not failures', function () {
expect(['a', 'b', 'c'])->not->toBeList();
})->throws(ExpectationFailedException::class);

0 comments on commit b33af71

Please sign in to comment.