所以我有一个CodeIgniter项目,我试图使用PHPUnit与它。我的目录看起来像
application
node_modules
Gruntfile.js
scripts
vendor
tests
PostTest.php
phpunit.phar
bootstrap.php
phpunit.xml
composer.json
package.json
当我在测试文件夹内时,我可以执行"phpunit ."或"php phpunit. "在PostTest.php中运行测试,这很好,但是当我在根文件夹中,并尝试做"phpunit测试"时,我得到错误:
ERROR: Not Found
The controller/method pair you requested was not found.
PostTest.php
<?php
class PostTest extends PHPUnit_Framework_TestCase {
private $CI;
public function setUp() {
$this->CI = &get_instance();
}
public function testNotes() {
$this->CI->load->model('class');
$students = $this->CI->class->getStudents('11');
$this->assertEquals(3, count($students->result_array()));
}
}
phpunit.xml
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
verbose="true">
</phpunit>
有人知道为什么我得到这个错误吗?
Phpunit在当前目录中查找Phpunit .xml,并下降到目录中查找测试文件。因此,将该文件移动到webroot,您应该排序。或者,您可以在phpunit.xml中指定测试运行的目录,并将其保留在原处,并添加如下内容(未测试)以使其包含webroot中的测试:
<testsuites>
<testsuite name="My Test Suite">
<directory suffix="Test.php">../</directory>
</testsuite>
</testsuites>
https://phpunit.de/manual/current/en/appendixes.configuration.html