Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unit testing phing和phpunit+;独自创立_Unit Testing_Zend Framework_Testing_Phpunit_Phing - Fatal编程技术网

Unit testing phing和phpunit+;独自创立

Unit testing phing和phpunit+;独自创立,unit-testing,zend-framework,testing,phpunit,phing,Unit Testing,Zend Framework,Testing,Phpunit,Phing,如何使用phing的引导文件运行PHPUnit测试套件 我的应用程序结构: application/ library/ tests/ application/ library/ bootstrap.php phpunit.xml build.xml phpunit.xml: <phpunit bootstrap="./bootstrap.php" colors="true"> <testsuite name="Application Test Suit

如何使用phing的引导文件运行PHPUnit测试套件

我的应用程序结构:

application/
library/
tests/
  application/
  library/
  bootstrap.php
  phpunit.xml
build.xml
phpunit.xml:

<phpunit bootstrap="./bootstrap.php" colors="true">
    <testsuite name="Application Test Suite">
        <directory>./</directory>
    </testsuite>
    <filter>
        <whitelist>
            <directory
              suffix=".php">../library/</directory>
            <directory
              suffix=".php">../application/</directory>
            <exclude>
                <directory
                  suffix=".phtml">../application/</directory>
            </exclude>
        </whitelist>
    </filter>
</phpunit>
但是如何从
/path/to/app/
目录运行测试?问题是,
bootstrap.php
依赖于库和应用程序的相对路径

如果我运行
phpunit--configuration tests/phpunit.xml/tests
我会得到一堆文件未找到的错误


如何为
phing
编写
build.xml
文件,以与
phpunit.xml
相同的方式运行测试?

我认为最好的方法是创建一个小PHP脚本来初始化单元测试,我正在做以下工作:

在my phpunit.xml/bootstrap=“./initalize.php”中

initalize.php

define('BASE_PATH', realpath(dirname(__FILE__) . '/../'));
define('APPLICATION_PATH', BASE_PATH . '/application');

// Include path
set_include_path(
    '.'
    . PATH_SEPARATOR . BASE_PATH . '/library'
    . PATH_SEPARATOR . get_include_path()
);

// Define application environment
define('APPLICATION_ENV', 'testing');
require_once 'BaseTest.php';
abstract class BaseTest extends Zend_Test_PHPUnit_ControllerTestCase
{

/**
 * Application
 *
 * @var Zend_Application
 */
public $application;

/**
 * SetUp for Unit tests
 *
 * @return void
 */
public function setUp()
{
    $session = new Zend_Session_Namespace();
    $this->application = new Zend_Application(
                    APPLICATION_ENV,
                    APPLICATION_PATH . '/configs/application.ini'
    );

    $this->bootstrap = array($this, 'appBootstrap');

    Zend_Session::$_unitTestEnabled;

    parent::setUp();
}

/**
 * Bootstrap
 *
 * @return void
 */
public function appBootstrap()
{
    $this->application->bootstrap();
}
}
BaseTest.php

define('BASE_PATH', realpath(dirname(__FILE__) . '/../'));
define('APPLICATION_PATH', BASE_PATH . '/application');

// Include path
set_include_path(
    '.'
    . PATH_SEPARATOR . BASE_PATH . '/library'
    . PATH_SEPARATOR . get_include_path()
);

// Define application environment
define('APPLICATION_ENV', 'testing');
require_once 'BaseTest.php';
abstract class BaseTest extends Zend_Test_PHPUnit_ControllerTestCase
{

/**
 * Application
 *
 * @var Zend_Application
 */
public $application;

/**
 * SetUp for Unit tests
 *
 * @return void
 */
public function setUp()
{
    $session = new Zend_Session_Namespace();
    $this->application = new Zend_Application(
                    APPLICATION_ENV,
                    APPLICATION_PATH . '/configs/application.ini'
    );

    $this->bootstrap = array($this, 'appBootstrap');

    Zend_Session::$_unitTestEnabled;

    parent::setUp();
}

/**
 * Bootstrap
 *
 * @return void
 */
public function appBootstrap()
{
    $this->application->bootstrap();
}
}

我所有的单元测试都在扩展BaseTest类,它的工作方式很有魅力。

当您在Phing中使用PHPUnit任务时,您可以包括如下引导文件:

<target name="test">
    <phpunit bootstrap="tests/bootstrap.php">
        <formatter type="summary" usefile="false" />
        <batchtest>
            <fileset dir="tests">
                <include name="**/*Test.php"/>
            </fileset>
        </batchtest>
    </phpunit> 
</target> 


谢谢。这或多或少是我的
bootstrap.php
。我的问题是,我不知道我可以用这种方式在phing中指定引导参数:
phpunit--bootstrap tests/bootstrap.php--configuration tests/phpunit.xml
不幸的是,在phing中以这种方式调用phpunit时不能使用phpunit.xml。