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

Module Asserts Laravel Package

codeception/module-asserts

Codeception Asserts module adds rich assertion helpers for your tests, letting you use a wide set of PHPUnit-style assertions directly in Codeception suites. Ideal for unit, functional, and acceptance tests to keep checks readable and failures clear.

View on GitHub
Deep Wiki
Context7

Getting Started

Add codeception/module-asserts to your codeception.yaml module configuration (or _bootstrap.php if per-suite). No setup is required—just ensure it's listed in the modules section under enabled. First use case: replace raw PHPUnit\Framework\TestCase::assertEquals() calls in unit tests with Codeception-native syntax like $this->assertEquals() directly incest. Check tests/_support/AcceptanceTester.php (or similar) to see the module’s methods automatically injected into actor classes.

Implementation Patterns

  • Consistent assertion syntax: Use assertEquals(), assertTrue(), assertArraySubset(), assertJsonStringEqualsJsonString(), etc., identically across unit, functional, and acceptance tests.
  • BDD-style fluent assertions: Chain readable expectations like $I->assertEquals(42, $result, 'Expected result after calculation'); for better failure diagnostics.
  • Cross-suite reuse: Define custom helper methods in _helpers/Helper/Functional.php (or Unit) using $this->assert*() methods, then reuse across multiple test files without duplicating logic.
  • Validation in API tests: In REST/GraphQL scenarios, assert response payloads with assertJson($json), assertArrayHasKey(), or assertObjectHasAttribute() to validate structured responses.

Gotchas and Tips

  • Actor class limitations: In acceptance tests, methods like assertNotContains() must be invoked via $I->assertNotContains(...)—ensure your AcceptanceTester class includes the module’s traits (Codeception does this automatically if declared in codeception.yaml).
  • No global scope: These assertions do not replace PHPUnit’s native assertions in standalone PHP unit tests unless the module is properly configured—check that codeception.yml includes module: [asserts].
  • Custom failure context: Always provide the optional 3rd $message parameter (e.g., assertEquals($expected, $actual, 'Price should match after discount')) to surface test intent in logs.
  • Extension point: Override or extend behavior by subclassing the module in _support/Helper/Unit.php (e.g., to add internal metrics logging on assertion failure).
  • Avoid overuse: Don’t assert internal implementation details (e.g., array keys in private methods); reserve for public behavior and outcome validation only.
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