8000 Add first integration tests · symfony-cli/symfony-cli@43d4ba3 · GitHub
[go: up one dir, main page]

Skip to content

Commit 43d4ba3

Browse files
Add first integration tests
1 parent c02c834 commit 43d4ba3

File tree

8 files changed

+353
-0
lines changed

8 files changed

+353
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
name: Integration tests
2+
3+
on:
4+
pull_request:
5+
push:
6+
7+
jobs:
8+
tests:
9+
name: Integration test
10+
runs-on: ubuntu-latest
11+
steps:
12+
- name: Checkout
13+
uses: actions/checkout@v3
14+
with:
15+
fetch-depth: 0
16+
17+
- name: Set up Go
18+
uses: actions/setup-go@v3
19+
with:
20+
go-version: '^1.21.1'
21+
22+
- name: Setup PHP
23+
uses: shivammathur/setup-php@v2
24+
with:
25+
php-version: 8.3
26+
27+
- uses: actions/cache@v3
28+
with:
29+
path: |
30+
~/.cache/go-build
31+
~/go/pkg/mod
32+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
33+
restore-keys: |
34+
${{ runner.os }}-go-
35+
36+
- name: Build SUT
37+
run: |
38+
go build .
39+
40+
- name: Run tests
41+
run: go test -v --tags=integration ./integration/...

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
/dist
22
/vendor
3+
symfony-cli

integration/hello_world/index.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2024-present Fabien Potencier <fabien@symfony.com>
3+
*
4+
* This file is part of Symfony CLI project
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
<?php
21+
22+
echo 'Hello world!';

