Skip to content

Commit aa20430

Browse files
authored
doc: run component test
1 parent 04d5cff commit aa20430

File tree

1 file changed

+59
-18
lines changed

1 file changed

+59
-18
lines changed

CONTRIBUTING.md

+59-18
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ Then, if it appears that it's a real bug, you may report it using GitHub by foll
1616
* A clear title to resume the issue
1717
* A description of the workflow needed to reproduce the bug
1818

19-
> _NOTE:_ Don't hesitate giving as much information as you can (OS, PHP version extensions...)
19+
> [!NOTE]
20+
> Don't hesitate giving as much information as you can (OS, PHP version extensions...)
2021
2122
## Pull Requests
2223

@@ -153,6 +154,9 @@ Coverage will be available in `coverage/index.html`.
153154

154155
#### Behat
155156

157+
> [!WARNING]
158+
> Please **do not add new Behat tests**, use a functional test (for example: [ComputedFieldTest](https://github.com/api-platform/core/blob/04d5cff1b28b494ac2e90257a79ce6c045ba82ae/tests/Functional/Doctrine/ComputedFieldTest.php)).
159+
156160
The command to launch Behat tests is:
157161

158162
php -d memory_limit=-1 ./vendor/bin/behat --profile=default --stop-on-failure --format=progress
@@ -165,27 +169,64 @@ To get more details about an error, replace `--format=progress` by `-vvv`. You m
165169

166170
docker run -p 27017:27017 mongo:latest
167171

168-
Start by adding a fixture, usually using Doctrine entities in `tests/Fixtures/TestBundle/Entity`. Note that we often duplicate the fixture
169-
in the `tests/Fixtures/TestBundle/Document` directory for MongoDB ODM, if your test doesn't need to be tested with MongoDB use the `@!mongodb` group on the Behat scenario.
170-
If you need a `Given` step, add it to the doctrine context in `tests/Core/Behat/DoctrineContext.php`, for example:
172+
## Components tests
171173

172-
```
173-
/**
174-
* @Given there is a payment
175-
*/
176-
public function thereIsAPayment()
177-
{
178-
$this->manager->persist(new Payment('123.45'));
179-
$this->manager->flush();
180-
}
181-
```
174+
> [!NOTE]
175+
> This requires linking dependencies together, we recommend to use `composer global require --dev soyuka/pmu` (see [soyuka/pmu](github.com/soyuka/pmu)).
182176
183-
The last step is to add you feature inside `features/`. You can add your test in one of our existing features, or create your own.
177+
API Platform is split into several components, components have their own set of tests.
184178

185-
## Components tests
179+
To run a component test:
180+
181+
```bash
182+
COMPONENT_DIR=$(api-platform/doctrine-common cwd)
183+
ROOT_DIR=$(pwd)
184+
cd $COMPONENT_DIR
185+
composer link $ROOT_DIR
186+
./vendor/bin/phpunit
187+
```
188+
189+
<details>
190+
<summary>Run all the tests</summary>
191+
192+
193+
```bash
194+
#!/bin/bash
195+
196+
set -e
197+
198+
COMPONENTS=(
199+
"api-platform/doctrine-common"
200+
"api-platform/doctrine-orm"
201+
"api-platform/doctrine-odm"
202+
"api-platform/metadata"
203+
"api-platform/hydra"
204+
"api-platform/json-api"
205+
"api-platform/json-schema"
206+
"api-platform/elasticsearch"
207+
"api-platform/openapi"
208+
"api-platform/graphql"
209+
"api-platform/http-cache"
210+
"api-platform/ramsey-uuid"
211+
"api-platform/serializer"
212+
"api-platform/state"
213+
"api-platform/symfony"
214+
"api-platform/validator"
215+
)
216+
217+
PROJECT_ROOT=$(pwd)
218+
for component in "${COMPONENTS[@]}"; do
219+
cd "$PROJECT_ROOT"
220+
find src -name vendor -exec rm -r {} \; || true
221+
COMPONENT_DIR=$(composer "$component" --cwd)
222+
cd $COMPONENT_DIR
223+
composer link $PROJECT_ROOT
224+
./vendor/bin/phpunit --fail-on-deprecation --display-deprecations
225+
done
226+
exit 0
227+
```
228+
</details>
186229

187-
API Platform is split into several components. There are tests for each of these, to run them `cd src/Doctrine/Common` then `composer update` and `./vendor/bin/phpunit`.
188-
We do not provide a way to run all these tests at once yet.
189230

190231
## Changing a version constraint
191232

0 commit comments

Comments
 (0)