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
2 changes: 1 addition & 1 deletion .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
scripts/ export-ignore
src/Standards/**/Tests/ export-ignore
tests/Core/**/ export-ignore
tests/EndToEnd/**/ export-ignore
tests/EndToEndBash/**/ export-ignore
.cspell.json export-ignore
.gitattributes export-ignore
.gitignore export-ignore
Expand Down
4 changes: 2 additions & 2 deletions .github/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -405,13 +405,13 @@ To install bashunit, follow the [installation guide](https://bashunit.typeddevs.

You can then run the bashunit tests on Linux/Mac/WSL, like so:
```bash
./lib/bashunit -p tests/EndToEnd
./lib/bashunit -p tests/EndToEndBash
```

> Note: these tests will not run in the Windows native CMD shell. When on Windows, either use WSL or use the "git bash" shell.

When writing end-to-end tests, please use fixtures for the "files under scan" to make the tests stable.
These fixtures can be placed in the `tests/EndToEnd/Fixtures` subdirectory.
These fixtures can be placed in the `tests/EndToEndBash/Fixtures` subdirectory.


### Submitting Your Pull Request
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/end-to-end-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ jobs:

- name: "Run bashunit tests"
shell: bash
run: "./lib/bashunit -p tests/EndToEnd"
run: "./lib/bashunit -p tests/EndToEndBash"
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ vendor/
/tests/Standards/sniffStnd.xml
/tests/Core/Util/ExitCode/Fixtures/ExitCodeTest/*.fixed
/tests/Core/Util/ExitCode/Fixtures/ExitCodeTest/phpcs.cache
/tests/EndToEnd/Fixtures/*.fixed
/tests/EndToEndBash/Fixtures/*.fixed
2 changes: 1 addition & 1 deletion .shellcheckrc
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ shell=bash
color=always

external-sources=false
source-path=/tests/EndToEnd
source-path=/tests/EndToEndBash
2 changes: 1 addition & 1 deletion phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
<exclude-pattern>*/src/Standards/*/Tests/*\.inc$</exclude-pattern>
<exclude-pattern>*/tests/Core/*/*\.inc$</exclude-pattern>
<exclude-pattern>*/tests/Core/*/Fixtures/*\.php$</exclude-pattern>
<exclude-pattern>*/tests/EndToEnd/Fixtures/*\.inc$</exclude-pattern>
<exclude-pattern>*/tests/EndToEndBash/Fixtures/*\.inc$</exclude-pattern>

<arg name="basepath" value="."/>
<arg name="colors"/>
Expand Down
73 changes: 0 additions & 73 deletions tests/EndToEnd/exit_code_test.sh

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/HEAD/licence.txt BSD Licence
*/

namespace PHP_CodeSniffer\Tests\EndToEnd\Fixtures;
namespace PHP_CodeSniffer\Tests\EndToEndBash\Fixtures;

class ClassOneWithoutStyleError
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/HEAD/licence.txt BSD Licence
*/

namespace PHP_CodeSniffer\Tests\EndToEnd\Fixtures;
namespace PHP_CodeSniffer\Tests\EndToEndBash\Fixtures;

class ClassTwoWithoutStyleError
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/HEAD/licence.txt BSD Licence
*/

namespace PHP_CodeSniffer\Tests\EndToEnd\Fixtures;
namespace PHP_CodeSniffer\Tests\EndToEndBash\Fixtures;

class ClassWithStyleError
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/HEAD/licence.txt BSD Licence
*/

namespace PHP_CodeSniffer\Tests\EndToEnd\Fixtures;
namespace PHP_CodeSniffer\Tests\EndToEndBash\Fixtures;

// The brace on the following line should be on a line by itself. This can be fixed with phpcbf.
class ClassWithTwoStyleErrors {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
* @license https://github.com/PHPCSStandards/PHP_CodeSniffer/blob/HEAD/licence.txt BSD Licence
*/

namespace PHP_CodeSniffer\Tests\EndToEnd\Fixtures;
namespace PHP_CodeSniffer\Tests\EndToEndBash\Fixtures;

class ClassWithUnfixableStyleError
{
Expand Down
73 changes: 73 additions & 0 deletions tests/EndToEndBash/exit_code_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/usr/bin/env bash

function tear_down() {
rm -f tests/EndToEndBash/Fixtures/*.fixed
}

function test_phpcs_exit_code_clean_file() {
bin/phpcs --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassOneWithoutStyleError.inc
assert_exit_code 0
}
function test_phpcs_exit_code_clean_stdin() {
bin/phpcs --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist < tests/EndToEndBash/Fixtures/ClassOneWithoutStyleError.inc
assert_exit_code 0
}
function test_phpcbf_exit_code_clean_file() {
bin/phpcbf --suffix=.fixed --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassOneWithoutStyleError.inc
assert_exit_code 0
}
function test_phpcbf_exit_code_clean_stdin() {
bin/phpcbf --suffix=.fixed --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist < tests/EndToEndBash/Fixtures/ClassOneWithoutStyleError.inc
assert_exit_code 0
}

function test_phpcs_exit_code_fixable_file() {
bin/phpcs --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassWithStyleError.inc
assert_exit_code 1
}
function test_phpcs_exit_code_fixable_stdin() {
bin/phpcs --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist < tests/EndToEndBash/Fixtures/ClassWithStyleError.inc
assert_exit_code 1
}
function test_phpcbf_exit_code_fixable_file() {
bin/phpcbf --suffix=.fixed --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassWithStyleError.inc
assert_exit_code 0
}
function test_phpcbf_exit_code_fixable_stdin() {
bin/phpcbf --suffix=.fixed --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist < tests/EndToEndBash/Fixtures/ClassWithStyleError.inc
assert_exit_code 0
}

function test_phpcs_exit_code_non_fixable_file() {
bin/phpcs --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassWithUnfixableStyleError.inc
assert_exit_code 2
}
function test_phpcs_exit_code_non_fixable_stdin() {
bin/phpcs --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist < tests/EndToEndBash/Fixtures/ClassWithUnfixableStyleError.inc
assert_exit_code 2
}
function test_phpcbf_exit_code_non_fixable_file() {
bin/phpcbf --suffix=.fixed --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassWithUnfixableStyleError.inc
assert_exit_code 2
}
function test_phpcbf_exit_code_non_fixable_stdin() {
bin/phpcbf --suffix=.fixed --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist < tests/EndToEndBash/Fixtures/ClassWithUnfixableStyleError.inc
assert_exit_code 2
}

function test_phpcs_exit_code_fixable_and_non_fixable_file() {
bin/phpcs --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassWithTwoStyleErrors.inc
assert_exit_code 3
}
function test_phpcs_exit_code_fixable_and_non_fixable_stdin() {
bin/phpcs --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist < tests/EndToEndBash/Fixtures/ClassWithTwoStyleErrors.inc
assert_exit_code 3
}
function test_phpcbf_exit_code_fixable_and_non_fixable_file() {
bin/phpcbf --suffix=.fixed --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassWithTwoStyleErrors.inc
assert_exit_code 2
}
function test_phpcbf_exit_code_fixable_and_non_fixable_stdin() {
bin/phpcbf --suffix=.fixed --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist < tests/EndToEndBash/Fixtures/ClassWithTwoStyleErrors.inc
assert_exit_code 2
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
#!/usr/bin/env bash

function tear_down() {
rm -f tests/EndToEnd/Fixtures/*.fixed
rm -f tests/EndToEndBash/Fixtures/*.fixed
}

function test_phpcs_out_of_memory_error_handling() {
OUTPUT="$( { bin/phpcs -d memory_limit=4M --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/; } 2>&1)"
OUTPUT="$( { bin/phpcs -d memory_limit=4M --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/; } 2>&1)"
# The exact exit code is not our concern, just that it's non-zero.
assert_unsuccessful_code

Expand All @@ -15,7 +15,7 @@ function test_phpcs_out_of_memory_error_handling() {
}

function test_phpcbf_out_of_memory_error_handling() {
OUTPUT="$( { bin/phpcbf -d memory_limit=4M --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ --suffix=.fixed; } 2>&1)"
OUTPUT="$( { bin/phpcbf -d memory_limit=4M --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ --suffix=.fixed; } 2>&1)"
# The exact exit code is not our concern, just that it's non-zero.
assert_unsuccessful_code

Expand Down
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
#!/usr/bin/env bash

function tear_down() {
rm -rf tests/EndToEnd/Fixtures/*.fixed
rm -f tests/EndToEndBash/Fixtures/*.fixed
}

function test_phpcbf_is_working() {
OUTPUT="$( { bin/phpcbf --no-cache --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEnd/Fixtures/ClassTwoWithoutStyleError.inc; } 2>&1 )"
OUTPUT="$( { bin/phpcbf --no-cache --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEndBash/Fixtures/ClassTwoWithoutStyleError.inc; } 2>&1 )"

assert_successful_code
assert_contains "No violations were found" "$OUTPUT"
}

function test_phpcbf_is_working_in_parallel() {
OUTPUT="$( { bin/phpcbf --no-cache --parallel=2 --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEnd/Fixtures/ClassTwoWithoutStyleError.inc; } 2>&1 )"
OUTPUT="$( { bin/phpcbf --no-cache --parallel=2 --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEndBash/Fixtures/ClassTwoWithoutStyleError.inc; } 2>&1 )"

assert_successful_code
assert_contains "No violations were found" "$OUTPUT"
}

function test_phpcbf_returns_error_on_issues() {
OUTPUT="$( { bin/phpcbf --no-colors --parallel=1 --no-cache --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassWithStyleError.inc; } 2>&1 )"
OUTPUT="$( { bin/phpcbf --no-colors --parallel=1 --no-cache --suffix=.fixed --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassWithStyleError.inc; } 2>&1 )"
assert_successful_code

assert_contains "F 1 / 1 (100%)" "$OUTPUT"
assert_contains "A TOTAL OF 1 ERROR WERE FIXED IN 1 FILE" "$OUTPUT"
}

function test_phpcbf_progressbar_shows_fixes_with_parallel_on() {
OUTPUT="$( { bin/phpcbf --no-colors --parallel=10 --no-cache --suffix=.fixed --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassWithStyleError.inc; } 2>&1 )"
OUTPUT="$( { bin/phpcbf --no-colors --parallel=10 --no-cache --suffix=.fixed --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassWithStyleError.inc; } 2>&1 )"
assert_successful_code

assert_contains "F 1 / 1 (100%)" "$OUTPUT"
Expand All @@ -37,9 +37,9 @@ function test_phpcbf_bug_1112() {
# See https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/1112
if [[ "$(uname)" == "Darwin" ]]; then
# Perform some magic with `& fg` to prevent the processes from turning into a background job.
assert_successful_code "$(bash -ic 'bash --init-file <(echo "echo \"Subprocess\"") -c "bin/phpcbf --no-cache --parallel=2 --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEnd/Fixtures/ClassTwoWithoutStyleError.inc" & fg')"
assert_successful_code "$(bash -ic 'bash --init-file <(echo "echo \"Subprocess\"") -c "bin/phpcbf --no-cache --parallel=2 --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEndBash/Fixtures/ClassTwoWithoutStyleError.inc" & fg')"
else
# This is not needed on Linux / GitHub Actions
assert_successful_code "$(bash -ic 'bash --init-file <(echo "echo \"Subprocess\"") -c "bin/phpcbf --no-cache --parallel=2 --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEnd/Fixtures/ClassTwoWithoutStyleError.inc"')"
assert_successful_code "$(bash -ic 'bash --init-file <(echo "echo \"Subprocess\"") -c "bin/phpcbf --no-cache --parallel=2 --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEndBash/Fixtures/ClassTwoWithoutStyleError.inc"')"
fi
}
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env bash

function test_phpcs_is_working() {
assert_successful_code "$(bin/phpcs --no-cache --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEnd/Fixtures/ClassTwoWithoutStyleError.inc)"
assert_successful_code "$(bin/phpcs --no-cache --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEndBash/Fixtures/ClassTwoWithoutStyleError.inc)"
}

function test_phpcs_is_working_in_parallel() {
assert_successful_code "$(bin/phpcs --no-cache --parallel=2 --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEnd/Fixtures/ClassTwoWithoutStyleError.inc)"
assert_successful_code "$(bin/phpcs --no-cache --parallel=2 --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEndBash/Fixtures/ClassTwoWithoutStyleError.inc)"
}

function test_phpcs_returns_error_on_issues() {
OUTPUT="$( { bin/phpcs --no-colors --no-cache --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassWithStyleError.inc; } 2>&1 )"
OUTPUT="$( { bin/phpcs --no-colors --no-cache --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassWithStyleError.inc; } 2>&1 )"
assert_exit_code 1

assert_contains "E 1 / 1 (100%)" "$OUTPUT"
Expand All @@ -20,9 +20,9 @@ function test_phpcs_bug_1112() {
# See https://github.com/PHPCSStandards/PHP_CodeSniffer/issues/1112
if [[ "$(uname)" == "Darwin" ]]; then
# Perform some magic with `& fg` to prevent the processes from turning into a background job.
assert_successful_code "$(bash -ic 'bash --init-file <(echo "echo \"Subprocess\"") -c "bin/phpcs --no-cache --parallel=2 --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEnd/Fixtures/ClassTwoWithoutStyleError.inc" & fg')"
assert_successful_code "$(bash -ic 'bash --init-file <(echo "echo \"Subprocess\"") -c "bin/phpcs --no-cache --parallel=2 --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEndBash/Fixtures/ClassTwoWithoutStyleError.inc" & fg')"
else
# This is not needed on Linux / GitHub Actions
assert_successful_code "$(bash -ic 'bash --init-file <(echo "echo \"Subprocess\"") -c "bin/phpcs --no-cache --parallel=2 --standard=tests/EndToEnd/Fixtures/endtoend.xml.dist tests/EndToEnd/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEnd/Fixtures/ClassTwoWithoutStyleError.inc"')"
assert_successful_code "$(bash -ic 'bash --init-file <(echo "echo \"Subprocess\"") -c "bin/phpcs --no-cache --parallel=2 --standard=tests/EndToEndBash/Fixtures/endtoend.xml.dist tests/EndToEndBash/Fixtures/ClassOneWithoutStyleError.inc tests/EndToEndBash/Fixtures/ClassTwoWithoutStyleError.inc"')"
fi
}
Loading