我可以从PHP脚本运行PHPUnit测试吗?

时间:2019-07-06 21:22:19

标签: php unit-testing phpunit

我发现this answer没有成功。

我尝试过

public class CustomAuthenticationData extends UsernamePasswordAuthenticationToken {

    private final Map<String, Object> attributes;

    public CustomAuthenticationData(String username, Map<String, Object> attributes, Collection<? extends GrantedAuthority> authorities) {
        super(username, "N/A", authorities);
        this.attributes = attributes;
    }

    public Map<String, Object> getAttributes() {
        return attributes;
    }
}

我得到了void writePage(uint16_t address, uint64_t *data, uint8_t const len, uint8_t const bPD) { uint8_t pageBuffer[32]; uint8_t bytes2Write = len * bPD; for (uint8_t dataIndex = 0; dataIndex < len; dataIndex++) { std::cout << int(dataIndex) << std::endl; std::cout << data[dataIndex] << std::endl; for (uint8_t i = 0; i < bPD; i++) { pageBuffer[i + (dataIndex * bPD)] = ((data[dataIndex] >> 8 * i) & 0xFF); std::cout << int(pageBuffer[i + (dataIndex * bPD)]) << std::endl << std::endl; } } } int main() { uint8_t array[3] = { 255, 20, 30 }; std::cout << int(array[0]) << int(array[1]) << int(array[2]) << std::endl; writePage(0, (uint64_t*)array, 3, 1); getch(); return 0; } 的错误,因此我将该行从$test = new \PHPUnit\Framework\TestSuite(); $test->addTestSuite(Tester::class); $result = $test->run(); 更改为使用index '_SERVER' is undefined on line 26 of (PHPUnit\Util\Filter file);

现在我得到了错误:

  

致命错误:未捕获PHPUnit \ Framework \ Exception:参数1(否   Value)的PHPUnit \ Framework \ TestSuite :: addTestSuite()必须是一个类   名称或对象/var/www/html/test/index.php:19抛出   /var/www/html/test/vendor/phpunit/phpunit/src/Util/InvalidArgumentHelper.php,第23行

如果我$GLOBALS['_SERVER']['SCRIPT_NAME']输出$_SERVER['SCRIPT_NAME'],那么我知道var_dump(Tester::class)类是有效的。


看起来PHPUnit应该从命令行运行。但我希望我可以改用PHP脚本运行。

0 个答案:

没有答案