PHP code example of nabeelalihashmi / lighttest

1. Go to this page and download the library: Download nabeelalihashmi/lighttest library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

nabeelalihashmi / lighttest example snippets



function getName() {
    return 'Nabeel Ali';
}
function getName2() {
    return 'Not Nabeel Ali but Nabeel Ali';
}

function getAge() {
    return 28;
}
function getAgeWrong() {
    return "28";
}

function printName() {
    echo 'Nabeel';
}

$test1 = new LEqualityTest('Nabeel Ali', function() { return getName(); }, "Test First Name");
$test2 = new LEqualityTest('Nabeel Ali', function() { return getName2(); }, "Testing Second Name");
$test3 = new LInstanceOfTest('string', function() { return getName(); }, "Testing If Name is a string");
$test4 = new LInstanceOfTest('integer', function() { return getAge(); }, "Testing if Age is an integer");
$test5 = new LInstanceOfTest('integer', function() { return getAge(); }, "Testing if Age is an integer");
$test6 = new LOutputEqualityTest('Nabeel', function() {  printName(); }, "Testing output of printName()");

$lt = new LightTest();
$lt->addTest($test1);
$lt->addTest($test2);
$lt->addTest($test3);
$lt->addTest($test4);
$lt->addTest($test5);
$lt->addTest($test6);
$lt->run();


namespace IconicCodes\LightTest;

class LInstanceOfTest extends LTest
{
    public function runAfter() {
        $this->result = gettype($this->result);
    }
    public function handle()
    {
        $this->__start();
        if ($this->getResult() == $this->expectedOutput) {
            $this->pass();
        } else {
            $this->fail();
        }
    }
}