定制 jbzoo/phpunit 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

jbzoo/phpunit

最新稳定版本:7.2.0

Composer 安装命令:

composer require --dev jbzoo/phpunit

包简介

PHPUnit toolbox with short assert aliases and useful functions around testing

README 文档

README

CI Coverage Status Psalm Coverage Psalm Level CodeFactor Stable Version Total Downloads Dependents GitHub License

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) - assertEquals
  • isNot($expected, $actual) - assertNotEquals
  • isSame($expected, $actual) - assertSame
  • isNotSame($expected, $actual) - assertNotSame
  • isTrue($value) - assertTrue
  • isFalse($value) - assertFalse
  • isNull($value) - assertNull
  • isNotNull($value) - assertNotNull
  • isEmpty($value) - assertEmpty
  • isNotEmpty($value) - assertNotEmpty

Arrays & Objects

  • isKey($key, $array) - assertArrayHasKey
  • isNotKey($key, $array) - assertArrayNotHasKey
  • isAttr($name, $object) - Check object attribute exists
  • isNotAttr($name, $object) - Check object attribute doesn't exist
  • isClass($expected, $actual) - assertInstanceOf
  • isCount($expected, $countable) - assertCount

Strings & RegExp

  • isLike($pattern, $value) - assertMatchesRegularExpression
  • isNotLike($pattern, $value) - assertDoesNotMatchRegularExpression
  • isContain($needle, $haystack) - String contains check
  • isNotContain($needle, $haystack) - String doesn't contain check

Files & Filesystem

  • isFile($path) - assertFileExists
  • isNotFile($path) - File doesn't exist
  • isDir($path) - Directory exists
  • isNotDir($path) - Directory doesn't exist
  • isFileEq($expected, $actual) - assertFileEquals
  • isFileContains($expected, $filepath) - File contains string
  • isFileNotContains($expected, $filepath) - File doesn't contain string

Extended Assertions

  • isEmail($email) - Valid email check
  • isNotEmail($email) - Invalid email check
  • isCurrentDate($date, $timeDiff) - Date is close to current time
  • isSameDate($expected, $actual, $format) - Date comparison
  • isAmount($expected, $actual, $allowableDiff) - Amount comparison with tolerance
  • isDiffBetweenDates($date1, $date2, $expectedDiff) - Time difference check

Test Control

  • skip($message) - markTestSkipped
  • fail($message) - fail test
  • incomplete($message) - markTestIncomplete
  • success($message) - Mark test as successful

Environment Detection

  • isWin() - Running on Windows
  • isTeamCity() - Running under TeamCity
  • isTravis() - Running under Travis CI
  • isPhpStorm() - 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

统计信息

  • 总下载量: 1.14M
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 6
  • 点击次数: 3
  • 依赖项目数: 29
  • 推荐数: 0

GitHub 信息

  • Stars: 5
  • Watchers: 3
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-04

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固