Installation

composer require phpunit/phpunit

Psr-4 Autoloading

    "autoload":{
        "psr-4": {
            "App\\":"app"
        }
    }

composer dump-autoload -o

Creating the phpunit.xml file

    <?xml version="1.0" encoding="UTF-8"?>
        <phpunit bootstrap="vendor/autoload.php"
            colors="true"
            verbose="true"
            stopOnFailure="false">
            <testsuites>
                <testsuite name="Test Suite">
                    <directory>tests</directory>
                </testsuite>
            </testsuites>
        </phpunit>

Running My first test

    use PHPUnit\Framework\TestCase;
    class SampleTest extends TestCase
    {
        public function testTrueAssertsToTrue()
        {
            $this->assertTrue(true);
        }
    }

A Unit test to get user first name

#/tests/unit/UserTest.php
use PHPUnit\Framework\TestCase;
class UserTest extends TestCase
{
    public function testThatWeCanGetTheFirstName()
    {
        $user = new \App\Models\User;

        $user->setFirstName("Billy");
            $this->assertEquals($user->getFirstName(), 'Billy');
    }
}
#/app/Models/User.php
<?php
namespace App\Models;
class User
{
  public $first_name;

    public function setFirstName($firstname)
    {
        $this->first_name = $firstname;
    }

    public function getFirstName()
    {
       return $this->first_name;
    }
}