Skip to content

Commit

Permalink
Merge branch 'main' into feat/captainhook
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey authored Mar 1, 2025
2 parents 2ae10ea + 4cdef30 commit f9e3f83
Show file tree
Hide file tree
Showing 27 changed files with 853 additions and 976 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ indent_size = 2
[*.txt]
insert_final_newline = false
trim_trailing_whitespace = false

[*.{bash,bats,exp}]
indent_style = tab
44 changes: 26 additions & 18 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,16 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: "Checkout repository"
uses: "actions/checkout@v3.3.0"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@2.23.0"
uses: "shivammathur/setup-php@v2"
with:
php-version: "latest"
coverage: "none"

- name: "Install dependencies (Composer)"
uses: "ramsey/composer-install@2.2.0"
uses: "ramsey/composer-install@v3"

- name: "Check syntax (php-parallel-lint)"
shell: "bash"
Expand All @@ -51,16 +51,16 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: "Checkout repository"
uses: "actions/checkout@v3.3.0"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@2.23.0"
uses: "shivammathur/setup-php@v2"
with:
php-version: "latest"
coverage: "none"

- name: "Install dependencies (Composer)"
uses: "ramsey/composer-install@2.2.0"
uses: "ramsey/composer-install@v3"

- name: "Statically analyze code (PHPStan)"
shell: "bash"
Expand All @@ -72,24 +72,24 @@ jobs:
runs-on: "ubuntu-latest"
steps:
- name: "Checkout repository"
uses: "actions/checkout@v3.3.0"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@2.23.0"
uses: "shivammathur/setup-php@v2"
with:
php-version: "latest"
coverage: "pcov"
ini-values: "memory_limit=-1"

- name: "Install dependencies (Composer)"
uses: "ramsey/composer-install@2.2.0"
uses: "ramsey/composer-install@v3"

- name: "Run unit tests (PHPUnit)"
shell: "bash"
run: "composer dev:test:coverage:ci"

- name: "Publish coverage report to Codecov"
uses: "codecov/codecov-action@v3.1.1"
uses: "codecov/codecov-action@v5"

unit-tests:
name: "Unit tests"
Expand All @@ -103,6 +103,7 @@ jobs:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
operating-system:
- "macos-latest"
- "ubuntu-latest"
Expand All @@ -123,16 +124,16 @@ jobs:
git config --system core.eol lf
- name: "Checkout repository"
uses: "actions/checkout@v3.3.0"
uses: "actions/checkout@v4"

- name: "Install PHP"
uses: "shivammathur/setup-php@2.23.0"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: "none"

- name: "Install dependencies (Composer)"
uses: "ramsey/composer-install@2.2.0"
uses: "ramsey/composer-install@v3"
with:
dependency-versions: "${{ matrix.dependencies }}"

Expand All @@ -152,26 +153,33 @@ jobs:
- "8.1"
- "8.2"
- "8.3"
- "8.4"

steps:
- name: "Checkout repository"
uses: "actions/[email protected]"
uses: "actions/checkout@v4"
with:
submodules: recursive

- name: "Install bats-core"
run: |
git clone https://github.com/bats-core/bats-core.git
sudo ./bats-core/install.sh /usr/local
- name: "Install expect"
shell: "bash"
run: |
sudo apt-get update
sudo apt-get -y install expect
- name: "Install PHP"
uses: "shivammathur/setup-php@2.23.0"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
coverage: "none"

- name: "Install dependencies (Composer)"
uses: "ramsey/composer-install@2.2.0"
uses: "ramsey/composer-install@v3"

- name: "Run functional tests"
shell: "bash"
run: "composer test-functional"
run: "composer dev:test:functional"
6 changes: 6 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[submodule "tests/test_helper/bats-assert"]
path = tests/test_helper/bats-assert
url = https://github.com/bats-core/bats-assert.git
[submodule "tests/test_helper/bats-support"]
path = tests/test_helper/bats-support
url = https://github.com/bats-core/bats-support.git
74 changes: 58 additions & 16 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ sure to `composer install`.
To run all the tests and coding standards checks, execute the following from the
command line, while in the project root directory:

```
``` bash
composer test
```

Expand All @@ -170,32 +170,74 @@ repository.

### Functional Tests

This project includes a suite of functional tests located in `tests/expect/`.
These tests use the [Expect](https://en.wikipedia.org/wiki/Expect) tool to
automate CLI interactions. The tests will run automatically as part of
continuous integration, or you may run them locally with:
This project includes a suite of functional tests located in `tests/functional/`.
These tests use [Bats](https://bats-core.readthedocs.io/) and
[Expect](https://en.wikipedia.org/wiki/Expect) to test CLI interactions.
The tests will run automatically as part of continuous integration, or you may
run them locally with:

```
``` bash
composer test-functional
```

