Done!

Setting up Initial PHP Project with composer, php unit and Initialize with Git


Create a git project on Git Hub and clone it into local

git clone https://github.com/sambhuRajSingh/DataStructure.git

Create composer.json file with phpunit as its dependencies to be installed. Assume DataStructure is the name of the application.

{
    "name": "Project/DataStructure",
    "require-dev": {
        "phpunit/phpunit": "~4.0"
    },
    "autoload": {
        "psr-4": {
            "DataStructure\\": "app/"
        }
    }
}

On terminal run composer install

In case, you change application name, you will need to run composer dump-autoload -o

As you have specified DataStructure to be the app folder in the composer file, make app folder as well as test folder for unit testing

Also create phpunit.xml file. Within it use boilerplate code below and specify test directory created in earlier step

<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
    <testsuites>
        <testsuite name="Application Test Suite">
            <directory>./test/</directory>
        </testsuite>
    </testsuites>
</phpunit>

Now, running phpunit on terminal should run all the test inside the test folder

create index.php and create include autoload.php file as below

   
<?php

    ini_set('display_errors', 1);
    error_reporting(E_ALL);

    require 'vendor/autoload.php';

    //can run php index.php from command line or create a virtual host to point to this file.

Thanks