mirror of
https://github.com/pestphp/pest.git
synced 2026-03-12 02:37:22 +01:00
feat(expectations): add toStartWith
This commit is contained in:
@ -158,6 +158,16 @@ final class Expectation
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asserts that the value starts with $expected.
|
||||||
|
*/
|
||||||
|
public function toStartWith(string $expected): Expectation
|
||||||
|
{
|
||||||
|
Assert::assertStringStartsWith($expected, $this->value);
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Asserts that $count matches the number of elements of the value.
|
* Asserts that $count matches the number of elements of the value.
|
||||||
*/
|
*/
|
||||||
|
|||||||
15
tests/Expect/toStartWith.php
Normal file
15
tests/Expect/toStartWith.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
test('pass', function () {
|
||||||
|
expect('username')->toStartWith('user');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('failures', function () {
|
||||||
|
expect('username')->toStartWith('password');
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
|
test('not failures', function () {
|
||||||
|
expect('username')->not->toStartWith('user');
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
Reference in New Issue
Block a user