@@ -69,14 +69,14 @@ For a quick start, follow the below steps.
69
69
70
70
#### DDEV installation
71
71
72
- This project is fully compatible with DDEV 1.19.1 , and it is recommended to use this specific version.
72
+ This project is fully compatible with DDEV 1.19.3 , and it is recommended to use this specific version.
73
73
For the DDEV installation, please follow the [ official instructions] ( https://ddev.readthedocs.io/en/stable/#installation ) .
74
74
On a Linux distribution, you can run:
75
75
```
76
76
sudo apt-get -qq update
77
77
sudo apt-get -qq -y install libnss3-tools
78
78
curl -LO https://raw.githubusercontent.com/drud/ddev/master/scripts/install_ddev.sh
79
- bash install_ddev.sh v1.19.1
79
+ bash install_ddev.sh v1.19.3
80
80
rm install_ddev.sh
81
81
```
82
82
@@ -86,18 +86,18 @@ rm install_ddev.sh
86
86
The final structure of the project will look like below.
87
87
88
88
```
89
- php-project-sources
89
+ php-project-sources (choose the name you want for this folder)
90
90
│
91
91
│ (your php project sources; could be a simple index.php file)
92
92
│
93
- └───.ddev
93
+ └───.ddev (do not change this folder name)
94
94
│ │
95
95
│ │ (Cloned sources of a PHP specific ddev repo)
96
96
│
97
- └───my-own-modules
98
- │
97
+ └───my-own-modules (do not change this folder name)
99
98
│
100
- └───crowdsec-php-lib
99
+ │
100
+ └───crowdsec-php-lib (do not change this folder name)
101
101
│
102
102
│ (Clone of this repo)
103
103
@@ -212,7 +212,7 @@ Finally, run
212
212
213
213
214
214
``` bash
215
- ddev exec BOUNCER_KEY=your-bouncer-key LAPI_URL=http://crowdsec:8080 MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./my-own-modules/crowdsec-php-lib/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./my-own-modules/crowdsec-php-lib/tests/IpVerificationTest.php
215
+ ddev exec BOUNCER_KEY=your-bouncer-key LAPI_URL=http://crowdsec:8080 MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./my-own-modules/crowdsec-php-lib/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./my-own-modules/crowdsec-php-lib/tests/Integration/ IpVerificationTest.php
216
216
```
217
217
218
218
For geolocation Unit Test, you should first put 2 free MaxMind databases in the ` tests ` folder : ` GeoLite2-City.mmdb `
@@ -222,7 +222,7 @@ and`GeoLite2-Country.mmdb`. You can download these databases by creating a maxmi
222
222
Then, you can run:
223
223
224
224
``` bash
225
- ddev exec BOUNCER_KEY=your-bouncer-key LAPI_URL=http://crowdsec:8080 /usr/bin/php ./my-own-modules/crowdsec-php-lib/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./my-own-modules/crowdsec-php-lib/tests/GeolocationTest.php
225
+ ddev exec BOUNCER_KEY=your-bouncer-key LAPI_URL=http://crowdsec:8080 /usr/bin/php ./my-own-modules/crowdsec-php-lib/vendor/bin/phpunit --testdox --colors --exclude-group ignore ./my-own-modules/crowdsec-php-lib/tests/Integration/ GeolocationTest.php
226
226
227
227
```
228
228
@@ -295,30 +295,42 @@ yarn global add cross-env
295
295
296
296
#### Coding standards
297
297
298
+ We set up some coding standards tools that you will find in the ` tools/coding-standards ` folder.
299
+ In order to use these, you will need to work with a PHP version >= 7.4 and run first:
300
+
301
+ ```
302
+ ddev composer update --working-dir=./my-own-modules/crowdsec-php-lib/tools/coding-standards
303
+ ```
304
+
298
305
##### PHPCS Fixer
299
306
300
307
We are using the [ PHP Coding Standards Fixer] ( https://cs.symfony.com/ )
301
308
302
309
With ddev, you can do the following:
303
310
311
+
304
312
``` bash
305
- ddev composer update --working-dir=./my-own-modules/crowdsec-php-lib/tools/php-cs-fixer
313
+ ddev phpcsfixer my-own-modules/crowdsec-php-lib/tools/coding-standards/php-cs-fixer ../
314
+
306
315
```
307
- And then:
316
+
317
+ ##### PHPSTAN
318
+
319
+ To use the [ PHPSTAN] ( https://github.com/phpstan/phpstan ) tool, you can run:
320
+
308
321
309
322
``` bash
310
- ddev phpcsfixer my-own-modules/crowdsec-php-lib tools/php-cs-fixer
323
+ ddev phpstan /var/www/html/ my-own-modules/crowdsec-php-lib/ tools/coding-standards phpstan/phpstan.neon /var/www/html/my-own-modules/crowdsec-php-lib/src
311
324
312
325
```
313
326
314
- ** N.B** : to use PHPCS Fixer, you will need to work with a PHP version >= 7.4.
315
327
316
328
##### PHP Mess Detector
317
329
318
330
To use the [ PHPMD] ( https://github.com/phpmd/phpmd ) tool, you can run:
319
331
320
332
``` bash
321
- ddev phpmd ./my-own-modules/crowdsec-php-lib tools/phpmd/rulesets.xml src
333
+ ddev phpmd ./my-own-modules/crowdsec-php-lib/ tools/coding-standards phpmd/rulesets.xml ../../ src
322
334
323
335
```
324
336
@@ -327,15 +339,51 @@ ddev phpmd ./my-own-modules/crowdsec-php-lib tools/phpmd/rulesets.xml src
327
339
To use [ PHP Code Sniffer] ( https://github.com/squizlabs/PHP_CodeSniffer ) tools, you can run:
328
340
329
341
``` bash
330
- ddev phpcs ./my-own-modules/crowdsec-php-lib/vendor/bin/phpcs my-own-modules/crowdsec-php-lib/src
342
+ ddev phpcs ./my-own-modules/crowdsec-php-lib/tools/coding-standards my-own-modules/crowdsec-php-lib/src PSR12
331
343
```
332
344
333
345
and:
334
346
335
347
``` bash
336
- ddev phpcbf ./my-own-modules/crowdsec-php-lib/vendor/bin/phpcs my-own-modules/crowdsec-php-lib/src
348
+ ddev phpcbf ./my-own-modules/crowdsec-php-lib/tools/coding-standards my-own-modules/crowdsec-php-lib/src PSR12
349
+ ```
350
+
351
+
352
+ ##### PSALM
353
+
354
+ To use [ PSALM] ( https://github.com/vimeo/psalm ) tools, you can run:
355
+
356
+ ``` bash
357
+ ddev psalm ./my-own-modules/crowdsec-php-lib/tools/coding-standards ./my-own-modules/crowdsec-php-lib/tools/coding-standards/psalm
337
358
```
338
359
360
+ ##### PHP Unit Code coverage
361
+
362
+ In order to generate a code coverage report, you have to:
363
+
364
+ - Enable ` xdebug ` :
365
+ ``` bash
366
+ ddev xdebug
367
+ ```
368
+
369
+ To generate a html report, you can run:
370
+ ``` bash
371
+ ddev exec XDEBUG_MODE=coverage BOUNCER_KEY=your-bouncer-key LAPI_URL=http://crowdsec:8080
372
+ MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./my-own-modules/crowdsec-php-lib/tools/coding-standards/vendor/bin/phpunit --configuration ./my-own-modules/crowdsec-php-lib/tools/coding-standards/phpunit/phpunit.xml
373
+
374
+ ```
375
+
376
+ You should find the main report file ` dashboard.html ` in ` tools/coding-standards/phpunit/code-coverage ` folder.
377
+
378
+
379
+ If you want to generate a text report in the same folder:
380
+
381
+ ``` bash
382
+ ddev exec XDEBUG_MODE=coverage BOUNCER_KEY=your-bouncer-key LAPI_URL=http://crowdsec:8080
383
+ MEMCACHED_DSN=memcached://memcached:11211 REDIS_DSN=redis://redis:6379 /usr/bin/php ./my-own-modules/crowdsec-php-lib/tools/coding-standards/vendor/bin/phpunit --configuration ./my-own-modules/crowdsec-php-lib/tools/coding-standards/phpunit/phpunit.xml --coverage-text=./my-own-modules/crowdsec-php-lib/tools/coding-standards/phpunit/code-coverage/report.txt
384
+ ```
385
+
386
+
339
387
340
388
#### Generate CrowdSec tools and settings on start
341
389
0 commit comments