Skip to content

Commit

Permalink
Added toBeList expectation
Browse files Browse the repository at this point in the history
  • Loading branch information
Morten Harders committed May 21, 2024
1 parent 303f4c0 commit 55f6b56
Show file tree
Hide file tree
Showing 2 changed files with 32 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
20 changes: 20 additions & 0 deletions tests/Features/Expect/toBeList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

use PHPUnit\Framework\ExpectationFailedException;

test('pass', function () {
expect([1, 2, 3])->toBeList();
expect(['a' => 1, 'b' => 2, 'c' => 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 55f6b56

Please sign in to comment.