hshn / phpunit-object-constraint
v0.1.0
2018-01-17 15:20 UTC
Requires
- php: ^7.0.0
- phpunit/phpunit: ^5.7.5
- symfony/property-access: ^3.0.9|^2.8.15
This package is not auto-updated.
Last update: 2024-09-15 04:47:21 UTC
README
PHPUnit 对象比较助手。
通过提供简单的对象断言,使您的应用程序更加安全。
如何使用
1. 将助手特质导入您的类
use Hshn\PHPUnit\Framework\Constraint\ObjectConstraintSupport; class MyTest extends \PHPUnit_Framework_TestCase { use ObjectConstraintSupport; }
2. 使用约束构建器构建您的对象约束
public function test1() { // this constraint means: // property 'foo' start with 'a' and end with 'e' // and property 'bar' is true $constraint = $this->constraintFor(\stdClass::class) ->property('foo') ->stringStartsWith('a') ->stringEndsWith('e') ->property('bar') ->isTrue() ->getConstraint(); }
3. 使用您构建的约束断言任何值
self::assertThat($value, $constraint);