feat(expectations): add toEndWith

This commit is contained in:
Owen Voke
2020-09-16 08:21:46 +01:00
parent cad8a41e6d
commit 04fafe742c
2 changed files with 25 additions and 0 deletions

View File

@ -168,6 +168,16 @@ final class Expectation
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.
*/

View 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);