mirror of
https://github.com/pestphp/pest.git
synced 2026-03-07 00:07:22 +01:00
Merge pull request #520 from abenerd/feature/new-expectation
add new expectation
This commit is contained in:
@ -799,6 +799,22 @@ final class Expectation
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param class-string $class
|
||||||
|
*
|
||||||
|
* @return Expectation<TValue>
|
||||||
|
*/
|
||||||
|
public function toContainOnlyInstancesOf(string $class): Expectation
|
||||||
|
{
|
||||||
|
if (!is_iterable($this->value)) {
|
||||||
|
InvalidExpectationValue::expected('iterable');
|
||||||
|
}
|
||||||
|
|
||||||
|
Assert::assertContainsOnlyInstancesOf($class, $this->value);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that executing value throws an exception.
|
* Asserts that executing value throws an exception.
|
||||||
*
|
*
|
||||||
|
|||||||
20
tests/Features/Expect/toContainOnlyInstancesOf.php
Normal file
20
tests/Features/Expect/toContainOnlyInstancesOf.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
beforeEach(function () {
|
||||||
|
$this->times = [new DateTimeImmutable(), new DateTimeImmutable()];
|
||||||
|
});
|
||||||
|
|
||||||
|
test('pass', function () {
|
||||||
|
expect($this->times)->toContainOnlyInstancesOf(DateTimeImmutable::class);
|
||||||
|
expect($this->times)->not->toContainOnlyInstancesOf(DateTime::class);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('failures', function () {
|
||||||
|
expect($this->times)->toContainOnlyInstancesOf(DateTime::class);
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
|
test('not failures', function () {
|
||||||
|
expect($this->times)->not->toContainOnlyInstancesOf(DateTimeImmutable::class);
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
Reference in New Issue
Block a user