MockAxeBuilder

Playwright\Accessibility\Testing\MockAxeBuilder

Mock AxeBuilder for testing without a real browser.
This allows you to simulate accessibility test results in your unit tests
without needing to run Playwright or have axe-core available.

$ composer require playwright-php/accessibility

Methods

create()

self

Create a new mock builder.

function create(): self

withViolation()

self

Add a violation to the mock results.

function withViolation( RuleId|string $ruleId, ImpactLevel|string $impact = 'serious', array $selectors = [], ?string $help = null, ): self

withPass()

self

Add a passing rule to the mock results.

function withPass(string $ruleId): self

withIncomplete()

self

Add an incomplete rule to the mock results.

function withIncomplete(string $ruleId): self

withInapplicable()

self

Add an inapplicable rule to the mock results.

function withInapplicable(string $ruleId): self

withNoViolations()

self

Simulate an accessible page with no violations.

function withNoViolations(): self

within()

self

Fluent API compatibility: within() (no-op in mock).

function within(string $selector): self

exclude()

self

Fluent API compatibility: exclude() (no-op in mock).

function exclude(string $selector): self

withTags()

self

Fluent API compatibility: withTags() (no-op in mock).

function withTags(array $tags): self

withoutRules()

self

Fluent API compatibility: withoutRules() (filters out violations in mock).

function withoutRules(array $rules): self

analyze()

AxeResults

Generate the mock AxeResults.

function analyze(): AxeResults