测试

oil test(或 oil t)命令运行與你的 web app、模組和套件相關的 PHPUnit 测试。關於 FuelPHP 单元测试的完整文件可以在 单元测试 文件頁面找到,而關於 PHPUnit 的完整文件可以在 PHPUnit 網站找到。

配置

Oil 實用工具本身不需要太多配置,但如果在你機器上的 PHPUnit 實例不是全域安装(例如,如果你使用 Composer 安装 PHPUnit 到你的專案),你会想要配置 Oil 來解決你的 PHPUnit 安装。在 app/config/oil.php 建立(或從 Oil 套件複製)一个配置档案,并根據需要變更这些設定:

PHPUnit 配置

參数 类型 預設 描述
phpunit.autoload_path 字串
'PHPUnit/Autoload.php'
指向 PHPUnit Autoload 档案的路徑。
phpunit.binary_path 字串
'phpunit'
这是运行 PHPUnit 命令(如果需要的話,包含完整路徑)的可执行文件。

命令列選項

测试支援幾个 PHPUnit 命令列選項:

--file=<file> 只在指定的档案运行测试。

--group=<group> 只在指定的群組(們)运行测试。

--testsuite=<testsuite> 只运行指定测试套裝(們)的测试。

--exclude-group=<group> 從指定的群組(們)排除测试。

--coverage-clover=<file> 產生 Clover XML 格式的程式码覆蓋率報告。

--coverage-html=<dir> 產生 HTML 格式的程式码覆蓋率報告。

--coverage-php=<file> 序列化 PHP_CodeCoverage 物件到档案。

--coverage-text=<file> 產生文本格式的程式码覆蓋率報告。

--log-junit=<file> 產生执行在 JUnit XML 格式的测试報告到档案。

--debug 在测试执行過程顯示除错資訊。

更多關於这些命令列選項以及它們所处理的資訊,請見 PHPUnit 文件

PHPUnit 测试运行配置

預設情況下,Oil 将傳遞位於 COREPATH 目录中的 phpunit.xml 测试运行配置档案給 PHPUnit。

Fuel 在 fuel/core/phpunit.xml 的基本 phpunit.xml 包含:

<?xml version="1.0" encoding="UTF-8"?>
<phpunit colors="true" stopOnFailure="false" bootstrap="../core/bootstrap_phpunit.php">
	<php>
		<server name="doc_root" value="../../"/>
		<server name="app_path" value="fuel/app"/>
		<server name="core_path" value="fuel/core"/>
		<server name="package_path" value="fuel/packages"/>
	</php>
	<testsuites>
		<testsuite name="core">
			<directory suffix=".php">../core/tests</directory>
		</testsuite>
		<testsuite name="packages">
			<directory suffix=".php">../packages/*/tests</directory>
		</testsuite>
		<testsuite name="app">
			<directory suffix=".php">../app/tests</directory>
		</testsuite>
	</testsuites>
</phpunit>

如果你需要更改这个配置档案,将它複製到你的 APPPATH 目录并编輯它。Oil 才能夠識別代替預設的新配置档案,并使用你自訂的配置。

例如,如果你在 Modules 开发,你可能需要以下額外的测试組在你自訂的测试配置档案:

		<testsuite name="modules">
			<directory suffix=".php">../modules/*/tests</directory>
		</testsuite>