I am new to PHP, and I am going to add some unit test for existed code app\Common\PrintLoggerTool.php.
<?php
/**
* Created by PhpStorm.
* User: tong
* Date: 2021/1/8
* Time: 9:46
*/
namespace App\Common;
class PrintLoggerTool
{
public static function printLogger(string $method, $getMessage, $level = 1)
{
// Just some code of log, ignored.
}
}
Below is my test code, test\Cases\Common\PrintLoggerToolTest.php
<?php
declare(strict_types=1);
/**
* This file is part of Hyperf.
*
* @link https://www.hyperf.io
* @document https://hyperf.wiki
* @contact [email protected]
* @license https://github.com/hyperf/hyperf/blob/master/LICENSE
*/
namespace HyperfTest\Cases\Common;
use App\Common\PrintLoggerTool;
use PHPUnit\Framework\TestCase;
/**
* @internal
* @coversNothing
*/
class PrintLoggerToolTest extends TestCase
{
public function testDecrypt()
{
PrintLoggerTool::printLogger(__METHOD__, 'abc', 2);
}
}
But when I run the test code, I got:Error: Class "App\Common\PrintLoggerTool" not found.
And I can not run existed unit test either, for same error.
So I think there may be some "environment problem" on my computer.
I find something in composer.json
{
"autoload": {
"psr-4": {
"App\\": "app/"
},
"files": []
},
"autoload-dev": {
"psr-4": {
"HyperfTest\\": "./test/"
}
}
// other code ingored
}
So I think the "namespace" I use is right.