$_SERVER['DOCUMENT_ROOT']
Bootstrapファイルにも設定でき、同じ属性名でBootstrap_test.php
phpunit構成ファイルに添付されますphpunit.xml
bootstrap=Bootstrap_test.php
Jenkins ジョブ構成に $_SERVER['DOCUMENT_ROOT'] を設定するという要件を達成できました。「Bootstrap_test.php」は次のようになります
<phpunit
backupGlobals="false"
backupStaticAttributes="false"
strict="true"
verbose="true"
bootstrap="Bootstrap_test.php">
<testsuites>
<testsuite name="PHPUnit Test Suite">
<file>PHPUnitTest.php</file>
</testsuite>
</testsuites>
<logging>
<log type="coverage-clover" target="logs/clover.xml"/>
</logging>
</phpunit>
の内容は関数Bootstrap.php
を使用して宣言されます。define()
define('BASE_PATH', realpath(dirname(__FILE__)));
$_SERVER['DOCUMENT_ROOT'] = BASE_PATH;
このBASE_PATH
変数は通常、Jenkins ジョブ ディレクトリへのフル パスを保持します。たとえば、Jenkins のジョブ名はTest_Job
. Jenkins がプロジェクトのソース コードを配置するディレクトリは/var/lib/jenkins/jobs/Test_Job/workspace
(jenkins の作業ディレクトリを と仮定すると/var/lib/jenkins
) です。
Bootstrap_test.php がベースディレクトリに配置されている場合、BASE_PATH
が保持/var/lib/jenkins/jobs/Test_Job/workspace
され、最終的に に設定され$_SERVER['DOCUMENT_ROOT']
ます。