You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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.
24
24
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
40
26
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:
42
28
43
29
```yaml
44
30
app:
45
31
- app
46
32
- src
33
+
47
34
tests:
48
35
engine: pest
49
36
parallel: true
@@ -53,17 +40,7 @@ tests:
53
40
- '*.test.php'
54
41
coverage:
55
42
processUncoveredFiles: true
56
-
```
57
43
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
-
...
67
44
lint:
68
45
preset: 'PSR12'
69
46
ignore_dot_files: true
@@ -76,13 +53,49 @@ lint:
76
53
imports_order: null
77
54
case_sensitive: false
78
55
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'
79
68
```
80
69
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.
82
71
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.
84
81
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
+
```
86
99
87
100
- `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.
88
101
@@ -94,34 +107,22 @@ Breaking down the `alchemy.yml` file:
94
107
95
108
- `tests.files`: The files to look for tests in.
96
109
97
-
- `coverage`: Configuration for code coverage.
110
+
- `tests.coverage`: Configuration for code coverage.
98
111
- You can set `processUncoveredFiles` to `true` to process files that are not covered by tests.
99
112
- 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.
100
113
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.
106
115
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
108
117
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.
110
119
111
120
```yaml
112
121
app:
113
122
- app
114
123
- src
115
124
116
-
tests:
117
-
engine: pest
118
-
parallel: true
119
-
paths:
120
-
- tests
121
-
files:
122
-
- '*.test.php'
123
-
coverage:
124
-
processUncoveredFiles: true
125
+
...
125
126
126
127
lint:
127
128
preset: 'PSR12'
@@ -137,6 +138,42 @@ lint:
137
138
sort_algorithm: 'alpha'
138
139
```
139
140
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
+
140
177
## Overriding Alchemy Configuration
141
178
142
179
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