MichaelMrt / ChessPHP

Programming Chess in PHP
1 stars 0 forks source link

Automatic tests setup with phpstan #7

Closed MichaelMrt closed 7 months ago

MichaelMrt commented 7 months ago

Automatic tests on the code are working well with phpstan. phpstan is not only detecting errors, but also smaller problems. You can choose from level 0 up to level 8 and change how strict the checks should be.

On level 8 phpstan found 24 errors, keep in mind warnings and notices are all errors in phpstan.

To run phpstan locally you will need to follow these steps:

  1. Install composer on your machine
  2. Run composer init in your terminal and follow the steps in the terminal
  3. Run composer require --dev phpstan/phpstan in terminal to add phpstan to your project with composer
  4. Run vendor/bin/phpstan analyse src --level 0 in the terminal to test the code. As mentioned you can go up to level 8

The vendor folder created by composer is ignored by git.

You might need to tell composer your php.exe path. It is in xampp/php/php.exe

I also setup the main.yml to have automatic tests with github actions on every pull request to main or dev.

These are only general tests, if we want to we can write our own specialized tests later

MichaelMrt commented 7 months ago

Can you try vendor/bin/phpstan analyse src --level 0

And if it doesn't work provide the error message.

MichaelMrt commented 7 months ago

Nice, with src you tell phpstan which foulder should be checked.