PHP code example of fabstract / unit-test

1. Go to this page and download the library: Download fabstract/unit-test 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/ */

    

fabstract / unit-test example snippets


    
    namespace MyPackage;
    
    class Calculator
    {
        public function add($a, $b) {
            return $a + $b;
        }
        
        public function multiply($a, $b) {
            return $a * $b;
        }
    }


    namespace MyPackage\Calculator;

    class AddMethodTest extends \Fabstract\Component\UnitTest\MethodTestBase
    {
        public function testOneAndOneEqualsTwo() {
            $arguments = [1, 1];
            
            $result = $this->call(new Calculator(), $arguments);
            
            $this->assertEquals(2, $result);
        }
        
        public function testOneAndZeroEqualsOne() {
            $arguments = [1, 0];
            
            $result = $this->call(new Calculator(), $arguments);
            
            $this->assertEquals(1, $result);
        }
    }


    namespace MyPackage\Calculator;

    class MultiplyMethodTest extends \Fabstract\Component\UnitTest\MethodTestBase
    {
        public function testOneAndOneEqualsOne() {
            $arguments = [1, 1];
            
            $result = $this->call(new Calculator(), $arguments);
            
            $this->assertEquals(1, $result);
        }
        
        public function testOneAndZeroEqualsZero() {
            $arguments = [1, 0];
            
            $result = $this->call(new Calculator(), $arguments);
            
            $this->assertEquals(0, $result);
        }
    }