2013-02-15 69 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