jbzoo / phpunit
PHPUnit toolbox with short assert aliases and useful functions around testing
Installs: 1 137 753
Dependents: 29
Suggesters: 0
Security: 0
Stars: 5
Watchers: 3
Forks: 0
Open Issues: 0
Requires
- php: ^8.2
- ext-filter: *
- ext-mbstring: *
- jbzoo/markdown: ^7.0.1
- phpunit/phpunit: ^11.5.41
- ulrichsg/getopt-php: >=4.0.4
Requires (Dev)
- guzzlehttp/guzzle: >=7.10.0
- jbzoo/codestyle: ^7.1.6
- jbzoo/data: ^7.1
- jbzoo/http-client: ^7.1
- jbzoo/toolbox-dev: ^7.1
- jbzoo/utils: ^7.2
- symfony/process: >=7.3.4
- dev-master / 7.x-dev
- 7.2.0
- 7.1.3
- 7.1.2
- 7.1.1
- 7.1.0
- 7.0.0
- 5.0.0
- 4.13.1
- 4.13.0
- 4.12.0
- 4.11.1
- 4.11.0
- 4.10.0
- 4.9.0
- 4.8.0
- 4.7.0
- 4.6.2
- 4.6.1
- 4.6.0
- 4.5.0
- 4.4.6
- 4.4.5
- 4.4.4
- 4.4.3
- 4.3.1
- 4.3.0
- 4.2.0
- 4.1.1
- 4.1.0
- 4.0.0
- 3.2.0
- 3.1.0
- 3.0.0
- 2.3.0
- 2.2.2
- 2.2.1
- 2.2.0
- 2.1.2
- 2.1.1
- 2.1.0
- 2.0.7
- 2.0.6
- 2.0.5
- 2.0.4
- 2.0.3
- 2.0.2
- 2.0.1
- 2.0
- 1.11.0
- 1.10.1
- 1.10.0
- 1.9.0
- 1.8.0
- 1.7.1
- 1.7.0
- 1.6.1
- 1.6.0
- 1.5.12
- 1.5.11
- 1.5.10
- 1.5.9
- 1.5.8
- 1.5.7
- 1.5.6
- 1.5.5
- 1.5.4
- 1.5.3
- 1.5.2
- 1.5.1
- 1.5.0
- 1.4.0
- 1.3.0
- 1.2.8
- 1.2.7
- 1.2.6
- 1.2.5
- 1.2.4
- 1.2.3
- 1.2.2
- 1.2.1
- 1.2.0
- 1.1.3
- 1.1.2
- 1.1.1
- 1.1.0
- 1.0.11
- 1.0.10
- 1.0.9
- 1.0.7
- 1.0.6
- 1.0.5
- 1.0.4
- 1.0.3
- 1.0.2
- 1.0.1
- 1.0.0
- dev-bump-phpunit
- dev-fix-perms
- dev-alert-autofix-8
- dev-bump
- dev-docs
- dev-fix-linter
This package is auto-updated.
Last update: 2025-09-27 19:27:20 UTC
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