Skip to content
Snippets Groups Projects
Commit 9f51fc99 authored by danielspeicher's avatar danielspeicher
Browse files

Doc for testing and code coverage

parent 5ba22706
No related branches found
No related tags found
No related merge requests found
Pipeline #494605 skipped
......@@ -3,6 +3,148 @@ title: Testing
tags:
- documentation
- tools
- tests
---
# Testing Drupal Code
This section describes everything we have to test our code from static
code analysis to unit testing.
You also have to set up your environment with the tool [l3d](../docker/l3d/index.md).
## Static Code Analysis
We have several tools to perform static code analysis.
* PHP LOC
* Code Sniffer
* Mess Detection
### PHP LOC
PHP LOC prints several metrics about your code, like the average size of a class.
To execute PHP LOC on the console:
```l3d
a test phploc <file_ordirectory>
```
Whether it is a directory, it runs the analysis for everything under this directory
recursively.
### PHP Code Sniffer
PHP Code Sniffer performs a static code analysis with a specific Drupal profile. It detects
code smells like static calls.
To execute PHP Code Sniffer on the console:
```l3d
a test phpcs <file_ordirectory>
```
Whether it is a directory, it runs the analysis for everything under this directory
recursively.
### PHP Mess Detection
PHP Mess Detection is a more detailed analysis comparing to code sniffer. It
uses several profiles like:
* cleancode
* design
This analysis detects also code smells like the complexity (e.g. number of
dependencies) of classes.
To execute PHP Code Sniffer on the console:
```l3d
a test phpmd <file_ordirectory> json <profile>
```
Whether it is a directory, it runs the analysis for everything under this directory
recursively.
## Unit/Kernel/Functional Testing
To execute the tests, you can use a single command:
```l3d
a test phpunit <file_ordirectory>
```
All kind of Drupal tests will be executed.
Whether it is a directory, it runs the analysis for everything under this directory
recursively.
You also can execute the tests within your IDE.
First got to the settings of your IDE and add a new PHP interpreter. Select Docker and
enter the form:
![Screenshot](/files/screenshots/settings_php_interpreter.png)
Use the option Docker Compose:
![Screenshot](/files/screenshots/settings_php_interpreter_docker.png)
Fill the following form like:
![Screenshot](/files/screenshots/settings_php_interpreter_new.png)
Use the server you created for [debugging](./debug.md).
The next step is to create a settings for your test framework. Remove all configuration
and add a new one for remote interpreter:
![Screenshot](/files/screenshots/settings_php_test_framework_new_config.png)
![Screenshot](/files/screenshots/settings_php_test_framework_new.png)
Set the autoloader and the configurations file.
Now you are ready to go. Open a directory or a single test file (or method) and click on the green
arrow:
![Screenshot](/files/screenshots/settings_php_test_execution.png)
You can also use the execution with the debugger.
### Code Coverage
First, activate the coverage option:
```l3d
a debug coverage
```
Enter the projects to cover into your ```.lakedrops.yml``` file, like:
```yml
lakedrops-dev:
coverage:
- ../web/modules/contrib/bpmn_io
- ../web/modules/contrib/camunda
- ../web/modules/contrib/eca
- ../web/modules/contrib/eca_entity_share
- ../web/modules/contrib/eca_state_machine
- ../web/modules/contrib/eca_tamper
```
This is just an example!
You have to execute the following command to write a new config file for testing:
```l3d
composer lakedrops:scaffold
```
Now you can execute every test including code coverage. To check, if it is
working properly, a new view for coverage should open in your IDE, like:
![Screenshot](/files/screenshots/settings_php_test_coverage_view.png)
docs/files/screenshots/settings_php_interpreter.png

131 B

docs/files/screenshots/settings_php_interpreter_docker.png

130 B

docs/files/screenshots/settings_php_interpreter_new.png

130 B

docs/files/screenshots/settings_php_test_coverage_view.png

131 B

docs/files/screenshots/settings_php_test_execution.png

130 B

docs/files/screenshots/settings_php_test_framework_new.png

130 B

docs/files/screenshots/settings_php_test_framework_new_config.png

130 B

# New in version 2021.12.15:
# New in version 2022.4.22:
--------
- [](dev_tools/index.md)
- [Debugging](dev_tools/debug.html)
> __
> How to debug within your IDE
- [Host setup](dev_tools/host.html)
> Host configuration
- [Testing](dev_tools/test.html)
> All testing tools including code coverage
This diff is collapsed.
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment