gpt4 book ai didi

PHPUnit 不读取配置文件?

转载 作者:行者123 更新时间:2023-12-04 14:25:56 27 4
gpt4 key购买 nike

我想用 composer 安装 PHPUnit 并按照本教程进行操作:https://jtreminio.com/2013/03/unit-testing-tutorial-introduction-to-phpunit/

我加了

{
"require-dev": {
"phpunit/phpunit": "3.7.14"
},
"autoload": {
psr-0": {
"phpUnitTutorial": ""
}
}
}

到文件 composer.json .进入 ./vendor/bin/phpunit向我显示 phpunit 已安装。

这是我的文件夹结构:
composer.json
composer.phar
phpUnitTutorial/
vendor/

我创建了一个 phpunit.xml phpUnitTutorial 内的文件包含内容的文件夹
<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./phpUnitTutorial/Test/</directory>
</testsuite>
</testsuites>
</phpunit>

此外,我在 phpUnitTutorial/Test/StupidTest.php 创建了一个文件与内容
<?php

namespace phpUnitTutorial\Test;

class StupidTest extends \PHPUnit_Framework_TestCase
{
public function testTrueIsTrue(){
$foo = ture;
$this->assertTrue($foo);
}
}

在教程中,建议执行以下操作:

From project root, run PHPUnit: $ vendor/bin/phpunit



使用以下屏幕截图:

enter image description here

如果我执行 $ vendor/bin/phpunitphpUnitTutorial文件夹然后我收到错误

bash: vendor/bin/phpunit: No such file or directory



这对我来说很有意义,因为文件夹 vendor与文件夹 phpUnitTutorial 处于同一级别.如果我执行 $ ../vendor/bin/phpunit我得到

enter image description here

它说没有执行任何测试,也没有确认我的配置文件已被读取。为什么不执行测试?

最佳答案

一、phpunit.xml文件应该在根文件夹 /bin/然后命令 $ vendor/bin/phpunit将工作,测试将实际执行。

其次,您需要更改文件 StupidTest.php
线

class StupidTest extends \PHPUnit_Framework_TestCase


class StupidTest extends \PHPUnit\Framework\TestCase

https://stackoverflow.com/a/42561590/2311074

关于PHPUnit 不读取配置文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44327318/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com