villfa / phpunit-extra-constraints
Extra constraints for PHPUnit
1.2.0
2020-11-01 19:49 UTC
Requires
- php: >=7.2
- phpunit/phpunit: 8.* || 9.*
Requires (Dev)
- linfo/linfo: ^4.0
- phpstan/phpstan: ^0.12.18
- phpstan/phpstan-phpunit: ^0.12.6
- phpstan/phpstan-strict-rules: ^0.12.2
- squizlabs/php_codesniffer: ^3.5
- villfa/composer-substitution-plugin: ^1.0
- vimeo/psalm: >=3.11.4
README
Installation
composer require --dev villfa/phpunit-extra-constraints
Usage
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')); } }
Available extra constraints
- 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
Tests
To validate and test the library:
composer run-script test
License
Other libraries proposing extra constraints
- 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)