2015-09-22 35 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