In this tutorial, I will show you how to setup PHPUnit in PHPStorm.
This step might be optional since composer is already added to the project. But anyways
In the project title > right click > composer > init composer
You would click on download composer and store it in the project. But since I already have it, I just added C:\ProgramData\ComposerSetup\bin
Once Composer is installed then you can add dependencies by going to the same method above. In the project title > right click > composer > add dependencies. Search for phpunit/phpunit. Since I already had Composer installed, I just edited the composer.json file in project.
Then I added a new test folder in root which will contain all my tests.
To create a test, right click in the test folder > php unit > phpunit test
Give it a name
Used this code.
To run the test. Edit the configuration and add a new runner. Top right dropdown next to the right green triangle.
Add a new runner of type PHP Unit
In the configuration.
- Give it a name.
- Directory > select the location of the test folder.
- Click on the configurator icon > use custom loader > get the path of the composer autoload. It should be in /vendor in the project.
Now you can press the green triangle and run it.
Calculator Class & Test
Calculator Class in test_src
Calculator Test Script