@jasen_gottlieb
To install PHPUnit using Composer, you can follow these steps:
- Install Composer: If you haven't already installed Composer, go to the Composer website (getcomposer.org) and follow the instructions for installation on your operating system.
- Create a new project directory: Open a terminal, navigate to the directory where you want to create your project, and run the following command:
1
2
|
$ mkdir project-name
$ cd project-name
|
- Initialize a new Composer project: Run the following command to initialize a new composer project in the current directory:
This command will guide you through creating a composer.json file, which defines the dependencies for your project.
- Add PHPUnit as a dependency: Once the initialization is complete, open the composer.json file in a text editor and add PHPUnit as a dependency. Add the following code to the "require-dev" section:
1
2
3
|
"require-dev": {
"phpunit/phpunit": "^9.0"
}
|
This will install PHPUnit as a development dependency for your project.
- Save the composer.json file and close the editor.
- Install PHPUnit: Run the following command to install PHPUnit and its dependencies:
Composer will download PHPUnit and all its dependencies to the vendor directory in your project.
- Verify PHPUnit installation: To verify that PHPUnit is installed correctly, run the following command in your terminal:
1
|
$ vendor/bin/phpunit --version
|
This should display the version of PHPUnit installed in your project.
Now you can start using PHPUnit in your project for writing and running tests.