to use phpunit you can download the phpunit.phar
:
After downloading, copy phpunit.phar file into a folder
(you can download in a folder that is mapped on %PATH% environment variable, or in the project folder)
An example of use:
php.exe phpunit.phar tests\myTest.php
but a better approach is to use composer:
there are some ways to install using composer.
its possible to initialize a new project, use the command:
composer require --dev phpunit\phpunit
this command will download the latest stable version inside vendor folder.
if you are in an existent composer project, then add phpunit dependecy to composer.json:
"require-dev": {
"phpunit/phpunit": "^6.4",
...
and execute:
composer update
create a file for tests named UserTest.php:
<?php
use PHPUnit\Framework\TestCase;
class UserTest extends TestCase
{
public function testTalkToTheWorld() {
$expected = "Hello world!";
$actual = 'Hello !';
$this->assertEquals($expected, $actual);
}
}
Execute in the root folder:
vendor/bin/phpunit --color --testdox UserTest.php
testdox option: Report test execution progress in TestDox format.
or simply:
vendor/bin/phpunit UserTest.php
links: