Download as pdf or txt
Download as pdf or txt
You are on page 1of 10

Dr.

Rahmanian Academy

http://www.alirahmanian.com/
chapters
• Installing PHPUnit
• PHPUnit Support in IDEs
• Tests and What They're All About
• Writing and Running Tests
• Testing Functions
• Testing Class Methods
• Test Fixtures and Data Providers
• Command Line Options
• Filtering Tests
• Errors vs. Failures
• Autoloading
• The setup and teardown methods
• Php command line interpreter-------- > run test from cli
• phpUnit --------> framework
• Xdebug ---------> This is a PHP extension for remote debugging, code
coverage, and m
Installation methods:
✓Composer installation
• PEAR installation
• Linux package installation
• Manual installation

➢ To test if PHP CLI is installed on your machine, run the following command line:

> php -r "echo 'Hello, World!';"


Local installation
• You can specify and download PHPUnit only for your specific project
• PHPUnit installation with Composer, you have to create a composer.json
file. The simplest version could look the following lines of code:
{
"require-dev": {
"phpunit/phpunit": "3.7.*"
}
}
System-wide installation
{
"require": {
"phpunit/phpunit": "3.7.*"
},
"config": {
"bin-dir": "/usr/local/bin/"
}
}
System-wide installation might be easier in the beginning, and allows you to run tests from the
command line. It's easier to start with moving composer.phar to the project document root—the same
place where the composer.json file is stored. Then, to install PHPUnit, just run the following command
line:
➢php composer.phar install
(Install xdebug extension )
➢phpunit
Method2: setting up PHPUnit
1. Create a new PHP project: First, create a new directory for your PHP
project. For example, you could create a directory called “phpunit-
intro”.
2. Install Composer:
3. Use the composer config generator to generate the composer.json
file:
➢composer init
for the last question use the following answer Search for a
package: phpunit/phpunit and install the latest version.
• Run the following command:
➢composer dump-autoload
• Finally, create a new file in your project directory called
“phpunit.xml”. This file will contain the configuration settings for
PHPUnit, such as the location of your test files and the output format
for test results.
• Here’s an example configuration file:
• Create a bootstrap.php file in the src folder with the following content:

You might also like