Weave 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
Phpunit Pest Html Assertions

Phpunit Pest Html Assertions Laravel Package

sorge-it/phpunit-pest-html-assertions

HTML assertion helpers for PHPUnit and Pest. Assert the structure and content of HTML responses with readable, chainable methods instead of brittle string matching, ideal for Laravel feature tests and works with both PHPUnit and Pest suites.

Deep Wiki
Context7

sorge-it/phpunit-pest-html-assertions brings expressive HTML assertions to PHPUnit and Pest, so you can verify rendered markup without brittle string comparisons. Assert on real DOM structure using CSS selectors and readable, chainable methods—ideal for testing Blade views, components, and API responses.

  • Assert elements exist or are missing by CSS selector
  • Check text content, attributes, and element counts
  • Works seamlessly with both PHPUnit and Pest
  • Fluent, readable API with clear failure messages
  • Lightweight, no extra configuration required
Frequently asked questions about Phpunit Pest Html Assertions
How do I install sorge-it/phpunit-pest-html-assertions?
Install it with Composer as a dev dependency using composer require --dev sorge-it/phpunit-pest-html-assertions. It is designed for test suites, so keep it out of production dependencies. After installation, use the provided assertions in your PHPUnit or Pest tests. If your project uses Laravel, no special application bootstrapping is mentioned beyond normal test setup.
Does this package work with Laravel?
Yes, the package blurb says it integrates cleanly with Laravel and plain PHP test suites. It is intended for validating rendered HTML in tests, which fits Laravel response and view testing. The package does not appear to be Laravel-only, so you can also use it in non-Laravel PHP projects. For Laravel-specific helpers, rely on the documented assertions in the package.
Is it compatible with Pest as well as PHPUnit?
Yes. The package name and description explicitly cover PHPUnit and Pest HTML assertions. You can use the same chainable assertions in either test runner. Check the package README for any runner-specific setup or examples. Both are first-class targets according to the overview.
What kinds of HTML assertions can I write?
The package provides expressive, chainable assertions for checking elements, attributes, text, and structure using CSS selectors. This lets you validate rendered markup without brittle string matching. Typical tests assert that a selector exists, that an attribute has a value, or that text appears in the right element. Refer to the README for the exact assertion method names and chaining syntax.
How does it avoid brittle string matching?
Instead of comparing raw HTML strings, the assertions use CSS selectors to locate parts of the DOM and then inspect elements, attributes, and text. That makes tests resilient to unrelated markup changes such as whitespace, attribute order, or surrounding content. You still get precise checks, but they are scoped to the structure you care about.
What are the PHPStan rules for?
The package includes PHPStan rules, according to its description. These are likely intended to catch incorrect or unsafe usage of the HTML assertions in your test code during static analysis. Add them to your PHPStan configuration if you want that extra safety. See the package documentation for the exact rule names and setup.
What does the Rector rule do?
The package ships a Rector rule, which is typically used to automate code upgrades or refactors. In this context, it may help migrate existing tests to the package's assertion style or keep usage consistent. Enable it in your Rector configuration if it matches your upgrade path. The README should list the exact rule class and before/after examples.
Is there support for AI coding agents?
Yes, the description mentions a skill for AI coding agents. That likely provides guidance or context so agents can write correct assertions when working in your codebase. It is not required for normal test usage. Check the repository for how to install or reference the skill.
Can I use this in production code?
This is a testing package for PHPUnit and Pest, so it should be installed as a dev dependency and used in test code, not in production runtime. Keep it in require-dev and avoid loading it in production deployments. If you generate HTML in production, use your application's own rendering and validation logic instead.
How is the package maintained and what are the alternatives?
The repository field is unknown in the provided context, so verify the package on Packagist and the linked source repository before adopting it. Check release history, Laravel and PHP version support, and open issues for maintenance signals. Alternatives include raw DOMDocument or XPath assertions, Symfony DomCrawler, or Laravel's built-in test response assertions for common cases. Choose based on whether you need chainable CSS-selector assertions across both PHPUnit and Pest.
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.
robertmarney/lara-hierarchial-collections
simonschaufi/rule-doc-generator
emissaoja/emissaoja
blackbricksoftware/gravityforms-civicrm-form-processor
al-rahabi/fancy-crud
jinas/dhivatar-component
mltstephane/laravel-quality
bernskiold/laravel-talentlms
bernskioldmedia/laravel-form-architect
youbar/easy-crud
c-point-labs/laravel-hostyourai
dbravoan/dbcms-admin-theme-dbcms
dbravoan/dbcms-theme-db-cyber
dbravoan/dbcms-blocks-basic
dbravoan/dbcms-module-content-audit
dbravoan/dbcms-module-ai-assistant
paygate-to/paygate-php
padosoft/askmydocs-connector-base
defstudio/supercharged-carbon
bernskioldmedia/laravel-matomo