| Prev | Next |
この章では、まず継続的インテグレーションという技法の概要について述べ、 それを PHPUnit にどのように適用するかを説明していきます。
Continuous Integration is a software development practice where members of a team integrate their work frequently, usually each person integrates at least daily, leading to multiple integrations per day. Each integration is verified by an automated build (including test) to detect integration errors as quickly as possible. Many teams find that this approach leads to significantly reduced integration problems and allows a team to develop cohesive software more rapidly. 継続的インテグレーション というソフトウェア開発手法は、チームのメンバーどうしが お互いの開発内容を頻繁に結合させるというものだ、通常は、 最低でも一日に一度、あるいは場合によっては一日に何度もこれを行う。 結合の際には自動ビルド (テストを含む) を行い、 エラーはできるだけ早い段階で検出する。 多くのチームが、この手法によって結合時の問題を激減させている。 また、ソフトウェアをより高速に開発できるようにもなっている。 | ||
| --Martin Fowler | ||
継続的インテグレーションでは、テストを含めたビルド手順を 完全に自動化して何度でも実行できるようにしておく必要があります。 これは、一日に何度も実行されます。 各開発者は、この仕組みによって結合を行い、結合時の問題を減らします。 cronjob を使用して自動化を実現することもできます。まずプロジェクトの ソースコードリポジトリ から定期的に最新版をチェックアウトし、 テストを実行し、その結果を利用しやすい形式で出力するというジョブを作成すればよいのです。 ただ、もう少しましなやりかたもありそうです。
Atlassian Bamboo は継続的インテグレーション (Continuous Integration: CI) サーバで、 ソフトウェア開発チームを支援するための機能を提供します。 自動化されたビルド、ソフトウェアのソースコードの状態のテスト、 ビルドが成功したか失敗したかの判定、統計解析データの出力といった機能があります。
次の例では、Bamboo の配布アーカイブが
/usr/local/Bamboo.
に展開されたことを想定しています。
cd /usr/local/Bamboowebapp/WEB-INF/classes/bamboo-init.properties ファイルを編集します。
オプションで bamboo-checkstyle プラグインをインストールします。
./bamboo.sh starthttp://localhost:8085/ をブラウザで開きます。インストールガイドの指示に従います。
Apache Ant を管理パネル内で Builder として設定します。
これで、Bamboo の設定が完了し、プロジェクトのプランを用意できるようになりました。
しかしながら、まずはプロジェクトが必要です。この例では、PHPUnit に同梱されている
Money サンプルのコピーが Subversion リポジトリ
(file:///var/svn/money) にあるものとします。
*.php ファイル群とともに、次のような
Apache Ant ビルドスクリプト (build.xml)
もリポジトリに置きます。
例 21.2: build.xml
<project name="Money" default="build">
<target name="clean">
<delete dir="${basedir}/build"/>
</target>
<target name="prepare">
<mkdir dir="${basedir}/build"/>
<mkdir dir="${basedir}/build/logs"/>
</target>
<target name="phpcs">
<exec dir="${basedir}"
executable="phpcs"
output="${basedir}/build/logs/checkstyle.xml"
failonerror="false">
<arg line="--report=checkstyle ." />
</exec>
</target>
<target name="phpunit">
<exec dir="${basedir}" executable="phpunit" failonerror="true">
<arg line="--log-xml ${basedir}/build/logs/phpunit.xml
--coverage-clover ${basedir}/build/logs/clover.xml
--coverage-html ${basedir}/build/coverage
MoneyTest" />
</exec>
</target>
<target name="build" depends="clean,prepare,phpcs,phpunit"/>
</project>これでプロジェクトができあがりました。Bamboo でプランを作成してみましょう。
http://localhost:8080/ をブラウザで開きます。"Create a Plan" を選び、指示に従います。
"Create a Plan" のステップ 3 で "The build will produce test results" と "Clover output will be produced" をチェックし、PHPUnit が作成した XML ファイルのパスを指定します。
bamboo-checkstyle プラグインをインストールした場合は "CheckStyle output will be produced" もチェックし、PHP_CodeSniffer が作成した XML ファイルのパスを指定します。
"Create a Plan" のステップ 5 で、PHPUnit が作成する HTML ファイルを設定します。
CruiseControl は継続的ビルドプロセス用のフレームワークです。それだけではなく、 メールでの通知や Apache Ant との統合、 またさまざまなバージョン管理ツールとの統合のためのプラグインが用意されています。 またウェブインターフェイスも用意されており、 最新のビルドおよび以前のビルドについての詳細を見ることができます。
次の例では、CruiseControl が
/usr/local/cruisecontrol
にインストールされていることを想定しています。
cd /usr/local/cruisecontrolmkdir -p projects/Money/build/logscd projects/Moneyfile:///var/svn/money sourcebuild.xml ファイルを編集します。例 21.3: projects/Money/build.xml
<project name="Money" default="build" basedir=".">
<target name="checkout">
<exec dir="${basedir}/source/" executable="svn">
<arg line="up"/>
</exec>
</target>
<target name="test">
<exec dir="${basedir}/source" executable="phpunit" failonerror="true">
<arg line="--log-xml ${basedir}/build/logs/phpunit.xml MoneyTest"/>
</exec>
</target>
<target name="build" depends="checkout,test"/>
</project>cd /usr/local/cruisecontrolconfig.xml ファイルを編集します。例 21.4: config.xml
<cruisecontrol>
<project name="Money" buildafterfailed="false">
<plugin
name="svnbootstrapper"
classname="net.sourceforge.cruisecontrol.bootstrappers.SVNBootstrapper"/>
<plugin
name="svn"
classname="net.sourceforge.cruisecontrol.sourcecontrols.SVN"/>
<listeners>
<currentbuildstatuslistener file="logs/${project.name}/status.txt"/>
</listeners>
<bootstrappers>
<svnbootstrapper localWorkingCopy="projects/${project.name}/source/"/>
</bootstrappers>
<modificationset>
<svn localWorkingCopy="projects/${project.name}/source/"/>
</modificationset>
<schedule interval="300">
<ant
anthome="apache-ant-1.7.0"
buildfile="projects/${project.name}/build.xml"/>
</schedule>
<log dir="logs/${project.name}">
<merge dir="projects/${project.name}/build/logs/"/>
</log>
<publishers>
<currentbuildstatuspublisher
file="logs/${project.name}/buildstatus.txt"/>
<email
mailhost="localhost"
buildresultsurl="http://cruise.example.com/buildresults/${project.name}"
skipusers="true"
spamwhilebroken="true"
returnaddress="project@example.com">
<failure address="dev@lists.example.com" reportWhenFixed="true"/>
</email>
</publishers>
</project>
</cruisecontrol>これで CruiseControl サーバを(再)起動できるようになります。
./cruisecontrol.shhttp://localhost:8080/ をブラウザで開きます。
phpUnderControl は
CruiseControl の拡張で、さまざまな PHP 開発ツール、たとえばテスト用の
PHPUnit や
静的コード解析用の
PHP_CodeSniffer、
そして API
ドキュメントの生成用の
PHPDocumentor
を統合します。強力なコマンドラインツールも付属しており、あなたのプロジェクト用に
CruiseControl の XML 設定ファイルを自動生成させることもできます。
次の例では、CruiseControl が
/usr/local/cruisecontrol
にインストールされていることを想定しています。
pear install --alldeps phpunit/phpUnderControlphpuc install /usr/local/cruisecontrolphpuc project --version-control svn
--version-control-url file:///var/svn/money
--test-case MoneyTest
--test-file MoneyTest.php
--test-dir .
--project-name Money
/usr/local/cruisecontrol
上のコマンドは、まずプロジェクトのディレクトリとそのプロジェクト用の設定ファイル
build.xml を作成し、ソースリポジトリから初期チェックアウトを行い、
その新しいプロジェクトをグローバル設定ファイル
config.xml に追加します。
これで CruiseControl サーバを(再)起動できるようになります。
cd /usr/local/cruisecontrol./cruisecontrol.shhttp://localhost:8080/ をブラウザで開きます。| Prev | Next |
assertArrayHasKey()assertClassHasAttribute()assertClassHasStaticAttribute()assertContains()assertContainsOnly()assertEqualXMLStructure()assertEquals()assertFalse()assertFileEquals()assertFileExists()assertGreaterThan()assertGreaterThanOrEqual()assertLessThan()assertLessThanOrEqual()assertNull()assertObjectHasAttribute()assertRegExp()assertSame()assertSelectCount()assertSelectEquals()assertSelectRegExp()assertStringEndsWith()assertStringEqualsFile()assertStringStartsWith()assertTag()assertThat()assertTrue()assertType()assertXmlFileEqualsXmlFile()assertXmlStringEqualsXmlFile()assertXmlStringEqualsXmlString()Copyright © 2005-2010 Sebastian Bergmann.