-
-
Notifications
You must be signed in to change notification settings - Fork 118
Add first integration tests #435
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
alexandre-daubois
wants to merge
1
commit into
symfony-cli:main
Choose a base branch
from
alexandre-daubois:ft-first-try
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
name: Integration tests | ||
|
||
on: | ||
pull_request: | ||
push: | ||
|
||
jobs: | ||
tests: | ||
name: Integration test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v3 | ||
with: | ||
go-version: '^1.21.1' | ||
|
||
- name: Setup PHP | ||
uses: shivammathur/setup-php@v2 | ||
with: | ||
php-version: 8.3 | ||
|
||
- uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.cache/go-build | ||
~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
|
||
- name: Build SUT | ||
run: | | ||
go build . | ||
|
||
- name: Run tests | ||
run: go test -v --tags=integration ./integration/... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2024-present Fabien Potencier <fabien@symfony.com> | ||
* | ||
* This file is part of Symfony CLI project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
<?php | ||
|
||
echo 'Hello world!'; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//go:build integration | ||
// +build integration | ||
|
||
/* | ||
* Copyright (c) 2024-present Fabien Potencier <fabien@symfony.com> | ||
* | ||
* This file is part of Symfony CLI project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package integration | ||
|
||
import ( | ||
"os/exec" | ||
"testing" | ||
) | ||
|
||
func Cleanup(t *testing.T) { | ||
cmd := exec.Command("../symfony-cli", "server:stop", "--all") | ||
err := cmd.Run() | ||
|
||
if err != nil { | ||
t.Errorf("Error cleaning up integration test %s: %s", t.Name(), err) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
//go:build integration | ||
// +build integration | ||
|
||
/* | ||
* Copyright (c) 2024-present Fabien Potencier <fabien@symfony.com> | ||
* | ||
* This file is part of Symfony CLI project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package integration | ||
|
||
import ( | ||
"os/exec" | ||
"regexp" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestServerList(t *testing.T) { | ||
startCommands := []string{ | ||
"../symfony-cli server:start -d --dir=phpinfo/", | ||
"../symfony-cli server:start -d --dir=hello_world/", | ||
} | ||
|
||
for _, command := range startCommands { | ||
cmd := exec.Command(strings.Split(command, " ")[0], strings.Split(command, " ")[1:]...) | ||
err := cmd.Run() | ||
if err != nil { | ||
t.Errorf("Error running command: %s", err) | ||
} | ||
} | ||
|
||
cmd := exec.Command("../symfony-cli", "server:list", "--no-ansi") | ||
output, err := cmd.Output() | ||
if err != nil { | ||
t.Errorf("Error listing servers: %s", err) | ||
} | ||
|
||
expectedMatches := []string{ | ||
"(.+)symfony-cli/integration/phpinfo/ | 8000", | ||
"(.+)symfony-cli/integration/hello_world/ | 8001", | ||
} | ||
|
||
for _, match := range expectedMatches { | ||
matched, _ := regexp.Match(match, output) | ||
if !matched { | ||
t.Errorf("Expected server to be running while matching: %s", match) | ||
} | ||
} | ||
|
||
Cleanup(t) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
//go:build integration | ||
// +build integration | ||
|
||
/* | ||
* Copyright (c) 2024-present Fabien Potencier <fabien@symfony.com> | ||
* | ||
* This file is part of Symfony CLI project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package integration | ||
|
||
import ( | ||
"net/http" | ||
"os/exec" | ||
"testing" | ||
) | ||
|
||
func TestServerStartDaemon(t *testing.T) { | ||
cmd := exec.Command("../symfony-cli", "server:start", "-d", "--dir=phpinfo/") | ||
err := cmd.Run() | ||
if err != nil { | ||
t.Errorf("Error running command: %s", err) | ||
} | ||
|
||
r, err := http.Head("http://localhost:8000") | ||
if err != nil { | ||
t.Errorf("Error sending request: %s", err) | ||
} | ||
|
||
if r.StatusCode != 200 { | ||
t.Errorf("Expected status code 200, got %d", r.StatusCode) | ||
} | ||
|
||
Cleanup(t) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
//go:build integration | ||
// +build integration | ||
|
||
/* | ||
* Copyright (c) 2024-present Fabien Potencier <fabien@symfony.com> | ||
* | ||
* This file is part of Symfony CLI project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
package integration | ||
|
||
import ( | ||
"os/exec" | ||
"regexp" | ||
"strings" | ||
"testing" | ||
) | ||
|
||
func TestServerStop_WithDir(t *testing.T) { | ||
cmd := exec.Command("../symfony-cli", "server:start", "-d", "--dir=phpinfo/") | ||
err := cmd.Run() | ||
if err != nil { | ||
t.Errorf("Error starting server: %s", err) | ||
} | ||
|
||
// explicitly stop the server "contained" in the "phpinfo" directory | ||
cmd = exec.Command("../symfony-cli", "server:stop", "--dir=phpinfo/") | ||
err = cmd.Run() | ||
if err != nil { | ||
t.Errorf("Error stopping server: %s", err) | ||
} | ||
|
||
cmd = exec.Command("../symfony-cli", "server:list", "--no-ansi") | ||
output, _ := cmd.Output() | ||
|
||
if strings.Contains(string(output), "integration/phpinfo") { | ||
t.Errorf("Expected no servers to be running, got %s", output) | ||
|
||
Cleanup(t) | ||
} | ||
} | ||
|
||
func TestServerStop_WithAll(t *testing.T) { | ||
startCommands := []string{ | ||
"../symfony-cli server:start -d --dir=phpinfo/", | ||
"../symfony-cli server:start -d --dir=hello_world/", | ||
} | ||
|
||
for _, command := range startCommands { | ||
cmd := exec.Command(strings.Split(command, " ")[0], strings.Split(command, " ")[1:]...) | ||
err := cmd.Run() | ||
if err != nil { | ||
t.Errorf("Error running command: %s", err) | ||
} | ||
} | ||
|
||
// only give the --all flag, which should stop all servers | ||
cmd := exec.Command("../symfony-cli", "server:stop", "--all") | ||
err := cmd.Run() | ||
if err != nil { | ||
t.Errorf("Error stopping server: %s", err) | ||
} | ||
|
||
cmd = exec.Command("../symfony-cli", "server:list", "--no-ansi") | ||
output, _ := cmd.Output() | ||
|
||
expectedToNotMatch := []string{ | ||
"(.+)symfony-cli/integration/phpinfo/", | ||
"(.+)symfony-cli/integration/hello_world/", | ||
} | ||
|
||
for _, match := range expectedToNotMatch { | ||
matched, _ := regexp.Match(match, output) | ||
if matched { | ||
t.Errorf("Expected server NOT to be running while matching: %s", match) | ||
} | ||
} | ||
} | ||
|
||
func TestServerStop_CurrentDir(t *testing.T) { | ||
cmd := exec.Command("../symfony-cli", "server:start", "-d", "--dir=phpinfo/") | ||
|
||
err := cmd.Run() | ||
if err != nil { | ||
t.Errorf("Error starting server: %s", err) | ||
} | ||
|
||
cmd = exec.Command("../../symfony-cli", "server:stop") | ||
// change the working directory to the "phpinfo" directory so the server can be stopped | ||
// without needing to specify the --dir flag | ||
cmd.Dir = "phpinfo/" | ||
|
||
err = cmd.Run() | ||
if err != nil { | ||
t.Errorf("Error stopping server: %s", err) | ||
} | ||
|
||
cmd = exec.Command("../symfony-cli", "server:list", "--no-ansi") | ||
output, _ := cmd.Output() | ||
|
||
if strings.Contains(string(output), "symfony-cli/integration/phpinfo") { | ||
t.Errorf("Expected no servers to be running, got %s", output) | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
/* | ||
* Copyright (c) 2024-present Fabien Potencier <fabien@symfony.com> | ||
* | ||
* This file is part of Symfony CLI project | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
<?php | ||
|
||
echo phpinfo(); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
to get more control I would rather directly use the code here (starting the server in a goroutine and issuing http request, worst case: starting the application instead of directly the HTTP server).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you do this in all functional tests or only this one? About issuing HTTP request, it is only relevant for starting and stopping the server (and not listing running ones), right?