To run the tests, you must have an up-to-date version of coreutils (8.30 or
later).
later), and `expect` and `bats` must be installed on your system.

To generate a new functional test:
Not all functional tests need to use Expect, but anything that requires user
interaction (i.e., prompting the user for input) will be easier to test with
Expect.

```
cd tests/expect/
autoexpect ../../bin/conventional-commits prepare --config ../configs/default.json
You can auto-generate an Expect script using the following:

``` bash
cd tests/functional/expect/
autoexpect ../../../bin/conventional-commits --no-ansi prepare --config ../../configs/default.json
```

Follow the prompts to enter the data you wish to test. When finished,
`autoexpect` will save the test to `script.exp`. Rename it with a more
descriptive name, and run it to ensure it does what you expect: `./script.exp`.
You may need to edit the test file or add to it, according to your needs.
`autoexpect` will save the test to `script.exp`. Rename it to a more
descriptive name, and run it to ensure it does what you expect (e.g.,
`./script.exp`).

You will need to edit the generated Expect script to ensure the paths are
correct for running it from Bats. At the very least, your changes should look
something like this:

``` diff
--- a/tests/functional/expect/script.exp
+++ b/tests/functional/expect/script.exp
@@ -42,8 +42,11 @@ if {$force_conservative} {
# -Don


+variable scriptPath [file normalize [info script]]
+variable scriptDir [file dirname $scriptPath]
+
set timeout -1
-spawn ../../../bin/conventional-commits --no-ansi prepare --config ../../configs/default.json
+spawn $scriptDir/../../../bin/conventional-commits --no-ansi prepare --config $scriptDir/../../configs/default.json
match_max 100000
expect -exact "\r
Prepare Commit Message\r
```

You may also need to make other changes to the Expect script, depending on what
you're trying to test. Expect scripts are written in Tcl. To learn more about
what you can do in Expect,
[check out the man pages and examples](https://wiki.tcl-lang.org/page/Expect).

After you've completed your expect script, you can create a Bats test to run it
and perform assertions on the output. For example:

``` bats
@test 'prepares a basic commit message' {
run -0 "$PROJECT_ROOT/tests/functional/expect/prepare-basic.exp"

assert_output -p 'feat: this is a test'
}
```

When done, `cd ../..` and run `composer test-functional`.
Your new test should run along with the other functional tests.
See the other Bats tests in `tests/functional/` for examples.

[github]: https://github.com/ramsey/conventional-commits
[issues]: https://github.com/ramsey/conventional-commits/issues
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
"phpstan/phpstan-mockery": "^1.1",
"phpstan/phpstan-phpunit": "^1.3",
"phpunit/phpunit": "^10.1",
"ramsey/coding-standard": "^2.2",
"ramsey/coding-standard": "^2.3",
"ramsey/composer-repl": "^1.4",
"roave/security-advisories": "dev-latest",
"sebastianfeldmann/cli": "^3.4",
Expand Down Expand Up @@ -111,7 +111,7 @@
],
"dev:test:coverage:ci": "phpunit --colors=always --coverage-text --coverage-clover build/coverage/clover.xml --coverage-cobertura build/coverage/cobertura.xml --coverage-crap4j build/coverage/crap4j.xml --coverage-xml build/coverage/coverage-xml --log-junit build/junit.xml",
"dev:test:coverage:html": "phpunit --colors=always --coverage-html build/coverage/coverage-html/",
"dev:test:functional": "./tests/bash-test tests/functional-tests.sh",
"dev:test:functional": "bats tests/functional",
"dev:test:unit": "phpunit --colors=always",
"test": "@dev:test",
"test-functional": "@dev:test:functional"
Expand Down
4 changes: 2 additions & 2 deletions tests/ConventionalCommits/Configuration/FinderToolTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ class FinderToolTest extends TestCase
{
use SnapshotsTool;

private InputInterface&MockInterface $input;
private InputInterface & MockInterface $input;

private object $finderTool;

private OutputInterface&MockInterface $output;
private OutputInterface & MockInterface $output;

protected function setUp(): void
{
Expand Down
Loading

0 comments on commit f9e3f83

Please sign in to comment.