我已经阅读了与此问题相关的其他问题。但似乎建议的答案无法解决我的问题。
我的项目目录结构:
app/models/User.php
tests/UserTest.php
vendor/
composer.json
composer.lock
phpunit.xml
composer.json
{
"require": {
"phpunit/phpunit": "^6.5"
},
"autoload":{
"psr-4":{
"App\\": "app/"
}
}
}
phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
bootstrap="vendor/autoload.php"
colors="true"
stopOnFailure="false"
verbose="true">
<testsuites>
<testsuite name="User Test">
<directory>tests</directory>
</testsuite>
</testsuites>
</phpunit>
user.php的
namespace App\Models;
class User{
public $firstname;
public function setFirstName($firstname){
$this->firstname = $firstname;
}
}
UserTest.php
use PHPUnit\Framework\TestCase;
use App\Models\User;
class UserTest extends TestCase{
public function testTrue(){
$user = new User();
$this->assertTrue(false);
}
}
我正在执行此示例测试,但我一直在:
Error: Class 'App\Models\User' not found
如何在此特定设置中正确测试用户类?