2015-09-22 36 views
2

因此,我有一个CodeIgniter项目,我试图使用PHPUnit。我的目录看起来像无法在测试文件夹外运行PHPUnit

application 
node_modules 
Gruntfile.js 
scripts 
vendor 
tests 
    PostTest.php 
    phpunit.phar 
    bootstrap.php 
    phpunit.xml 
composer.json 
package.json 

当我在测试文件夹内,我可以做“phpunit”。或“php phpunit.phar”。运行测试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> 

没有人有任何想法,为什么我收到错误?

回答

1

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

+0

所以我试图将phpunit.xml移入根目录,当我这样做时,错误更改为'致命错误:调用/Applications/XAMPP/xamppfiles/htdocs/project/tests/PostTest.php中的未定义函数get_instance()在线7',我跑过这个错误之前,但我无法找出一个永久的解决方案。 – Jon

+0

@Jon - 刚刚意识到这是CodeIgniter,我对CI项目的设置一无所知,所以我不打算。 – markdwhite