找不到PHPunit名称空间类

时间:2018-08-18 07:24:35

标签: php namespaces phpunit

我使用phpunit测试我的代码

并使用名称空间,但是在运行命令行时出现错误

Code.php:

<?php
namespace Check;

class Code {
    private $code;

    public function set($code){
        $this->ensureIsValidCode($code);
        $this->code = $code;

        return $this->code;
    }

    private function ensureIsValidCode($code) {
        if(!is_numeric($code) || strlen($code) != 5) {
            echo "Not valid code : ".$code.PHP_EOL;
            exit();
        }
    }
}
?>

CodeTest.php

<?php
use PHPUnit\Framework\TestCase;
use Check\Code as Code;

final class CodeTest extends TestCase {
    public function testSet(){
        $random = 34211;
        $code = new Code();
        $res = $code->set($random);

        $this->assertEquals($res, 34211);
    }
}
?>

错误:

1) CodeTest::testSet
Error: Class 'Check\Code' not found

命令行:

./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/CodeTest

但是我使用了require文件,工作正常

0 个答案:

没有答案