codeception/lib-asserts
Lightweight assertion library used by Codeception. Provides clear, dependency-free assert helpers for writing expressive tests in PHP, with informative failure messages and easy integration into any PHPUnit-style workflow.
Install via Composer:
composer require codeception/lib-asserts --dev
No bootstrapping required—just import assertions directly:
use Codeception\Asserts;
// In your test or utility script
Asserts::equals($actual, $expected, 'User should be active');
Asserts::isTrue($user->isActive(), 'User status check');
Asserts::contains('admin', $roles, 'Roles should include admin');
Start with the most common assertions (equals, isEmpty, isTrue, contains, throws) to validate simple business logic in unit tests, custom test runners, or CI validation scripts.
Asserts::isNotBlankEmail($value)) wrapping lib-asserts for reusable validation logic.lib-asserts in PHPSpec, PHPUnit, or plain CLI scripts—especially where you want consistent failure messages without phpunit/phpunit as a hard dependency.Asserts::isTrue(file_exists('.env'), 'Environment file missing')).Asserts::hasStatusCode(201) for API tests) by extending Asserts class and overriding fail() for custom reporting.->assertEquals(), methods are static and not chainable—write Asserts::equals($a, $b) on separate lines.Asserts::equals() failed: User should be active). For fine-grained control, use Asserts::equals($a, $b) and pass an empty string '' to suppress default prefix if desired.equals() is not strict—use strictEquals() for identical type+value checks. Default equals() uses ==; prefer explicit types when validating numeric strings or booleans.throws() requires a callable and optionally an expected class/message. Remember to wrap in a closure: Asserts::throws(RuntimeException::class, fn() => $subject->action()).Asserts and override fail($message) to redirect output to custom loggers (e.g., Monolog), CI annotations, or Slack alerts.2026-02-06 in the description is likely a placeholder—verify the latest stable tag on Packagist for production use.How can I help you explore Laravel packages today?