composer require --dev villfa/phpunit-extra-constraints
Here a basic example:
<?php
require_once 'vendor/autoload.php';
use PHPUnitExtraConstraints\Constraint\IsDate;
class ExampleTest extends PHPUnit\Framework\TestCase
{
public function testDate(): void
{
$this->assertThat('2020-04-02', new IsDate('Y-m-d'));
}
}
- IsDate: asserts that a string is a valid date according a given format
- IsEmail: asserts that a string contains only an email address
- IsJSON: asserts that the value is a decodable JSON string
- IsList: asserts that the value is a sequential list
- IsURL: asserts that a string contains only an URL
- StringEndsWith: asserts that a string ends with another string
- StringStartsWith: asserts that a string starts with another string
To validate and test the library:
composer run-script test
- https://github.com/etsy/phpunit-extensions
- https://github.com/ergebnis/phpunit-framework-constraint
- https://github.com/Datamedrix/phpunit-ext
- https://github.com/spawnia/phpunit-assert-directory
- https://github.com/MarcinOrlowski/phpunit-extra-asserts
- https://github.com/kuria/phpunit-extras
- https://github.com/martin-helmich/phpunit-json-assert
- https://github.com/GeckoPackages/GeckoPHPUnit (Abandoned)