- 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.