PHPUnit测试套件包含路径
使用phpunit,我在包含路径方面遇到了一些问题,不是phpunit本身,而是我的代码和测试目录 我有以下代码结构:PHPUnit测试套件包含路径,php,unit-testing,phpunit,Php,Unit Testing,Phpunit,使用phpunit,我在包含路径方面遇到了一些问题,不是phpunit本身,而是我的代码和测试目录 我有以下代码结构: Application -StringCalculator.php tests -StringCalculatorTest.php 在我的StringCalculatorTest.php中,我有一个require语句: require_once('../StringCalculator.php'); 从tests文件夹中运行phpunit-StringCalcul
Application
-StringCalculator.php
tests
-StringCalculatorTest.php
在我的StringCalculatorTest.php中,我有一个require语句:
require_once('../StringCalculator.php');
从tests文件夹中运行phpunit-StringCalculatorTest.php
非常有效
但是,当我随后在根目录中引入phpunit.xml配置文件时
Application
-StringCalculator.php
tests
-StringCalculatorTest.php
phpunit.xml
包含路径已拧紧。我必须换一次新的
require_once('StringCalculator.php');
在应用程序和测试目录之间设置包含路径的正确方法是什么?设置PHP包含路径的最佳位置是在引导文件中。通常,您的
phpunit.xml
文件将包含一个引导属性:
<phpunit backupGlobals="true"
backupStaticAttributes="false"
bootstrap="bootstrap.php"
cacheTokens="true"
colors="true"
... and so on ...
</phpunit>
配置文件包含在PHPunit文档的部分中
编辑:链接已更新首先,我不知道
如何要求一次('../StringCalculator.php')代码>工作,它应该是:require_once('../Application/StringCalculator.php')代码>
然后,slashingweapon答案很好,这是最好的IMO,但是如果您不想那么麻烦,您可以指定您的require\u once
从当前文件的目录开始:
require_once(__DIR__ . '../Application/StringCalculator.php');
我知道问题已经得到了回答
这个答案是给未来的访客的
根据phpunit文档,您可以在phpunit.xml
中使用includePath
指令作为包含路径
<php>
<includePath>/path/to/ur/project</includePath>
</php>
/路径/目的地/市区/项目
<php>
<includePath>/path/to/ur/project</includePath>
</php>