Skip to content

Commit c3092f6

Browse files
authored
Implement e2e tests with testscript (#53)
* Implement e2e tests with `testscript` * Dependabot: Add `gomod` * GitHub Actions: Add `govulncheck` workflow
1 parent b5a89b1 commit c3092f6

File tree

372 files changed

+4774
-10139
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

372 files changed

+4774
-10139
lines changed

.github/dependabot.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ updates:
55
directory: /
66
schedule:
77
interval: weekly
8+
- package-ecosystem: gomod
9+
directory: /
10+
schedule:
11+
interval: weekly
812
- package-ecosystem: github-actions
913
directory: /
1014
schedule:

.github/workflows/govulncheck.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: govulncheck
2+
3+
on:
4+
schedule:
5+
- cron: '2 2 * * 1' # Weekly on Monday
6+
workflow_dispatch:
7+
pull_request:
8+
branches:
9+
- main
10+
push:
11+
branches:
12+
- main
13+
14+
concurrency:
15+
group: ${{ github.workflow }}-${{ github.event.pull_request.number || github.ref_name }}-${{ github.event.pull_request.number || github.sha }}
16+
cancel-in-progress: true
17+
18+
permissions: {}
19+
20+
jobs:
21+
govulncheck:
22+
runs-on: ubuntu-latest
23+
steps:
24+
- uses: golang/govulncheck-action@v1
25+
with:
26+
go-version-file: 'go.mod'
27+
go-package: ./...

.github/workflows/test.yml

Lines changed: 30 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,27 +27,13 @@ jobs:
2727
coverage: xdebug
2828
- uses: ramsey/composer-install@v3
2929

30-
- run: composer pest:unit -- --coverage-clover coverage-unit.xml --ci --bail --stop-on-incomplete --fail-on-all-issues
30+
- run: composer pest:unit -- --coverage-clover coverage-unit.xml --ci
3131

3232
- uses: actions/upload-artifact@v4
3333
with:
3434
name: coverage
3535
path: coverage-unit.xml
3636

37-
e2e:
38-
needs: pest
39-
runs-on: ubuntu-latest
40-
steps:
41-
- uses: actions/checkout@v5
42-
43-
- uses: shivammathur/setup-php@v2
44-
with:
45-
php-version: '8.4'
46-
coverage: none
47-
- uses: ramsey/composer-install@v3
48-
49-
- run: composer pest:e2e -- --ci --bail --stop-on-incomplete --fail-on-all-issues
50-
5137
codecov:
5238
needs: pest
5339
runs-on: ubuntu-latest
@@ -67,3 +53,32 @@ jobs:
6753
disable_search: true
6854
files: coverage-unit.xml
6955
flags: unit
56+
57+
bin:
58+
runs-on: ubuntu-latest
59+
env:
60+
GOFLAGS: '-mod=mod'
61+
steps:
62+
- uses: actions/checkout@v5
63+
64+
- uses: shivammathur/setup-php@v2
65+
with:
66+
php-version: '8.4'
67+
coverage: none
68+
- uses: ramsey/composer-install@v3
69+
with:
70+
composer-options: '--no-dev --prefer-dist'
71+
72+
- name: Add bin into PATH
73+
run: echo "${WORKSPACE}/bin" >> "$GITHUB_PATH"
74+
env:
75+
WORKSPACE: ${{ github.workspace }}
76+
77+
- uses: actions/setup-go@v6
78+
with:
79+
go-version-file: 'go.mod'
80+
81+
- name: Print php-matrix binary path
82+
run: go test -count=1 -v ./internal
83+
84+
- run: go test -count=1 ./...

Makefile

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
export GOFLAGS=-mod=mod
2+
3+
.PHONY: FORCE
4+
FORCE:;
5+
6+
.PHONY: vendor
7+
vendor:
8+
composer install --no-dev --prefer-dist
9+
composer reinstall --prefer-dist '*'
10+
11+
bin: vendor
12+
13+
test-%: %
14+
PATH="$(shell pwd)/$*:$(shell echo $$PATH)" \
15+
go test -count=1 ./...
16+
17+
tests/data/releases-%.json: FORCE
18+
curl 'https://www.php.net/releases/index.php?json&max=1000&version=$*' | jq . > ./tests/data/releases-$*.json
19+
20+
resources/all-versions.json: bin tests/data/releases-5.json tests/data/releases-7.json tests/data/releases-8.json
21+
./bin/update-all-versions
22+
23+
--go-generate:
24+
go generate ./...
25+
26+
txtar: resources/all-versions.json --go-generate
27+
$(MAKE) UPDATE_SCRIPTS=1 test-bin

composer.json

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -62,19 +62,11 @@
6262
"sort-packages": true
6363
},
6464
"scripts": {
65-
"data:update": [
66-
"curl 'https://www.php.net/releases/index.php?json&max=1000&version=5' | jq . > ./tests/data/releases-5.json",
67-
"curl 'https://www.php.net/releases/index.php?json&max=1000&version=7' | jq . > ./tests/data/releases-7.json",
68-
"curl 'https://www.php.net/releases/index.php?json&max=1000&version=8' | jq . > ./tests/data/releases-8.json",
69-
"@php ./bin/update-all-versions",
70-
"XDEBUG_MODE=off pest --update-snapshots"
71-
],
7265
"lint": [
7366
"pint --test",
7467
"phpstan analyse"
7568
],
7669
"pest": "pest",
77-
"pest:e2e": "XDEBUG_MODE=off pest --group=e2e",
7870
"pest:unit": "pest --group=unit"
7971
}
8072
}

