I found this answer with no success.
I tried
$test = new \PHPUnit\Framework\TestSuite();
$test->addTestSuite(Tester::class);
$result = $test->run();
and i got error that index '_SERVER' is undefined on line 26 of (PHPUnit\Util\Filter file)
so I changed that line from $GLOBALS['_SERVER']['SCRIPT_NAME']
to use $_SERVER['SCRIPT_NAME']
;
Now I get the error:
Fatal error: Uncaught PHPUnit\Framework\Exception: Argument #1 (No Value) of PHPUnit\Framework\TestSuite::addTestSuite() must be a class name or object /var/www/html/test/index.php:19 thrown in /var/www/html/test/vendor/phpunit/phpunit/src/Util/InvalidArgumentHelper.php on line 23
if I var_dump(Tester::class)
it outputs string(6) "Tester"
, so I know that Tester
class is valid.
It looks like PHPUnit is supposed to be run from command line. But I'm hoping I can run from a PHP script instead.