mirror of
https://github.com/pestphp/pest.git
synced 2026-03-11 18:27:23 +01:00
Merge pull request #187 from owenvoke/feature/assert-string
feat: add 'toStartWith' and 'toEndWith' expectations
This commit is contained in:
@ -158,6 +158,26 @@ 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 the value ends with $expected.
|
||||||
|
*/
|
||||||
|
public function toEndWith(string $expected): Expectation
|
||||||
|
{
|
||||||
|
Assert::assertStringEndsWith($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.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@ -155,6 +155,11 @@
|
|||||||
✓ passes strings
|
✓ passes strings
|
||||||
✓ passes arrays
|
✓ passes arrays
|
||||||
✓ failures
|
✓ failures
|
||||||
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Expect\toEndWith
|
||||||
|
✓ pass
|
||||||
|
✓ failures
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Expect\toEqual
|
PASS Tests\Expect\toEqual
|
||||||
@ -195,6 +200,11 @@
|
|||||||
PASS Tests\Expect\toMatchObject
|
PASS Tests\Expect\toMatchObject
|
||||||
✓ pass
|
✓ pass
|
||||||
✓ failures
|
✓ failures
|
||||||
|
✓ not failures
|
||||||
|
|
||||||
|
PASS Tests\Expect\toStartWith
|
||||||
|
✓ pass
|
||||||
|
✓ failures
|
||||||
✓ not failures
|
✓ not failures
|
||||||
|
|
||||||
PASS Tests\Features\AfterAll
|
PASS Tests\Features\AfterAll
|
||||||
@ -363,5 +373,5 @@
|
|||||||
✓ depends with defined arguments
|
✓ depends with defined arguments
|
||||||
✓ depends run test only once
|
✓ depends run test only once
|
||||||
|
|
||||||
Tests: 6 skipped, 214 passed
|
Tests: 6 skipped, 220 passed
|
||||||
|
|
||||||
15
tests/Expect/toEndWith.php
Normal file
15
tests/Expect/toEndWith.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use PHPUnit\Framework\ExpectationFailedException;
|
||||||
|
|
||||||
|
test('pass', function () {
|
||||||
|
expect('username')->toEndWith('name');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('failures', function () {
|
||||||
|
expect('username')->toEndWith('password');
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
|
|
||||||
|
test('not failures', function () {
|
||||||
|
expect('username')->not->toEndWith('name');
|
||||||
|
})->throws(ExpectationFailedException::class);
|
||||||
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