So I have a CodeIgniter project and I'm trying to use PHPUnit with it. My directory looks something like
所以我有一个CodeIgniter项目,我正在尝试使用PHPUnit。我的目录看起来像
application
node_modules
Gruntfile.js
scripts
vendor
tests
PostTest.php
phpunit.phar
bootstrap.php
phpunit.xml
composer.json
package.json
When I'm inside of the tests folder, I can do "phpunit ." or "php phpunit.phar ." to run the tests inside of PostTest.php and that works fine, but when I'm in the root folder, and try doing "phpunit tests", I get the error:
当我在测试文件夹里面时,我可以做“phpunit”。或者“php phpunit.phar”。在PostTest.php中运行测试并且工作正常,但是当我在根文件夹中并尝试执行“phpunit tests”时,我收到错误:
ERROR: Not Found
The controller/method pair you requested was not found.
PostTest.php
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
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>
Does anyone have any ideas why I'm getting that error?
有没有人有任何想法我为什么会收到这个错误?
1 个解决方案
#1
1
Phpunit looks in the current directory for phpunit.xml, and descends into directories to find test files. So move this file to webroot and you should be sorted. Alternatively, you could specify the directory for tests to run in in the phpunit.xml and leave it where it is and add something like this (untested) to get it to include tests in webroot:
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
https://phpunit.de/manual/current/en/appendixes.configuration.html
#1
1
Phpunit looks in the current directory for phpunit.xml, and descends into directories to find test files. So move this file to webroot and you should be sorted. Alternatively, you could specify the directory for tests to run in in the phpunit.xml and leave it where it is and add something like this (untested) to get it to include tests in webroot:
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
https://phpunit.de/manual/current/en/appendixes.configuration.html