jbzoo/phpunit
Composer 安装命令:
composer require --dev jbzoo/phpunit
包简介
PHPUnit toolbox with short assert aliases and useful functions around testing
README 文档
README
PHPUnit toolbox with short assertion aliases and useful testing utilities. This library provides a more concise and readable way to write tests by offering shorter function names for common PHPUnit assertions.
Features
- Short assertion aliases - Use
isTrue()instead of$this->assertTrue() - Extended assertions - Additional assertions for emails, dates, amounts, file contents
- Environment detection - Detect if running under TeamCity, Travis, PhpStorm
- Built-in utilities - Tools for test organization and debugging
- PHP 8.2+ support - Modern PHP features and strict typing
Installation
composer require jbzoo/phpunit --dev
Quick Start
namespace JBZoo\PHPUnit; /** * Class PackageTest * @package JBZoo\PHPUnit */ class PackageTest extends PHPUnit { public function testSimple() { // Boolean isTrue(true); isFalse(false); // null isNull(null); // Check is variable empty isEmpty(0); isEmpty(''); isEmpty(null); isEmpty('0'); isEmpty(.0); isEmpty(array()); // Equals is(1, true); is(array(1, 2, 3), array(1, 2, 3)); isSame(array(1, 2, 3), array(1, 2, 3)); // Array, Object etc isKey('test', array('test' => true)); isNotKey('undef-kest', array('test' => true)); isAttr('test', (object)array('test' => true)); isNotAttr('undef-test', (object)array('test' => true)); // Instance Of ... isClass(JBZoo\PHPUnit\PHPUnit::class, $this); // Count props isCount(0, array()); isCount(1, array(1)); isCount(2, array(1, 3)); // regExp isLike('#t.st#i', 'TESTO'); isNotLike('#teeest#i', 'TESTO'); // Strings isContain('t', 'test'); isNotContain('x', 'test'); // Filesystem isFileEq(__FILE__, __FILE__); isFile(__FILE__); isDir(__DIR__); } public function testSkip() { skip('Some reason to skip this test'); } public function testFail() { fail('Some reason to fail this test'); } }
Available Assertions
Basic Assertions
is($expected, $actual)- assertEqualsisNot($expected, $actual)- assertNotEqualsisSame($expected, $actual)- assertSameisNotSame($expected, $actual)- assertNotSameisTrue($value)- assertTrueisFalse($value)- assertFalseisNull($value)- assertNullisNotNull($value)- assertNotNullisEmpty($value)- assertEmptyisNotEmpty($value)- assertNotEmpty
Arrays & Objects
isKey($key, $array)- assertArrayHasKeyisNotKey($key, $array)- assertArrayNotHasKeyisAttr($name, $object)- Check object attribute existsisNotAttr($name, $object)- Check object attribute doesn't existisClass($expected, $actual)- assertInstanceOfisCount($expected, $countable)- assertCount
Strings & RegExp
isLike($pattern, $value)- assertMatchesRegularExpressionisNotLike($pattern, $value)- assertDoesNotMatchRegularExpressionisContain($needle, $haystack)- String contains checkisNotContain($needle, $haystack)- String doesn't contain check
Files & Filesystem
isFile($path)- assertFileExistsisNotFile($path)- File doesn't existisDir($path)- Directory existsisNotDir($path)- Directory doesn't existisFileEq($expected, $actual)- assertFileEqualsisFileContains($expected, $filepath)- File contains stringisFileNotContains($expected, $filepath)- File doesn't contain string
Extended Assertions
isEmail($email)- Valid email checkisNotEmail($email)- Invalid email checkisCurrentDate($date, $timeDiff)- Date is close to current timeisSameDate($expected, $actual, $format)- Date comparisonisAmount($expected, $actual, $allowableDiff)- Amount comparison with toleranceisDiffBetweenDates($date1, $date2, $expectedDiff)- Time difference check
Test Control
skip($message)- markTestSkippedfail($message)- fail testincomplete($message)- markTestIncompletesuccess($message)- Mark test as successful
Environment Detection
isWin()- Running on WindowsisTeamCity()- Running under TeamCityisTravis()- Running under Travis CIisPhpStorm()- Running in PhpStorm
Requirements
- PHP 8.2 or higher
- PHPUnit ^9.6.29
- ext-filter, ext-mbstring
Contributing
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
License
MIT
jbzoo/phpunit 适用场景与选型建议
jbzoo/phpunit 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1.15M 次下载、GitHub Stars 达 5, 最近一次更新时间为 2015 年 10 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「debug」 「testing」 「phpunit」 「assert」 「assertion」 「aliases」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 jbzoo/phpunit 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 jbzoo/phpunit 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 jbzoo/phpunit 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Debug your SimpleBus EventBus and CommandBus
HiDev plugin for PHPUnit
nice output for debug functions for PHP 5.3
Testing Suite For Lumen like Laravel does.
A cli tool which generates unit tests.
Analysis module for finding problematical shop data.
统计信息
- 总下载量: 1.15M
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 6
- 点击次数: 33
- 依赖项目数: 29
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2015-10-14