Don't forget to set Path Mappings for your remote environments! That is, you probably have your project in, say, $HOME/projects/cool-project, but inside a docker or on a remote host it might be located at /app or /var/Place a cursor inside a test method, press the shotcut: PHPStorm will launch PHPUnit with that particular test method! When the cursor in a scope of test class but not inside a test method - the whole test class will be run. Follow this guide, it has much more information which will be more up-to-date than this post. Go to Settings -> Languages and Frameworks -> PHP -> Test Frameworks. Next step - creating PHPUnit configuration. "Remote" can be pretty much everything: SSH if your Dev environment runs on a shared sandbox for all developers, docker or docker-compose if you run it using docker containers. "Local" is the PHP that you have on your workstation, the host machine. You will find both local and remote interpreter setups. For all those integrations, you will first need to setup the PHP interpreter for the project: Configuring PHP Development Environment. Test fails, you click on a trace entry, get to a problematic line, place a break point, re-run the test in debug mode - and there you go. I also find the ability to run a debugger for a unit test, extremely attractive. Second, the test results appear right there, in PHPStorm, with failures and their stack traces, every entry clickable and takes you directly to the file:line where a nasty thing happened. First, it's super-handy to launch a test method, test class or a whole folder with tests, just by pressing a hotkey. However, there are certain advantages in running tests from the IDE. I even know a guy who runs watch phpunit /path/to/test while developing: this way the test is run every 2 seconds, you switch to the terminal whenever you want to see the latest results and that's it. As of unit tests, I often hear that it's good enough to run tests from the terminal. Sometimes it can save you hours of old school var_dumping. If you see the code for the first time, if you work with legacy code - step-by-step interactive debugging is the way to go. Even if you use VMs or containers to run your development environment, chances are they got you covered! I often see even experienced PHP programmers debugging their code with var_dump(), which is obviously not the best way to do it. This industry-standard level IDE has tons of capabilities for integrating test frameworks and debuggers into your project. You know that unit tests are essential, don't you? So do the PHPStorm developers. In this post, I'll say a few words on this beautiful IDE, PHPUnit and XDebug. Now that the Thanksgiving and Black Friday are left behind, we're all back at our desks, some of us having PHPStorm open for the whole day.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |