Note: phpunit9 doesn't support php8^, it compatible with php7.4
- clone the repo: https://github.com/pcreem/psr-4Autoload
- install phpunit
$composer require --dev phpunit/phpunit ^9
$./vendor/bin/phpunit --version
PHPUnit 9.0.0 by Sebastian Bergmann and contributors.
-
$code composer.json
{
"autoload": {
"psr-4": {
"App\\":"App/"
}
},
"require-dev": {
"phpunit/phpunit": "^9"
}
}
-
$code App/Data/Database.php
<?php
namespace App\Data;
class Database {
public function sayHi()
{
return 'create database\n';
}
}
-
$code tests/DatabaseTest.php
<?php declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use App\Data\Database;
final class DatabaseTest extends TestCase
{
public function testCanCreateDatabase(): void
{
$database = new Database();
$this->assertSame('create database\n', $database->sayHi());
}
}
$./vendor/bin/phpunit --testdox tests
output
PHPUnit 9.5.4 by Sebastian Bergmann and contributors.
Database
β Can create database
the init
Time: 00:00.006, Memory: 4.00 MB
OK (1 test, 1 assertion)
Top comments (0)