integration/integration_cleanup.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//go:build integration
2+
// +build integration
3+
4+
/*
5+
* Copyright (c) 2024-present Fabien Potencier <fabien@symfony.com>
6+
*
7+
* This file is part of Symfony CLI project
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
package integration
24+
25+
import (
26+
"os/exec"
27+
"testing"
28+
)
29+
30+
func Cleanup(t *testing.T) {
31+
cmd := exec.Command("../symfony-cli", "server:stop", "--all")
32+
err := cmd.Run()
33+
34+
if err != nil {
35+
t.Errorf("Error cleaning up integration test %s: %s", t.Name(), err)
36+
}
37+
}

integration/local_server_list_test.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
//go:build integration
2+
// +build integration
3+
4+
/*
5+
* Copyright (c) 2024-present Fabien Potencier <fabien@symfony.com>
6+
*
7+
* This file is part of Symfony CLI project
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
package integration
24+
25+
import (
26+
"os/exec"
27+
"regexp"
28+
"strings"
29+
"testing"
30+
)
31+
32+
func TestServerList(t *testing.T) {
33+
startCommands := []string{
34+
"../symfony-cli server:start -d --dir=phpinfo/",
35+
"../symfony-cli server:start -d --dir=hello_world/",
36+
}
37+
38+
for _, command := range startCommands {
39+
cmd := exec.Command(strings.Split(command, " ")[0], strings.Split(command, " ")[1:]...)
40+
err := cmd.Run()
41+
if err != nil {
42+
t.Errorf("Error running command: %s", err)
43+
}
44+
}
45+
46+
cmd := exec.Command("../symfony-cli", "server:list", "--no-ansi")
47+
output, err := cmd.Output()
48+
if err != nil {
49+
t.Errorf("Error listing servers: %s", err)
50+
}
51+
52+
expectedMatches := []string{
53+
"(.+)symfony-cli/integration/phpinfo/ | 8000",
54+
"(.+)symfony-cli/integration/hello_world/ | 8001",
55+
}
56+
57+
for _, match := range expectedMatches {
58+
matched, _ := regexp.Match(match, output)
59+
if !matched {
60+
t.Errorf("Expected server to be running while matching: %s", match)
61+
}
62+
}
63+
64+
Cleanup(t)
65+
}
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
//go:build integration
2+
// +build integration
3+
4+
/*
5+
* Copyright (c) 2024-present Fabien Potencier <fabien@symfony.com>
6+
*
7+
* This file is part of Symfony CLI project
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
package integration
24+
25+
import (
26+
"net/http"
27+
"os/exec"
28+
"testing"
29+
)
30+
31+
func TestServerStartDaemon(t *testing.T) {
32+
cmd := exec.Command("../symfony-cli", "server:start", "-d", "--dir=phpinfo/")
33+
err := cmd.Run()
34+
if err != nil {
35+
t.Errorf("Error running command: %s", err)
36+
}
37+
38+
r, err := http.Head("http://localhost:8000")
39+
if err != nil {
40+
t.Errorf("Error sending request: %s", err)
41+
}
42+
43+
if r.StatusCode != 200 {
44+
t.Errorf("Expected status code 200, got %d", r.StatusCode)
45+
}
46+
47+
Cleanup(t)
48+
}

integration/local_server_stop_test.go

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
//go:build integration
2+
// +build integration
3+
4+
/*
5+
* Copyright (c) 2024-present Fabien Potencier <fabien@symfony.com>
6+
*
7+
* This file is part of Symfony CLI project
8+
*
9+
* This program is free software: you can redistribute it and/or modify
10+
* it under the terms of the GNU Affero General Public License as
11+
* published by the Free Software Foundation, either version 3 of the
12+
* License, or (at your option) any later version.
13+
*
14+
* This program is distributed in the hope that it will be useful,
15+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
16+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17+
* GNU Affero General Public License for more details.
18+
*
19+
* You should have received a copy of the GNU Affero General Public License
20+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21+
*/
22+
23+
package integration
24+
25+
import (
26+
"os/exec"
27+
"regexp"
28+
"strings"
29+
"testing"
30+
)
31+
32+
func TestServerStop_WithDir(t *testing.T) {
33+
cmd := exec.Command("../symfony-cli", "server:start", "-d", "--dir=phpinfo/")
34+
err := cmd.Run()
35+
if err != nil {
36+
t.Errorf("Error starting server: %s", err)
37+
}
38+
39+
// explicitly stop the server "contained" in the "phpinfo" directory
40+
cmd = exec.Command("../symfony-cli", "server:stop", "--dir=phpinfo/")
41+
err = cmd.Run()
42+
if err != nil {
43+
t.Errorf("Error stopping server: %s", err)
44+
}
45+
46+
cmd = exec.Command("../symfony-cli", "server:list", "--no-ansi")
47+
output, _ := cmd.Output()
48+
49+
if strings.Contains(string(output), "integration/phpinfo") {
50+
t.Errorf("Expected no servers to be running, got %s", output)
51+
52+
Cleanup(t)
53+
}
54+
}
55+
56+
func TestServerStop_WithAll(t *testing.T) {
57+
startCommands := []string{
58+
"../symfony-cli server:start -d --dir=phpinfo/",
59+
"../symfony-cli server:start -d --dir=hello_world/",
60+
}
61+
62+
for _, command := range startCommands {
63+
cmd := exec.Command(strings.Split(command, " ")[0], strings.Split(command, " ")[1:]...)
64+
err := cmd.Run()
65+
if err != nil {
66+
t.Errorf("Error running command: %s", err)
67+
}
68+
}
69+
70+
// only give the --all flag, which should stop all servers
71+
cmd := exec.Command("../symfony-cli", "server:stop", "--all")
72+
err := cmd.Run()
73+
if err != nil {
74+
t.Errorf("Error stopping server: %s", err)
75+
}
76+
77+
cmd = exec.Command("../symfony-cli", "server:list", "--no-ansi")
78+
output, _ := cmd.Output()
79+
80+
expectedToNotMatch := []string{
81+
"(.+)symfony-cli/integration/phpinfo/",
82+
"(.+)symfony-cli/integration/hello_world/",
83+
}
84+
85+
for _, match := range expectedToNotMatch {
86+
matched, _ := regexp.Match(match, output)
87+
if matched {
88+
t.Errorf("Expected server NOT to be running while matching: %s", match)
89+
}
90+
}
91+
}
92+
93+
func TestServerStop_CurrentDir(t *testing.T) {
94+
cmd := exec.Command("../symfony-cli", "server:start", "-d", "--dir=phpinfo/")
95+
96+
err := cmd.Run()
97+
if err != nil {
98+
t.Errorf("Error starting server: %s", err)
99+
}
100+
101+
cmd = exec.Command("../../symfony-cli", "server:stop")
102+
// change the working directory to the "phpinfo" directory so the server can be stopped
103+
// without needing to specify the --dir flag
104+
cmd.Dir = "phpinfo/"
105+
106+
err = cmd.Run()
107+
if err != nil {
108+
t.Errorf("Error stopping server: %s", err)
109+
}
110+
111+
cmd = exec.Command("../symfony-cli", "server:list", "--no-ansi")
112+
output, _ := cmd.Output()
113+
114+
if strings.Contains(string(output), "symfony-cli/integration/phpinfo") {
115+
t.Errorf("Expected no servers to be running, got %s", output)
116+
}
117+
}

integration/phpinfo/index.php

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
* Copyright (c) 2024-present Fabien Potencier <fabien@symfony.com>
3+
*
4+
* This file is part of Symfony CLI project
5+
*
6+
* This program is free software: you can redistribute it and/or modify
7+
* it under the terms of the GNU Affero General Public License as
8+
* published by the Free Software Foundation, either version 3 of the
9+
* License, or (at your option) any later version.
10+
*
11+
* This program is distributed in the hope that it will be useful,
12+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+
* GNU Affero General Public License for more details.
15+
*
16+
* You should have received a copy of the GNU Affero General Public License
17+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
18+
*/
19+
20+
<?php
21+
22+
echo phpinfo();

0 commit comments

Comments
 (0)
0