Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Lib Asserts Laravel Package

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.

View on GitHub
Deep Wiki
Context7

Getting Started

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.

Implementation Patterns

  • Custom Assertion Libraries: Build domain-specific assertions (e.g., Asserts::isNotBlankEmail($value)) wrapping lib-asserts for reusable validation logic.
  • Integration with Test Frameworks: Use lib-asserts in PHPSpec, PHPUnit, or plain CLI scripts—especially where you want consistent failure messages without phpunit/phpunit as a hard dependency.
  • CI Validation Hooks: Embed assertions in deployment checks or schema validation scripts (e.g., Asserts::isTrue(file_exists('.env'), 'Environment file missing')).
  • Test DSL Construction: Layer expressive macros (e.g., Asserts::hasStatusCode(201) for API tests) by extending Asserts class and overriding fail() for custom reporting.
  • Mixed Test Environments: In monorepos or polyglot projects, use assertions to validate non-PHP outputs (e.g., JSON response from a Go microservice via CLI) in a unified test suite.

Gotchas and Tips

  • No assertion chaining: Unlike PHPUnit’s ->assertEquals(), methods are static and not chainable—write Asserts::equals($a, $b) on separate lines.
  • Failure message formatting: Messages are prepended with method name (e.g., 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.
  • Type coercion differences: equals() is not strict—use strictEquals() for identical type+value checks. Default equals() uses ==; prefer explicit types when validating numeric strings or booleans.
  • Exception assertions: throws() requires a callable and optionally an expected class/message. Remember to wrap in a closure: Asserts::throws(RuntimeException::class, fn() => $subject->action()).
  • Extensibility: Extend Asserts and override fail($message) to redirect output to custom loggers (e.g., Monolog), CI annotations, or Slack alerts.
  • Versioning note: The release date 2026-02-06 in the description is likely a placeholder—verify the latest stable tag on Packagist for production use.
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
davejamesmiller/laravel-breadcrumbs
artisanry/parsedown
christhompsontldr/phpsdk
enqueue/dsn
bunny/bunny
enqueue/test
enqueue/null
enqueue/amqp-tools
bower-asset/punycode
bower-asset/inputmask
bower-asset/jquery
bower-asset/yii2-pjax
laravel/nova
spatie/laravel-mailcoach
spatie/laravel-superseeder
laravel/liferaft
nst/json-test-suite
danielmiessler/sec-lists
jackalope/jackalope-transport
twbs/bootstrap4