Unit Testing
A fully integrated test runner and a slew of test helpers makes PHPStorm a valuable tool for test development.
New > PHPUnit > PHPUnit Test
ASIDE: Shortcuts
PHPStorm provides a lot of useful shortcuts for generating methods and implementations.
CMD + N
Creating a test configuration
If we are going to be running tests frequently, we will need to set things up so PHPStorm knows how to run our test suite:
Preferences > PHP > PHPUnit
Running tests
To run the current test, just press CTRL + SHIFT + R
If you get this you will need to click "Fix" and point PHPStorm to your PHP install:
Test results are shown in the "Run" panel:
At any point in your project, you can hit CTRL + R to run what was run last
Debugging
Set break points, and step through code like one of the cool kids!
The folks at JetBrains have a ready made play by play for configuring xdebug and using it within PHPStorm:
Creating aN Application configuration
Just like we created a PHPUnit configuration so we could run tests, we do the same for a web application.
Run > Edit Configurations + PHP Web Application
Creating a server configuration
Our application configuration requires a server configuration:
Setting BREAKpoints
We set breakpoints to pause execution and take a peak at the current environment while an application is running:
Click gutter or press cmd+F8
STEPPING Through breakpoints
Instead of CTRL + R to run, we use CTRL + D to start a debug session.
When execution hits a breakpoint we should see the following:
SHORTCUTS
There are shortcuts for stepping over and through debugged code, line by line:
- F8 - Step over
- F7 - Step into
- ALT + CMD + R - Resume program