PHP unit Globally with Xampp and Windows

PHP unit Globally with Xampp and Windows

To use PHP Unit globally and with XAMPP and Windows follow this. Using Git bash run
composer global require "phpunit/phpunit=4.1.*"
then run
phpunit --version
to check its installed. Download to a new folder in C:/xampp/phpunit PHP Unit with the command
composer require --dev phpunit/phpunit ^5
In your website directory create a folder called tests. In here create a file called StackTest.php and add this code
use PHPUnit\Framework\TestCase;

class StackTest extends TestCase
    public function testPushAndPop()
        $stack = [];
        $this->assertEquals(0, count($stack));

        array_push($stack, 'foo');
        $this->assertEquals('foo', $stack[count($stack)-1]);
        $this->assertEquals(1, count($stack));

        $this->assertEquals('foo', array_pop($stack));
        $this->assertEquals(0, count($stack));
Globally you can now run
phpunit --bootstrap C:/xampp/phpunit/vendor/autoload.php StackTest.php
to run your tests.

Categories: Posts