Skip to content

Commit 20985d9

Browse files
committed
feat: update alchemy docs
1 parent 3185cac commit 20985d9

File tree

1 file changed

+84
-47
lines changed

1 file changed

+84
-47
lines changed

src/docs/utils/testing.md

Lines changed: 84 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -20,30 +20,17 @@ composer require leafs/alchemy
2020

2121
:::
2222

23-
Once installed, Alchemy will automatically set up an `alchemy.yml` file in your project's root along with some dummy tests in a `tests` directory using [Pest PHP Framework](https://pestphp.com/). Alchemy will also add a `test` and `lint` command to your project's `composer.json` file.
23+
Once installed, Alchemy will automatically set up an `alchemy.yml` file in your project's root which you can use to configure your tests, linting and github actions.
2424

25-
You should be able to run the dummy tests by running the following command:
26-
27-
::: code-group
28-
29-
```bash:no-line-numbers [Leaf CLI]
30-
leaf run test
31-
```
32-
33-
```bash:no-line-numbers [Composer]
34-
composer run test
35-
```
36-
37-
:::
38-
39-
If you don't want to use Pest, Alchemy also supports PHPUnit. You can change the testing framework by editing the `alchemy.yml` file in your project root, add your tests to the `tests` directory, and run the test command again. You don't need to worry about setting up PHPUnit or Pest as Alchemy will handle that for you.
25+
## Configuring Alchemy
4026

41-
By default Pest expects a `phpunit.xml` file in your project root, but as it's quite annoying to read, Leaf provides a `alchemy.yml` file in your project root. This file is used to configure Pest and is much easier to read and understand. The `alchemy.yml` file is used to configure Pest and can be used to set up your test environment.
27+
The `alchemy.yml` file should look something like this:
4228

4329
```yaml
4430
app:
4531
- app
4632
- src
33+
4734
tests:
4835
engine: pest
4936
parallel: true
@@ -53,17 +40,7 @@ tests:
5340
- '*.test.php'
5441
coverage:
5542
processUncoveredFiles: true
56-
```
5743

