Of course first phpunit/phpunit to be installed. I think, local installation much better.
composer require --dev phpunit/phpunit ^7
# phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Unit">
<directory suffix="Test.php">./tests</directory>
</testsuite>
</testsuites>
<filter>
<whitelist processUncoveredFilesFromWhitelist="true">
<directory suffix=".php">./src</directory>
</whitelist>
</filter>
</phpunit>
# ExampleTest.php, this file must be under tests folder.
(root/tests/ExampleTest.php)
?php
namespace yourvendorname\yourpackagename;
use PHPUnit\Framework\TestCase;
/**
* Description of ExampleTest
*
* @author Koray Zorluoglu <koray@d8devs.com>
*/
class ExampleTest extends TestCase
{
public function testExampleMethod()
{
$count = 0;
$this->assertSame(0, $count);
}
}
# Run on Command prompt.
./vendor/bin/phpunit
# Example Output
$ ./vendor/bin/phpunit PHPUnit 7.4.5 by Sebastian Bergmann and contributors. .... 4 / 4 (100%) Time: 968 ms, Memory: 4.00MB OK (4 tests, 4 assertions)
Views: 2