k2gl/phpunit-fluent-assertions
最新稳定版本:12.0.0
Composer 安装命令:
composer require --dev k2gl/phpunit-fluent-assertions
包简介
Improves test code readability.
README 文档
README
This library is insperated by Vladimir Khorikov, the author of Unit Testing: Principles, Patterns and Practices and makes checks in tests more readable.
Installation
You can add this library as a local, per-project dependency to your project using Composer:
composer require --dev k2gl/phpunit-fluent-assertions
Usage
Write tests as usual, just use fluent assertions short aliases check($x)->...;, expect($x)->...; or fact($x)->...; instead of self::assert...($x, $y).
// arrange $user = UserFactory::createOne([ 'phone' => $phoneBefore = faker()->e164PhoneNumber; ]); // act $user->setPhone( $phoneAfter = faker()->e164PhoneNumber ); // assert // traditional PHPUnit assertions self::assertSame(expected: $phoneAfter, actual: $user->getPhone()); self::assertNotSame(expected: $phoneBefore, actual: $user->getPhone()); // fluent assertions fact($user->getPhone()) ->is($phoneAfter) ->equals($phoneAfter) ->not($phoneBefore) ->true() ->notTrue() ->false() ->notFalse() ->null() ->notNull() ->matchesRegularExpression('#^\d+$#') ->notMatchesRegularExpression('#^\D+$#') ->containsString('alpha') ->notContainsString('alpha') ->containsStringIgnoringCase('beta') ->notContainsStringIgnoringCase('beta') ->count(5) ->notCount(5) ->arrayHasKey('echo') ->arrayNotHasKey('echo') ->instanceOf(UserFactory::class) ->notInstanceOf(UserFactory::class) ->ulid() // Universally Unique Lexicographically Sortable Identifier https://github.com/ulid/spec ... ; fact( [ 'a' => ['any' => 'thing'], 'b' => ['any' => 'thing', 'type' => 'candy', 'color' => 'green'], 'c' => ['miss' => 'kiss', 'foo' => 'bar', 'any' => 'thing'], 'd' => ['any' => 'thing'], ] )->arrayContainsAssociativeArray( [ 'c' => ['foo' => 'bar', 'miss' => 'kiss'], 'b' => ['color' => 'green'], ] ); // true
Pull requests are always welcome
统计信息
- 总下载量: 4.72k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-03-08