58-
## Code Styling
59-
60-
Alchemy allows you to define code styling rules in your `alchemy.yml` file. Alchemy linting uses PHP CS Fixer which is a powerful tool that fixes your code to follow standards; whether you want to follow PHP coding standards as defined in the PSR-1, PSR-2, etc. Of course, all of this is abstracted into the beautiful `alchemy.yml` file.
61-
62-
```yaml
63-
app:
64-
- app
65-
- src
66-
...
6744
lint:
6845
preset: 'PSR12'
6946
ignore_dot_files: true
@@ -76,13 +53,49 @@ lint:
7653
imports_order: null
7754
case_sensitive: false
7855
sort_algorithm: 'alpha'
56+
57+
actions:
58+
run:
59+
- 'lint'
60+
- 'test'
61+
php:
62+
extensions: json, zip
63+
versions:
64+
- '8.3'
65+
event:
66+
- 'push'
67+
- 'pull_request'
7968
```
8069
81-
As you see, you can set up your code styling rules in the `lint` section of the `alchemy.yml` file. All of [PHP-CS-Fixer Configurator](https://mlocati.github.io/php-cs-fixer-configurator/) rules are supported.
70+
You can make edits to this file to suit your needs. The `app` key is an array of directories to look for your app files in. The `tests` key is an array of configurations for your tests. The `lint` key is an array of configurations for your code styling checks. Once you're done setting up your `alchemy.yml` file, you can run the setup script.
8271

83-
## Configuring Alchemy
72+
```bash
73+
leaf run alchemy # or composer run alchemy
74+
```
75+
76+
This will install your test engine, PHP CS Fixer and any other dependencies you might need, and then generate dummy tests using the test engine you chose. It will then lint your code, run your tests and generate a coverage report (if you selected that option). It will also add a `test` and `lint` command to your `composer.json` file which you can use to run your tests and lint your code respectively. Finally, it will generate a `.github/workflows` directory with a `test.yml` file and a `lint.yml` file which you can use to run your tests and linting on github actions.
77+
78+
## Configuring Tests
79+
80+
If you don't want to use Pest, Alchemy also supports PHPUnit. You can change the testing framework by editing the `alchemy.yml` file in your project root, add your tests to the `tests` directory, and run the test command again. You don't need to worry about setting up PHPUnit or Pest as Alchemy will handle that for you.
8481

85-
Breaking down the `alchemy.yml` file:
82+
By default Pest expects a `phpunit.xml` file in your project root, but as it's quite annoying to read, Leaf provides a `alchemy.yml` file in your project root. This file is used to configure Pest and is much easier to read and understand. The `alchemy.yml` file is used to configure Pest and can be used to set up your test environment.
83+
84+
```yaml
85+
app:
86+
- app
87+
- src
88+
89+
tests:
90+
engine: pest
91+
parallel: true
92+
paths:
93+
- tests
94+
files:
95+
- '*.test.php'
96+
coverage:
97+
processUncoveredFiles: true
98+
```
8699

87100
- `app`: This is a list of directories that contain your application code. Alchemy will use these directories to lint your code and also in code coverage reports.
88101

@@ -94,34 +107,22 @@ Breaking down the `alchemy.yml` file:
94107

95108
- `tests.files`: The files to look for tests in.
96109

97-
- `coverage`: Configuration for code coverage.
110+
- `tests.coverage`: Configuration for code coverage.
98111
- You can set `processUncoveredFiles` to `true` to process files that are not covered by tests.
99112
- You can also set `include` to include specific directories in your code coverage report. By default Alchemy will just use the directories defined in the `app` configuration.
100113

101-
- `lint`: Configuration for code styling checks.
102-
103-
- `lint.preset`: The preset to use for code styling checks. You can use any of the presets available to PHP CS Fixer. The default is `PSR12`.
104-
105-
- `lint.ignore_dot_files`: Whether to ignore dot files when linting.
114+
If you don't want code coverage reports, you can just remove the entire `coverage` section.
106115

107-
- `lint.rules`: An array of rules to use for code styling checks. These rules are the same as the rules available in PHP CS Fixer.
116+
## Code Styling
108117

109-
Overall, your `alchemy.yml` file should look something like this:
118+
Alchemy allows you to define code styling rules in your `alchemy.yml` file. Alchemy linting uses PHP CS Fixer which is a powerful tool that fixes your code to follow standards; whether you want to follow PHP coding standards as defined in the PSR-1, PSR-2, etc. Of course, all of this is abstracted into the beautiful `alchemy.yml` file.
110119

111120
```yaml
112121
app:
113122
- app
114123
- src
115124
116-
tests:
117-
engine: pest
118-
parallel: true
119-
paths:
120-
- tests
121-
files:
122-
- '*.test.php'
123-
coverage:
124-
processUncoveredFiles: true
125+
...
125126
126127
lint:
127128
preset: 'PSR12'
@@ -137,6 +138,42 @@ lint:
137138
sort_algorithm: 'alpha'
138139
```
139140

141+
As you see, you can set up your code styling rules in the `lint` section of the `alchemy.yml` file. All of [PHP-CS-Fixer Configurator](https://mlocati.github.io/php-cs-fixer-configurator/) rules are supported.
142+
143+
- `lint`: Configuration for code styling checks.
144+
145+
- `lint.preset`: The preset to use for code styling checks. You can use any of the presets available to PHP CS Fixer. The default is `PSR12`.
146+
147+
- `lint.ignore_dot_files`: Whether to ignore dot files when linting.
148+
149+
- `lint.rules`: An array of rules to use for code styling checks. These rules are the same as the rules available in PHP CS Fixer.
150+
151+
## Configuring GitHub Actions
152+
153+
Alchemy can also set up GitHub Actions for you. You can configure what it should generate in the `alchemy.yml` file. Once you have set up your `alchemy.yml` file, you can run the `alchemy` command to generate the GitHub Actions files.
154+
155+
```yaml
156+
actions:
157+
run:
158+
- 'lint'
159+
- 'test'
160+
php:
161+
extensions: json, zip
162+
versions:
163+
- '8.3'
164+
event:
165+
- 'push'
166+
- 'pull_request'
167+
```
168+
169+
- `actions`: Configuration for GitHub Actions. You can remove this entire section if you don't want to generate GitHub Actions.
170+
171+
- `actions.run`: An array of commands to generate GitHub Actions for. The default is `lint` and `test`, but you can remove any command you don't want to generate.
172+
173+
- `actions.php`: Configuration for PHP in GitHub Actions. You can set the PHP extensions to install and the PHP versions to test against.
174+
175+
- `actions.event`: An array of events to generate GitHub Actions for. The default is `push` and `pull_request`, but you can remove any event you don't want to generate.
176+
140177
## Overriding Alchemy Configuration
141178

142179
Alchemy is designed to be a tool that sets up your tests and code styling checks with minimal configuration. Once you have written all the tests you need for your app and have your code styling checks, there's no longer the need for Alchemy's training wheels. At that point, you can remove Alchemy from your project and use PHPUnit or Pest directly with PHP CS Fixer.

0 commit comments

Comments
 (0)