2013-02-15 63 views
1

我需要從PHAR運行PHPUNit而不是從Pear運行。 我得到的唯一輸出是幫助文件。我沒有看到我的測試運行。這裏是我的代碼:PHPUnit從phar運行不起作用

<?php 
include 'phpunit.phar'; 
include 'phar://phpunit.phar/phpunit.php'; 

class ArrayTest extends PHPUnit_Framework_TestCase 
{ 

    public function setUp(){ } 
    public function tearDown(){ } 


    public function testNewArrayIsEmpty() 
    { 
     // Create the Array fixture. 
     $fixture = array(); 

     // Assert that the size of the Array fixture is 0. 
     $this->assertEquals(0, sizeof($fixture)); 
    } 

} 

而且我正在這樣的:

$ php index.php 

感謝

< < UPDATE >> 我跑在此之後:

$ php phpunit.phar index.php 

我得到了這個e rror:

Class 'index' could not be found in '/home/ericp/public_html/dev/_test/phpunit/index.php'. 

我修改了意外添加「../」改變路徑。我不知道爲什麼修復它,但它的工作原理。 我的index.php文件與我的phpunit.phar文件位於同一目錄中。 工作示例如下:

<?php 
include '../phpunit.phar'; 
include '../phar://phpunit.phar/phpunit.php'; 

class ArrayTest extends PHPUnit_Framework_TestCase 
{ 

    public function setUp(){ } 
    public function tearDown(){ } 

    public function testNewArrayIsEmpty() 
    { 
     // Create the Array fixture. 
     $fixture = array(); 

     // Assert that the size of the Array fixture is 0. 
     $this->assertEquals(0, sizeof($fixture)); 
     $this->assertEmpty($fixture); 
    } 

} 

回答

1

我不能完全肯定使用的PHPUnit的的Phar,但儘量在命令行中執行以下操作:

php phpunit.phar index.php 

我認爲PHPUnit的是閱讀查找要運行的測試。

或者,您可以嘗試在該目錄中創建phpunit.xml.dist文件,並僅運行phpunit,應該這樣做。

如上所述,我不知道Phars

+1

謝謝。這工作來運行它。但我碰到另一個問題,給了我這個錯誤:「類'索引'無法找到'/home/ericp/public_html/dev/_test/phpunit/index.php'」。我想通了,並會修復我的問題。 – EricP 2013-02-15 15:36:14

+0

sry,忘了提及。 PHPUnit也期望包含的類名與文件名匹配。嘗試將'index.php'重命名爲'ArrayTest.php'。 – 2013-02-15 19:54:21

+0

@EricP,什麼是修復? – Pacerier 2015-08-11 09:26:03