andrejsstepanovs

phpstorm dev setup

Aug 5th, 2021
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.99 KB | None | 0 0
  1. # PHPStorm setup
  2.  
  3.  
  4. ## Enable Symfony plugin
  5. - `File` -> `Settings` -> `Languages & Frameworks` -> `PHP`
  6. - `Symfony` -> `Enable Plugin for this Project (change need restart)`
  7. - `OK`
  8. - Restart PHPStorm
  9.  
  10.  
  11. ## Configure PHP CLI Interpreter
  12.  
  13. - `File` -> `Settings` -> `Languages & Frameworks` -> `PHP`
  14. - `PHP language level`: 7.4
  15. - `CLI Interpreter` -> `...` -> `+` -> `From Docker, Vagrant, VM, WSL, Remote...` -> `Docker Compose`
  16. - `Service`: app
  17. - `OK`
  18. - `Lifecycle`: Connect to existing container ('docker-compose exec')
  19. - Check that Xdebug was found
  20. - `OK`
  21. - `OK`
  22.  
  23.  
  24. ## PHP CS Fixer & PHPStan
  25.  
  26. These tools require to be installed. For sake of speed it is recommended to use them locally. So you need to have php installed locally to do that. (it is possible to run them using docker-compose app)
  27.  
  28. So to get them locally in existing project then start container with dir mounted and install these tools:
  29.  
  30. ```
  31. cp docker-compose.override.yml.dist docker-compose.override.yml
  32. docker-compose up -d
  33. docker-compose exec app app-build
  34. docker-compose down
  35. ```
  36.  
  37. Then proceed with configuraiton:
  38.  
  39. ### Enable code checks:
  40.  
  41. - `File` -> `Settings` -> `Editor` -> `Inspections` -> `Quality tools`
  42. - `PHP CS Fixer validation`: check
  43. - `PHPStan validation`: check
  44.  
  45. ### Configure tools:
  46.  
  47. - `File` -> `Settings` -> `Languages & Frameworks` -> `PHP` -> `Quality tools`
  48. - `PHP CS Fixer` -> `Configuration`: local
  49. - `...` -> `PHP CS Fixer path`: tools/php-cs-fixer
  50. - `Validate`
  51. - `OK`
  52. - `PHPStan` -> `Configuration`: local
  53. - `...` -> `PHPStan path`: vendor/bin/phpstan
  54. - `Validate`
  55. - `OK`
  56. - `OK`
  57.  
  58. ### Auto format
  59.  
  60. Then you should be able to open php file and see warning notices.
  61. Auto fix them with:
  62.  
  63. - `Code` -> `Reformat Code`
  64.  
  65. ## Phpunit
  66.  
  67. ### Configure phpunit paths
  68.  
  69. - `File` -> `Settings` -> `Languages & Frameworks` -> `PHP`
  70. - `Test Frameworks`
  71. - Click trough existing tools and find phpunit one
  72. - Validate "PHPUnit library" config
  73. - `Use Composer autoloader`
  74. - `Test Runner` -> `Default configuration file`: {full local path to phpunit.xml.dist}
  75.  
  76. ### Create phpunit runner
  77.  
  78. - `Run` -> `Edit configuration`
  79. - `+` -> `PHPUnit`
  80. - `Name`: phpunit
  81. - `Test Runner`
  82. - `Test scope`: Defined in the configuration file
  83. - `Interpreter`: app
  84. - `OK`
  85.  
  86. Use it from within PHPStorm
  87.  
  88. ```
  89. Run -> Run 'phpunit' with Coverage
  90. ```
  91.  
  92.  
  93. ## Debug cli command
  94.  
  95. - `Run` -> `Edit configuration`
  96. - `+` -> `PHP Script`
  97. - `Name`: app:test
  98. - `File`: bin/console
  99. - `Arguments`: app:test
  100. - `Interpreter`: app
  101. - `OK`
  102.  
  103. Use it from within PHPStorm
  104.  
  105. Open: `src/Command/TestCommand.php`
  106.  
  107. Add breakpoints and run script
  108.  
  109. - `Run` -> `Debug 'app:test'`
  110.  
  111.  
  112. ## Composer script: grump
  113.  
  114. - `File` -> `Settings` -> `Languages & Frameworks` -> `PHP`
  115. - `Composer`
  116. - `Execution` -> `CLI Interpreter`: app
  117. - `OK`
  118.  
  119. ### Run composer command:
  120.  
  121. - `Tools` -> `Composer` -> `Validate`
  122.  
  123. ### Create grump script:
  124.  
  125. - `Run` -> `Edit configuration`
  126. - `+` -> `Composer Script`
  127. - `Name`: `grump`
  128. - `Script`: `grump`
  129. - `OK`
  130.  
  131.  
  132. ## WEB debug
  133.  
  134. This setup is tested using `devs` reverse proxy running.
  135.  
  136. Create new server with correct mapping.
  137.  
  138. - `File` -> `Settings` -> `Languages & Frameworks` -> `PHP` -> `Servers`
  139. - `+`
  140. - `Name`: `sylius-server`
  141. - `Host`: `*`
  142. - `Port`: `8080`
  143. - `Use path mapping`
  144. - For root path add: `/var/www/app`
  145. - `OK`
  146.  
  147. Then start listening for xdebug requests:
  148.  
  149. `Run` -> `Start Listening for PHP Debug Connections`
  150.  
  151. `Run` -> `Break at first line in PHP scripts`
  152.  
  153. Install browser toolbar
  154. https://www.jetbrains.com/help/phpstorm/2020.3/browser-debugging-extensions.html
  155.  
  156. Open app website:
  157. https://de_de.sylius.localhost/
  158.  
  159. Turn debugger toolbar on
  160. Refresh page and switch PHPStorm
  161.  
Add Comment
Please, Sign In to add comment