-
Notifications
You must be signed in to change notification settings - Fork 0
/
php_test.go
129 lines (123 loc) · 3.02 KB
/
php_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package internal
import (
"testing"
"github.com/CircleCI-Public/circleci-config/config"
"github.com/CircleCI-Public/circleci-config/labeling/labels"
"github.com/google/go-cmp/cmp"
)
func TestGeneratePHPJobs(t *testing.T) {
type args struct {
ls labels.LabelSet
}
tests := []struct {
name string
args args
wantJobs []*Job
}{
{
name: "composer file has phpunit",
args: args{ls: labels.LabelSet{
labels.DepsPhp: labels.Label{
Valid: true,
LabelData: labels.LabelData{
Dependencies: map[string]string{"phpunit/phpunit": "~4.2"},
HasLockFile: true,
},
}}},
wantJobs: []*Job{
{
Job: config.Job{
Name: "test-php",
Comment: "Install php packages and run tests",
WorkingDirectory: "",
DockerImages: []string{"cimg/php:8.2.7-node"},
Steps: []config.Step{
{
Path: "~/project",
Type: config.Checkout,
},
{
Command: "php/install-packages",
Type: config.OrbCommand,
},
{
Type: config.Run,
Name: "run tests",
Command: "./vendor/bin/phpunit",
},
}},
Type: TestJob,
Orbs: map[string]string{"php": "circleci/php@1"},
},
},
},
{
name: "composer file has phpunit and php version",
args: args{ls: labels.LabelSet{
labels.DepsPhp: labels.Label{
Valid: true,
LabelData: labels.LabelData{
Dependencies: map[string]string{"phpunit/phpunit": "~4.2", "php": "^8.1"},
HasLockFile: true,
},
}}},
wantJobs: []*Job{
{
Job: config.Job{
Name: "test-php",
Comment: "Install php packages and run tests",
WorkingDirectory: "",
DockerImages: []string{"cimg/php:8.1-node"},
Steps: []config.Step{
{
Path: "~/project",
Type: config.Checkout,
},
{
Command: "php/install-packages",
Type: config.OrbCommand,
},
{
Type: config.Run,
Name: "run tests",
Command: "./vendor/bin/phpunit",
},
}},
Type: TestJob,
Orbs: map[string]string{"php": "circleci/php@1"},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
gotJobs := GeneratePHPJobs(tt.args.ls)
diff := cmp.Diff(tt.wantJobs, gotJobs)
if diff != "" {
t.Errorf("MakeGatewayInfo() mismatch (-want +got):\n%s", diff)
}
})
}
}
func Test_phpImageVersion(t *testing.T) {
type args struct {
composerVersion string
}
tests := []struct {
name string
args args
want string
}{
{"explicit version", args{"8.1.2"}, "cimg/php:8.1-node"},
{"caret version", args{"^8.1.2"}, "cimg/php:8.1-node"},
{"wildcard version", args{"8.1.*"}, "cimg/php:8.1-node"},
{"~ version", args{"~8.1.2"}, "cimg/php:8.1-node"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := phpImageVersion(tt.args.composerVersion); got != tt.want {
t.Errorf("phpImageVersion() = %v, want %v", got, tt.want)
}
})
}
}