<?php
namespace UnitTestFiles\Test;
use PHPUnit\Framework\TestCase;

class NodeFileTest extends TestCase
{
    /**
     * @dataProvider additionProvider
     */
    public function testAdd($val, $expected)
    {
        $random = substr(md5(mt_rand()), 0, 7);
        $input_code = 'let user_input = "' . $val . '";';
        
        $filePath = "/var/www/html/ide/temp/unit_" . $random. ".js";
        $unitTestfilePath = "/var/www/html/ide/temp/node_test.js";
        $code = file_get_contents($unitTestfilePath);
        $programFile = fopen($filePath, "w");
        fwrite($programFile, $input_code . $code);
        fclose($programFile);

        $output = shell_exec("node $filePath 2>&1");
        $output= (int)str_replace("\r\n","",$output);
        $expected= (int)str_replace("\r\n","",$expected);
        
        $this->expectOutputString($expected);
        print $output;
        unlink($filePath);
    }

    public function additionProvider()
    {
        return [
            ["1 1 1",3],
            ["15 15",30],
            ["25 25",50]
        ];
    }
}

?>