go.mod

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
module github.com/typisttech/php-matrix
2+
3+
go 1.25.2
4+
5+
require github.com/rogpeppe/go-internal v1.14.1
6+
7+
require (
8+
golang.org/x/sys v0.26.0 // indirect
9+
golang.org/x/tools v0.26.0 // indirect
10+
)

go.sum

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
2+
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
3+
golang.org/x/sys v0.26.0 h1:KHjCJyddX0LoSTb3J+vWpupP9p0oznkqVk/IfjymZbo=
4+
golang.org/x/sys v0.26.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
5+
golang.org/x/tools v0.26.0 h1:v/60pFQmzmT9ExmjDv2gGIfi3OqfKoEP6I5+umXlbnQ=
6+
golang.org/x/tools v0.26.0/go.mod h1:TPVVj70c7JJ3WCazhD8OdXcZg/og+b9+tH/KxylGwH0=

internal/common.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package internal
2+
3+
var Constraints = []string{
4+
"^7",
5+
"^7.1",
6+
"^7.1.2",
7+
"^7.1.2 || ~8.1.2",
8+
"^7 ^7.2",
9+
"*",
10+
"@stable",
11+
"^7@stable",
12+
}
13+
14+
var Modes = []string{
15+
"",
16+
"--mode=minor-only",
17+
"--mode=full",
18+
}

internal/composer/fail/main.go

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package main
2+
3+
import (
4+
"os"
5+
"text/template"
6+
7+
"github.com/typisttech/php-matrix/internal"
8+
)
9+
10+
const fileTemplateRaw = `# DO NOT EDIT THIS FILE
11+
# This file is generated by "internal/composer/fail/main.go"
12+
# Test the "{{ .Name }}" case
13+
14+
! exec php-matrix composer {{ .Mode }}
15+
! stdout .
16+
cmp stderr stderr.golden
17+
18+
! exec php-matrix composer {{ .Mode }} --source=auto
19+
! stdout .
20+
cmp stderr stderr.golden
21+
22+
! exec php-matrix composer {{ .Mode }} --source=php.net
23+
! stdout .
24+
cmp stderr stderr.golden
25+
26+
! exec php-matrix composer {{ .Mode }} --source=offline
27+
! stdout .
28+
cmp stderr stderr.golden
29+
30+
-- stderr.golden --
31+
32+
-- composer.json --
33+
{{ .ComposerJSON }}
34+
`
35+
36+
var rawCases = []rawData{
37+
{`no "require.php" is set/1`, `{"require":{"some/package":"^1.0"}}`},
38+
{`no "require.php" is set/2`, `{"require":{}}`},
39+
{`no "require.php" is set/3`, `{"require":123}`},
40+
{`no "require.php" is set/4`, `{"require-dev":{"php":"^1.0"}}`},
41+
{`no "require.php" is set/5`, `{"php":"^1.0"}`},
42+
{`no "require.php" is set/6`, `{}`},
43+
44+
{`"require.php" is not a string/null`, `{"require":{"php":null}}`},
45+
{`"require.php" is not a string/object`, `{"require":{"php":{}}}`},
46+
{`"require.php" is not a string/array`, `{"require":{"php":[]}}`},
47+
{`"require.php" is not a string/integer`, `{"require":{"php":123}}`},
48+
{`"require.php" is not a string/float`, `{"require":{"php":12.3}}`},
49+
{`"require.php" is not a string/true`, `{"require":{"php":true}}`},
50+
{`"require.php" is not a string/false`, `{"require":{"php":false}}`},
51+
52+
{`"require.php" is not a valid constraint/ruby`, `{"require":{"php":"~>1.0"}}`},
53+
{`"require.php" is not a valid constraint/empty string`, `{"require":{"php":""}}`},
54+
{`"require.php" is not a valid constraint/invalid string`, `{"require":{"php":"invalid constraint"}}`},
55+
56+
{`unsatisfiable/1`, `{"require":{"php":">8.0 <7.0"}}`},
57+
{`unsatisfiable/2`, `{"require":{"php":">999"}}`},
58+
{`unsatisfiable/3`, `{"require":{"php":"dev-master"}}`},
59+
60+
{`invalid json`, `{invalid json`},
61+
}
62+
63+
var fileTemplate = template.Must(template.New("").Parse(fileTemplateRaw))
64+
65+
type rawData struct {
66+
name string
67+
ComposerJSON string
68+
}
69+
70+
type data struct {
71+
Mode string
72+
rawData
73+
}
74+
75+
func (d data) Name() string {
76+
return d.name
77+
}
78+
79+
func (d data) Write(f *os.File) error {
80+
return fileTemplate.Execute(f, d)
81+
}
82+
83+
func main() {
84+
var cases []data
85+
for _, mode := range internal.Modes {
86+
for _, r := range rawCases {
87+
cases = append(cases, data{
88+
Mode: mode,
89+
rawData: r,
90+
})
91+
}
92+
93+
err := internal.Generate("composer/fail", cases...)
94+
if err != nil {
95+
panic(err)
96+
}
97+
}
98+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package main_test
2+
3+
import (
4+
"testing"
5+
6+
"github.com/typisttech/php-matrix/internal"
7+
)
8+
9+
//go:generate go run ./main.go
10+
func Test(t *testing.T) {
11+
internal.RunTestscript(t)
12+
}

0 commit comments

Comments
 (0)