1

我需要从 PHAR 而不是 Pear 运行 PHPUNIt。我得到的唯一输出是帮助文件。我根本看不到我的测试运行。这是我的代码:

<?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

我收到了这个错误:

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);
    }

}
4

1 回答 1

1

我不确定是否使用 PHPUnit 的 Phar,但请在命令行上尝试以下操作:

php phpunit.phar index.php

我假设 PHPUnit 正在阅读$argv以查找要运行的测试。

或者,您可以尝试在目录中创建一个phpunit.xml.dist文件,然后简单地运行phpunit,这应该可以。

如前所述,我对Phars一无所知

于 2013-02-15T14:27:50.627 回答