Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@
/.github export-ignore
/.gitattributes export-ignore
/.gitignore export-ignore
/CODE_OF_CONDUCT.md export-ignore
/CONTRIBUTING.md export-ignore
/SECURITY.md export-ignore
/composer.lock export-ignore
/context7.json export-ignore
/demo export-ignore
Expand All @@ -17,3 +14,4 @@
/rector.php export-ignore
/stubs export-ignore
/tests export-ignore
/type-coverage.xml export-ignore
File renamed without changes.
121 changes: 121 additions & 0 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
# Contributing

Pull requests are welcome. The issue tracker is closed: report a bug as a pull request with a
failing test; a fix is welcome but not required. Report a vulnerability privately instead; see the
[security policy](https://github.com/sorge-it/phpunit-pest-html-assertions/security/policy).
Everyone who takes part follows the
[Code of Conduct](https://github.com/sorge-it/phpunit-pest-html-assertions/blob/main/.github/CODE_OF_CONDUCT.md).

## Scope

Read [When to use it and when not to](https://github.com/sorge-it/phpunit-pest-html-assertions#when-to-use-it-and-when-not-to)
and [Scope](https://github.com/sorge-it/phpunit-pest-html-assertions#scope) in the README first. A
feature outside the scope, such as a check of the DOM after a script ran, will not be merged.

- There is no `tests/Scope/out.php` with a guard for each `out` row: this package copies no
reference implementation, so no out-of-scope behavior can come back from one. The row on
`<template>` has its test in `tests/PHPUnit/HtmlTest.php` instead.
- The list "Do not use it for" in the README gives the reason and the tool for the other `out` rows.
- A new `out` row comes with its reason, and with a test that shows the package does not do it where
it easily could, as the test of `<template>` does.

## Setup

You need Composer 2.4 or later, PHP 8.3 or a later 8.x with the `dom`, `intl` and `mbstring`
extensions, and pcov or Xdebug for line coverage. Without `intl`, the lowest versions fail in the
Rector tests.

```sh
composer install
```

`composer.json` sets the platform to PHP 8.3, so `composer.lock` holds versions that run on the
lowest PHP the package supports.

## Tests

Before you open a pull request:

```sh
composer lint # Rector, then Pint
composer test # the dry runs of both, PHPStan at max, 100% type coverage, every suite
composer test:coverage # 100% line coverage, needs pcov or Xdebug
composer validate --strict # composer.json against its schema
composer audit --locked # advisories for the locked packages, needs the network
```

PHPStan and Rector read `src` and `tests` without the fixtures; PHPStan also leaves out
`tests/Pest`. The type coverage reads all of `src` and `tests`. Pint reads the whole tree without
the fixtures.

The code must run on PHP 8.3 to 8.5, with the lowest and the newest versions that `composer.json`
allows, and on macOS.

The checkout of the package keeps the frames of the package in the trace of a failure; a project
hides them unless `HTML_ASSERTIONS_SHOW_FRAMES=1` is set in the shell.

When a message or the output of a check changes, re-record the README's demo and the social preview
with `make -C demo all` (needs Docker).

A workflow uses zizmor to audit the workflows and the Dependabot configuration in `.github`, and
actionlint to check the workflows. Run both when you change anything there:

```sh
docker build --quiet --tag zizmor .github/docker/zizmor
docker run --rm --volume "$PWD:/src:ro" --workdir /src zizmor --offline .github
docker build --quiet --tag actionlint .github/docker/actionlint
docker run --rm --volume "$PWD:/src:ro" --workdir /src actionlint -no-color
```

### Mutation tests

A workflow runs the mutation tests every week. Run them with pcov when you change `src/`. They run
one mutant after another, so run only the files you changed, with `--path`. Do not use
`--parallel`: with it, Pest Mutate counts each mutant as killed.

```sh
composer test:mutation # fails when the tests kill fewer than 97% of the mutants
composer test:mutation -- --path=src/PHPUnit/Html.php # only the mutants of that file
```

- `src/Pest/Expectations.php` and `src/PHPUnit/StackTrace.php` are left out. The two `Autoload.php`
in the `files` of `composer.json` load both classes before Pest Mutate can swap in a mutant, so no
test could ever see one.
- Most of the other survivors change nothing that a test could see, for example `?? ''` after the
`localName` of a `DOMElement`, which is never null. One more survives because its test would need
Livewire, which is not a dependency of the package. A new survivor in your change is either a
missing test or another such case; say which in the pull request.

## What the package ships

`.gitattributes` excludes everything from the Composer archive except `src/`, `README.md`,
`CHANGELOG.md`, `LICENSE`, `composer.json` and two more:

- `extension.neon`, which `phpstan/extension-installer` loads from `vendor/`;
- `resources/`, where Laravel Boost reads the guideline and the skill.

## Pull requests

### Reporting a bug

Open a pull request that contains only a failing test, with what you expected and the output of
`php -v`. A maintainer adds the fix. If you cannot write the test yourself, describe the problem to
a coding agent and let it draft the pull request; review it before you open it.

### Fixing a bug

Open a pull request with:

- a test that fails without the change;
- the change;
- a description of what went wrong and why the change fixes it, and the output of `php -v`.

### Adding a feature

Open a pull request with tests and a section in the README. Read [Scope](#scope) first.

### Review

A maintainer reviews a pull request once it is ready for review and the `tests` workflow passes; a
bug report without a fix may fail only in the test that it adds. Inactive drafts may be closed.
Pull requests opened in bulk are closed without review.
5 changes: 0 additions & 5 deletions .github/PULL_REQUEST_TEMPLATE.md

This file was deleted.

File renamed without changes.
28 changes: 28 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
version: 2

# Each update waits 14 days after its release, so a broken or taken-over release is found by others
# first. No Composer: the lock serves only the test tools, and the newest job takes their updates.
updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: monthly
cooldown:
default-days: 14
groups:
actions:
patterns: ['*']

# The images the job of the workflows runs in, and the image of the demo.
- package-ecosystem: docker
directories:
- /demo
- /.github/docker/actionlint
- /.github/docker/zizmor
schedule:
interval: monthly
cooldown:
default-days: 14
groups:
images:
patterns: ['*']
3 changes: 3 additions & 0 deletions .github/docker/actionlint/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# actionlint, which checks the syntax and the expressions of the workflows. A Dockerfile, so
# Dependabot updates the digest.
FROM rhysd/actionlint:1.7.12@sha256:b1934ee5f1c509618f2508e6eb47ee0d3520686341fec936f3b79331f9315667
2 changes: 2 additions & 0 deletions .github/docker/zizmor/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# zizmor, which audits the workflows. A Dockerfile, so Dependabot updates the digest.
FROM ghcr.io/zizmorcore/zizmor:1.30.1@sha256:a2eb396d886c053073405c7a980f2139ba2248ec172243cfa3841e57196e8101
12 changes: 12 additions & 0 deletions .github/pull_request_template.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!-- See .github/CONTRIBUTING.md. Report a vulnerability as the security policy describes, not here. -->

**What went wrong and what you expected, or what the feature does:**

**With a fix, why it works:**

**The row of Scope in the README that the change touches:**

- [ ] A test that fails without the change
- [ ] The output of `php -v`, for a bug
- [ ] A section in the README, for a feature
- [ ] `composer test` passes; in a bug report without a fix, only the new test fails
42 changes: 42 additions & 0 deletions .github/workflows/mutation.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: mutation

# A run of all of src/ takes about 18 minutes on one core, so it runs each week, not on each push.
# Composer, pinned by digest in `tools`, is updated by hand; Dependabot updates the actions.
on:
schedule:
- cron: '43 4 * * 1'

permissions:
contents: read

# A second run waits for the first instead of ending it.
concurrency:
group: ${{ github.workflow }}
cancel-in-progress: false

jobs:
mutation:
name: Mutation
runs-on: ubuntu-24.04
timeout-minutes: 60

steps:
- name: Checkout
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
persist-credentials: false

- name: Setup PHP
uses: shivammathur/setup-php@eb7c497e18156a6bbabfef1d3a82760b9eda3962 # 2.40.0
with:
php-version: '8.5'
extensions: dom, intl, mbstring
coverage: pcov
tools: composer:2.10.3@sha256:7a2d379d5b8ffdaa028580ef26494c36d2feef4b178d3dd1473a4dbc5e17c8d6

- name: Install dependencies
run: composer install --no-interaction --prefer-dist

# Serial: with --parallel, Pest Mutate counts each mutant as killed.
- name: Mutation
run: composer test:mutation
Loading
Loading