We can use PHPUnit as a testing framework. But you will face an issue when you install it with Composer and try to use it in a common way.
This is because Yii2 has its own autoloader (Yii.php) that differs from the
Composer’s autoloader (vendor/autoload.php). So some classes won’t be
accessible, and we will need to handle it.
Another option is to use Codeception - another great testing framework.
Andrew Dorokhov