To configure PHPUnit in XAMPP, follow these steps:
- Install XAMPP on your system if you haven't already. This will install PHP and Apache on your machine.
- Download PHPUnit. You can download the latest stable version of PHPUnit from the official website (https://phpunit.de/). Choose the PHAR (PHP Archive) file.
- Save the PHAR file in a directory accessible from the command line. For example, you can save it in the "htdocs" folder of your XAMPP installation.
- Open a command prompt and navigate to the directory where you saved the PHAR file.
- Run the following command to ensure PHPUnit is correctly installed:
php phpunit.phar --version
- Add the PHPUnit executable to your system's PATH. This will allow you to execute PHPUnit from any directory on the command line. To do this, follow these steps:
Find the "phpunit.phar" file in your file explorer.
Copy the file's path.
Press the "Windows" key and search for "Edit the system environment variables".
Click on the "Environment Variables" button.
Select the "Path" variable under "System variables" and click "Edit".
Click "New" and paste the path of the PHPUnit PHAR file.
Click "OK" on all open windows to save the changes.
- Test if PHPUnit is correctly in your system's PATH by opening a new command prompt and running the following command:
You should see the PHPUnit version being displayed.
- Configure PHPUnit for your project. Create a "phpunit.xml" file at the root of your project directory. Here's an example configuration file:
This configuration file tells PHPUnit to look for test classes in the "tests" directory.
- Write your PHPUnit tests and save them in the "tests" directory specified in the configuration file.
- Run your PHPUnit tests by navigating to your project directory in the command prompt and running the following command:
PHPUnit will execute all the tests in the specified directory and display the results.
That's it! You have now configured PHPUnit in XAMPP.