astrotomic/phpunit-assertions
Composer 安装命令:
composer require astrotomic/phpunit-assertions
包简介
Set of common PHPUnit custom assertions.
关键字:
README 文档
README
This package provides a set of common PHPUnit custom assertions.
Some require optional packages - check the composer.json[suggest] section for more details.
Installation
composer require --dev astrotomic/phpunit-assertions
Usage
Even if all assertions are in traits I highly recommend you to don't use these traits in your test classes.
Instead you can access all assertions as static methods on the traits.
\Astrotomic\PhpunitAssertions\StringLengthAssertions::assertSame(10, 'Astrotomic');
This will prevent any method name conflicts with core, your custom or other trait assertions.
Assertions
Array
\Astrotomic\PhpunitAssertions\ArrayAssertions::assertIndexed(['foo', 'bar']); \Astrotomic\PhpunitAssertions\ArrayAssertions::assertAssociative(['foo' => 'bar']); \Astrotomic\PhpunitAssertions\ArrayAssertions::assertEquals(['foo', 'bar'], ['bar', 'foo']); \Astrotomic\PhpunitAssertions\ArrayAssertions::assertSubset(['foo' => 'bar'], ['baz' => 'foo', 'foo' => 'bar']); \Astrotomic\PhpunitAssertions\ArrayAssertions::assertContainsAll(['foo', 'bar'], ['baz', 'foo', 'lorem', 'ipsum', 'bar']);
Country
composer require --dev league/iso3166:^3.0
\Astrotomic\PhpunitAssertions\CountryAssertions::assertName('Germany'); \Astrotomic\PhpunitAssertions\CountryAssertions::assertAlpha2('DE'); \Astrotomic\PhpunitAssertions\CountryAssertions::assertAlpha3('DEU'); \Astrotomic\PhpunitAssertions\CountryAssertions::assertNumeric('276');
composer require --dev egulias/email-validator:^3.0
\Astrotomic\PhpunitAssertions\EmailAssertions::assertValidLoose('gummibeer@astrotomic.info'); \Astrotomic\PhpunitAssertions\EmailAssertions::assertValidStrict('gummibeer@astrotomic.info'); \Astrotomic\PhpunitAssertions\EmailAssertions::assertDomain('astrotomic.info', 'gummibeer@astrotomic.info'); \Astrotomic\PhpunitAssertions\EmailAssertions::assertLocalPart('gummibeer', 'gummibeer@astrotomic.info'); \Astrotomic\PhpunitAssertions\EmailAssertions::assertPlusMailbox('gummibeer', 'gummibeer+news@astrotomic.info'); \Astrotomic\PhpunitAssertions\EmailAssertions::assertPlusAlias('news', 'gummibeer+news@astrotomic.info');
Geographic
\Astrotomic\PhpunitAssertions\GeographicAssertions::assertLatitude(53.551085); \Astrotomic\PhpunitAssertions\GeographicAssertions::assertLongitude(9.993682); \Astrotomic\PhpunitAssertions\GeographicAssertions::assertCoordinates([ 'lat' => 53.551085, 'lng' => 9.993682, ]);
HashID
composer require --dev hashids/hashids:^4.0
\Astrotomic\PhpunitAssertions\HashidAssertions::assertHashIds('3kTMd', 2, 'this is my salt'); \Astrotomic\PhpunitAssertions\HashidAssertions::assertHashId('yr8', 'this is my salt');
Language
composer require --dev astrotomic/iso639:^1.0
\Astrotomic\PhpunitAssertions\LanguageAssertions::assertName('German'); \Astrotomic\PhpunitAssertions\LanguageAssertions::assertAlpha2('de');
Nullable Type
\Astrotomic\PhpunitAssertions\NullableTypeAssertions::assertIsNullableString('Astrotomic'); \Astrotomic\PhpunitAssertions\NullableTypeAssertions::assertIsNullableInt(42); \Astrotomic\PhpunitAssertions\NullableTypeAssertions::assertIsNullableFloat(42.5); \Astrotomic\PhpunitAssertions\NullableTypeAssertions::assertIsNullableArray(['Astrotomic' => 'Gummibeer']); \Astrotomic\PhpunitAssertions\NullableTypeAssertions::assertIsNullableBool(true);
Phone Number
composer require --dev giggsey/libphonenumber-for-php:^8.12
\Astrotomic\PhpunitAssertions\PhoneNumberAssertions::assertE164('+498001110550'); \Astrotomic\PhpunitAssertions\PhoneNumberAssertions::assertValid('+49 800 - 111 0 550'); \Astrotomic\PhpunitAssertions\PhoneNumberAssertions::assertValidForRegion('+49 800 - 111 0 550', 'DE');
String
\Astrotomic\PhpunitAssertions\StringLengthAssertions::assertSame(10, 'Astrotomic'); \Astrotomic\PhpunitAssertions\StringLengthAssertions::assertNotSame(8, 'Astrotomic'); \Astrotomic\PhpunitAssertions\StringLengthAssertions::assertLessThan(11, 'Astrotomic'); \Astrotomic\PhpunitAssertions\StringLengthAssertions::assertLessThanOrEqual(10, 'Astrotomic'); \Astrotomic\PhpunitAssertions\StringLengthAssertions::assertGreaterThan(9, 'Astrotomic'); \Astrotomic\PhpunitAssertions\StringLengthAssertions::assertGreaterThanOrEqual(10, 'Astrotomic');
URL
\Astrotomic\PhpunitAssertions\UrlAssertions::assertValidLoose('https://astrotomic.info'); \Astrotomic\PhpunitAssertions\UrlAssertions::assertScheme('https', 'https://astrotomic.info'); \Astrotomic\PhpunitAssertions\UrlAssertions::assertHost('astrotomic.info', 'https://astrotomic.info'); \Astrotomic\PhpunitAssertions\UrlAssertions::assertPath('/contributor/gummibeer/', 'https://astrotomic.info/contributor/gummibeer/'); \Astrotomic\PhpunitAssertions\UrlAssertions::assertQuery(['_' => '123', 'q' => 'search'], 'https://astrotomic.info?q=search&_=123'); \Astrotomic\PhpunitAssertions\UrlAssertions::assertComponent('gummibeer', 'https://gummibeer@astrotomic.info', PHP_URL_USER);
Path
\Astrotomic\PhpunitAssertions\PathAssertions::assertDirname('/foo/bar', '/foo/bar/image.jpg'); \Astrotomic\PhpunitAssertions\PathAssertions::assertBasename('image.jpg', '/foo/bar/image.jpg'); \Astrotomic\PhpunitAssertions\PathAssertions::assertFilename('image', '/foo/bar/image.jpg'); \Astrotomic\PhpunitAssertions\PathAssertions::assertExtension('jpg', '/foo/bar/image.jpg');
UUID
composer require --dev ramsey/uuid:^4.0
\Astrotomic\PhpunitAssertions\UuidAssertions::assertUuid('52d08e38-ad24-4960-af02-22e0f7e0db8d');
Laravel Assertions
Collection
\Astrotomic\PhpunitAssertions\Laravel\CollectionAssertions::assertContains($collection, 'Astrotomic');
HashID
composer require --dev vinkla/hashids:^9.0
\Astrotomic\PhpunitAssertions\Laravel\HashidAssertions::assertHashIds('3kTMd', 2); \Astrotomic\PhpunitAssertions\Laravel\HashidAssertions::assertHashId('yr8');
Model
\Astrotomic\PhpunitAssertions\Laravel\ModelAssertions::assertExists($model); \Astrotomic\PhpunitAssertions\Laravel\ModelAssertions::assertSame($model, \App\Models\User::first()); \Astrotomic\PhpunitAssertions\Laravel\ModelAssertions::assertRelated($post, 'comments', $comment); \Astrotomic\PhpunitAssertions\Laravel\ModelAssertions::assertRelated( $post, 'comments', \App\Models\Comment::class, \Illuminate\Database\Eloquent\Relations\HasMany::class );
Blade
composer require --dev gajus/dindent:^2.0
\Astrotomic\PhpunitAssertions\Laravel\BladeAssertions::assertRenderEquals( "<p>Price: <code>99.99 €</code></p>", '<p>Price: <code>{{ number_format($price, 2) }} €</code></p>', ['price' => 99.99] );
astrotomic/phpunit-assertions 适用场景与选型建议
astrotomic/phpunit-assertions 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.23k 次下载、GitHub Stars 达 18, 最近一次更新时间为 2021 年 01 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「phpunit」 「assertions」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 astrotomic/phpunit-assertions 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 astrotomic/phpunit-assertions 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 astrotomic/phpunit-assertions 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Additional assertions for PHPUnit
Custom annotations and expectations for PHPUnit.
A collection of helpers for PHPUnit to ease testing Tarantool libraries.
HiDev plugin for PHPUnit
Testing Suite For Lumen like Laravel does.
A cli tool which generates unit tests.
统计信息
- 总下载量: 8.23k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 18
- 点击次数: 10
- 依赖项目数: 10
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-01-16