cvs: peardoc /ja/package/php/phpunit intro.xml run.xml testcase.xml /ja/package/php/phpunit/testcase intro.xml

From: Date: Wed, 20 Oct 2004 11:09:00 +0000
Subject: cvs: peardoc /ja/package/php/phpunit intro.xml run.xml testcase.xml /ja/package/php/phpunit/testcase intro.xml
Groups: php.pear.doc 
Request: Send a blank email to pear-doc+get-5005@lists.php.net to get a copy of this message
haruki Wed Oct 20 07:09:00 2004 EDT Added files: /peardoc/ja/package/php/phpunit/testcase intro.xml Modified files: /peardoc/ja/package/php/phpunit intro.xml run.xml testcase.xml Log: translate the remains

http://cvs.php.net/diff.php/peardoc/ja/package/php/phpunit/intro.xml?r1=1.2&r2=1.3&ty=u Index: peardoc/ja/package/php/phpunit/intro.xml diff -u peardoc/ja/package/php/phpunit/intro.xml:1.2 peardoc/ja/package/php/phpunit/intro.xml:1.3 --- peardoc/ja/package/php/phpunit/intro.xml:1.2 Wed Oct 22 11:18:32 2003 +++ peardoc/ja/package/php/phpunit/intro.xml Wed Oct 20 07:09:00 2004 @@ -1,160 +1,156 @@ <?xml encoding="utf-8" ?> -<!-- sync: 1.4 --> -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> +<!-- EN-Revision: 1.5 Maintainer: haruki Status: ready --> +<!-- CREDITS: hirokawa --> <refentry id="packages.php.phpunit.intro"> <refnamediv> <refname>チュートリアル</refname> <refpurpose> - PHPUnitに関する簡易チュートリアル + PHPUnit 簡易チュートリアル </refpurpose> </refnamediv> <refsect1> - <title>試験フレームワークの紹介</title> + <title>テストフレームワークの紹介</title> <para> - <classname>PHPUnit</classname>は、関数やクラスのテストを自動的に行 - うテストアプリケーションを作成する簡単な仕組みを提供します。 - PHPUnitは、<ulink url="&url.junit;">JUnit</ulink>からヒン - トを得ています。Kent BeckとErich Gammaが、 - <ulink url="&url.extreme.prog;">eXtreme Programming</ulink> - 用のツールとしてJUnitを作成しました。XPの要素の1つは、 - 小さなソフトウエアコンポーネントを可能な限り頻繁に、そして、早期に - 試験し、アプリケーション全体を設定、試験する際にAPIのバグやエラーを - を修正しないことです。 - PHPUnitから利益を得るためにXPに移行する必要はありません。 - PHPUnitは、クラスまたは関数の集まりをテストするための有効なツールで - あり、デバッグを際限なく続けることを避ける手助けとなります。 + <classname>PHPUnit</classname> は、関数やクラスを自動的にテストする + "テストスイート" を作成するためのシンプルなフレームワークを提供します。 + PHPUnit は、<ulink url="&url.junit;">JUnit</ulink> からヒントを得ています。 + JUnit は、Kent Beck と Erich Gamma が、 + <ulink url="&url.extreme.prog;">eXtreme Programming</ulink> (XP) + 用のツールとして作成したソフトウエアです。XP においては、 + 小さなソフトウエアコンポーネントを可能な限り早期に頻繁に試験すること、 + というルールが定められています。こうすることで、 + アプリケーション全体を設定し試験する際になってまで、コンポーネント内部のバグやエラーを + 修正する破目にならなくてすみます。ユニットテストと呼ばれるこういったコンポーネント毎の + テストは XP の基本原則のひとつですが、だからといって + PHPUnit を利用するために XP を実行しないといけない訳ではありません。 + PHPUnitは、単体として、クラスや関数をテストする有効なツールであり、 + 際限のないデバッグ作業を避けるのに有用です。 </para> </refsect1> <refsect1 id="packages.php.phpunit.intro.workroutine"> <title>実行手順</title> <para> - 通常、クラスを作成し、<function>echo</function> または - <function>var_dump</function> を用いてシステム化されていないいくつ - かのテストを行い、全てがうまく行くことを願います。PHPUnitによる恩恵 - を得るためには、この流れを再考する必要があります。最善の方法は、以 - 下のように行うことです。 + これまでに行われている良くあるテスト手順は、何らかのクラスを作成した後、 + <function>echo</function> や <function>var_dump</function> + を用いて非体系的にテストを行い、不具合が発生しないことを願う、という流れでしょう。 + PHPUnit を使って利益を得るためには、この流れを再考する必要があります。 + 最善の手順は、以下の通り行うことです。 <itemizedlist> <listitem> - <para>1. クラス/APIを設計</para> + <para>1. クラス/ API を設計</para> </listitem> <listitem> <para>2. テスト用ツールを作成</para> </listitem> <listitem> - <para>3. クラス/APIを実装</para> + <para>3. クラス/ API を実装</para> </listitem> <listitem> <para>4. テスト用ツールを実行</para> </listitem> <listitem> - <para>5. 失敗またはエラーを修正し、再度#4へ進む</para> + <para>5. 失敗またはエラーを修正し、再度 #4 へ進む</para> </listitem> </itemizedlist> - この手順は、多くの時間を必要とするように見えますが、この印象は誤り - です。PHPUnitを用いてテスト用ツールを作成するには数分しかかからず、 - テスト用ツールを実行するのには、数秒しかかかりません。 + この手順を踏むと時間が多く必要となるように見えますが、その印象は誤りです。 + PHPUnit を使ってテストスイートを作成するには数分しかかからず、 + テストスイートの実行にも、数秒しかかかりません。 </para> </refsect1> <refsect1 id="packages.php.phpunit.intro.design"> <title>クラスの設計</title> <para> - 簡単な例として、文字列処理クラスから始めてみましょう。まず、文字列 - 処理を行う一連の関数を関数の宣言を以下のように作成します。 + 簡単な例として、文字列を処理するクラスを取り上げます。 + まず、文字列処理を行う一連の関数の宣言を以下のように作成します。 <programlisting role="php"> <![CDATA[ ----- string.php ---- +//---- string.php ---- -<?php class String { - //contains the internal data + // 内部データを保持 var $data; - // constructor + // コンストラクタ function String($data) { $this->data = $data; } - // creates a deep copy of the string object + // 文字列オブジェクトのコピーを生成 function copy() { } - // adds another string object to this class + // 文字列をこのオブジェクトに付加 function add($string) { } - // returns the formated string + // フォーマット済み文字列を返す function toString($format) { } } -?> ]]> </programlisting> </para> </refsect1> <refsect1 id="packages.php.phpunit.intro.testsuite"> - <title>テスト用スーツの作成</title> + <title>テストスイートの作成</title> <para> - Now we can create a test suite, which checks every - function of your string class. A test suite is normal - PHP class inherited from <classname>PHPUnit_TestCase - </classname> containing test functions, - identified by a leading 'test' in the function name. - In the test function an expected value has to be compared - with the result of the function to test. - The result of this compare must delegate to a function - of the <function>assert*</function>-family, which decides - if a function pass or fail the test. + 次に、この文字列処理クラスの各関数をテストするテストスイートを作成します。 + テストスイートは、 <classname>PHPUnit_TestCase + </classname> を継承した通常の PHP クラスで、このクラス中に + 名称が 'test' で始まる "テスト関数" を定義していきます。 + テスト関数においては、テスト対象の関数の帰り値と + ありうべき正しい値との比較を行います。 + この比較は、<function>assert*</function> 系の関数を使って行い、 + テストに合格したかどうかの判断が行われます。 <programlisting role="php"> <![CDATA[ ----- testcase.php ---- - -<?php +//---- testcase.php ---- require_once 'string.php'; require_once 'PHPUnit.php'; class StringTest extends PHPUnit_TestCase { - // contains the object handle of the string class + // 文字列処理クラスのオブジェクト var $abc; - // constructor of the test suite + // このテストスイートのコンストラクタ function StringTest($name) { $this->PHPUnit_TestCase($name); } - // called before the test functions will be executed - // this function is defined in PHPUnit_TestCase and overwritten - // here + // テスト関数が実行される前にコールされる + // この関数は PHPUnit_TestCase にて定義されており、 + // ここでオーバーライドしている function setUp() { - // create a new instance of String with the - // string 'abc' + // 新しいインスタンスを文字列'abc'を設定して作成 $this->abc = new String("abc"); } - // called after the test functions are executed - // this function is defined in PHPUnit_TestCase and overwritten - // here + // テスト関数が実行された後にコールされる + // この関数は PHPUnit_TestCase にて定義されており、 + // ここでオーバーライドしている function tearDown() { - // delete your instance + // インスタンスの削除 unset($this->abc); } - // test the toString function + // toString 関数のテスト function testToString() { $result = $this->abc->toString('contains %s'); $expected = 'contains abc'; $this->assertTrue($result == $expected); } - // test the copy function + // copy 関数のテスト function testCopy() { $abc2 = $this->abc->copy(); $this->assertEquals($abc2, $this->abc); } - // test the add function + // add 関数のテスト function testAdd() { $abc2 = new String('123'); $this->abc->add($abc2); @@ -163,21 +159,18 @@ $this->assertTrue($result == $expected); } } -?> ]]> </programlisting> </para> </refsect1> <refsect1 id="packages.php.phpunit.intro.firstrun"> - <title>The first test run</title> + <title>テストの実行</title> <para> - Now, we can run a first test. Execute this PHP program. - Make sure that the paths are correct. + それでは、テストを実行してみましょう。 + パスが正しいか確認し、この PHP プログラムを実行してください。 <programlisting role="php"> <![CDATA[ ----- stringtest.php ---- - -<?php +//---- stringtest.php ---- require_once 'testcase.php'; require_once 'PHPUnit.php'; @@ -186,13 +179,11 @@ $result = PHPUnit::run($suite); echo $result -> toString(); -?> ]]> </programlisting> </para> <para> - If you call this script through commandline, you will get - this output: + コマンドラインで実行すると、以下の出力が得られます。 <programlisting> <![CDATA[ TestCase stringtest->testtostring() failed: expected true, actual false @@ -200,93 +191,94 @@ TestCase stringtest->testadd() failed: expected true, actual false ]]> </programlisting> - Every function fails the test, because your string functions - didn't returned what we defined as the expected value. + まだ実装が行われておらず、各文字列処理関数は正しい値を返しませんので、 + すべての関数がテストに不合格となります。 </para> <para> - If you want to call the script through your browser, you have to put - the script in a correct html page and call <function>$result->toHTML - </function> instead of <function>$result->toString</function>. + ブラウザから実行したい場合は、 + <function>$result->toString</function> を <function>$result->toHTML + </function> へ変更してください。HTML ページが出力されます。 </para> </refsect1> <refsect1 id="packages.php.phpunit.intro.implement"> - <title>Implementation</title> + <title>実装</title> <para> - Ok, let's start with implementation of the our string class. + 文字列処理クラスの実装を行いましょう。 <programlisting role="php"> <![CDATA[ ----- string.php ---- +//---- string.php ---- -<?php class String { - //contains the internal data + // 内部データを保持 var $data; - // constructor + // コンストラクタ function String($data) { $this->data = $data; } - // creates a deep copy of the string object + // 文字列オブジェクトのコピーを生成 function copy() { $ret = new String($this->data); return $ret; } - // adds another string object to this class + // 文字列をこのオブジェクトに付加 function add($string) { $this->data = $this->data.$string->toString("%ss"); } - // returns the formated string + // フォーマット済み文字列を返す function toString($format) { $ret = sprintf($format, $this->data); return $ret; } } -?> ]]> </programlisting> </para> <para> - Implementing is done and run the test again: + 実装が終了したら、テストを実行します。 <programlisting> ~> <command>php -f stringtest.php</command> TestCase stringtest->testtostring() passed TestCase stringtest->testcopy() passed TestCase stringtest->testadd() failed: expected true, actual false </programlisting> - D'oh! the last test failed! We did a typing mistake. Change - line 16 in <filename>string.php</filename> to + あれ、最後のテストが不合格です。タイプミスをしたようです。 + <filename>string.php</filename> の 16 行目を以下の様に修正します。 <programlisting role="php"> <![CDATA[ $this->data = $this->data.$string->toString("%s"); ]]> </programlisting> - and run the test again: + そして、テストを再実行します。 <programlisting> ~> <command>php -f stringtest.php</command> TestCase stringtest->testtostring() passed TestCase stringtest->testcopy() passed TestCase stringtest->testadd() passed </programlisting> - Everything is ok now! + すべて合格しました。 </para> </refsect1> <refsect1 id="packages.php.phpunit.intro.conclusion"> <title>まとめ</title> <para> - Hm, such a big expenditure for testing three simple - functions? Don't forget, this is a small example. - Think about bigger, complexer API's like database - abstraction or basket classes in a shop application. - PHPUnit is an excellent tool to detect errors in the - implementation. Maybe you have a big class used - in a few applications and you want to reimplement - the class. With a test suite, you can easily check - and fix the new implementation in a short session. + たった3つの単純な関数しかないクラスに対しては、大袈裟な手順かも知れません。 + しかし、上記は短い例に過ぎないのであって、オンラインショップの + ショッピングカートやデータベース抽象化クラスなどの、 + 大きくて複雑な API を持つクラスを考えて見てください。 + PHPUnit は、実装中に潜むバグを見つけるのに非常に有用なツールなのです。 + </para> + <para> + また、以前に使ったクラスの再実装をするような場合を考えると、 + テストスイート無しでは、そのクラスに依存するアプリケーションに + 不具合を発生させる可能性が高くなります。 + まずテストスイートを作成し、新しいクラスがテストにすべて合格するように保ったまま + 再実装を行っていけば、アプリケーションに不具合が起きる事はないでしょう。 </para> </refsect1> </refentry> http://cvs.php.net/diff.php/peardoc/ja/package/php/phpunit/run.xml?r1=1.2&r2=1.3&ty=u Index: peardoc/ja/package/php/phpunit/run.xml diff -u peardoc/ja/package/php/phpunit/run.xml:1.2 peardoc/ja/package/php/phpunit/run.xml:1.3 --- peardoc/ja/package/php/phpunit/run.xml:1.2 Wed Oct 22 11:18:32 2003 +++ peardoc/ja/package/php/phpunit/run.xml Wed Oct 20 07:09:00 2004 @@ -1,10 +1,11 @@ <?xml encoding="utf-8"?> -<!-- sync: 1.4 --> -<!-- $Revision: 1.2 $ --> +<!-- $Revision: 1.3 $ --> +<!-- EN-Revision: 1.4 Maintainer: haruki Status: ready --> +<!-- CREDITS: hirokawa --> <refentry id="package.php.phpunit.run"> <refnamediv> <refname>PHPUnit::run()</refname> - <refpurpose>TestSuiteを実行し、TestResultオブジェクトを返す</refpurpose> + <refpurpose>テストスイートを実行し、TestResult オブジェクトを返す</refpurpose> </refnamediv> <refsynopsisdiv> <funcsynopsis> @@ -22,7 +23,7 @@ <refsect1 id="package.php.phpunit.run.desc"> &title.desc; <para> - 指定したテストスーツを実行します。 + 指定したテストスイートを実行します。 </para> </refsect1> <refsect1 id="package.php.phpunit.run.parameter"> @@ -31,7 +32,7 @@ <itemizedlist> <listitem> <para> - <parameter>object $suite</parameter> - PHPUnit_TestSuiteのオブジェクト + <parameter>object $suite</parameter> - PHPUnit_TestSuite のオブジェクト <!-- <link linkend="package.phpunit.phpunit-testsuite"></link> --> </para> </listitem> @@ -41,7 +42,7 @@ <refsect1 id="package.categorie.mypackage.myfunction.return"> &title.returns; <para> - <parameter>&amp;PHPUnit_Result</parameter> - PHPUnit_Resultへのリファレンス。 + <parameter>&amp;PHPUnit_Result</parameter> - PHPUnit_Result へのリファレンス。 <!-- <link linkend="package.phpunit.phpunit-result">PHPUnit_Result</link>. --> </para> </refsect1> @@ -51,12 +52,10 @@ <title>Using <function>PHPUnit::run</function></title> <programlisting role="php"> <![CDATA[ -<?php require_once "PHPUnit.php"; $suite = New PHPUnit_TestSuite('Mathtest'); $result = PHPUnit::run($suite); echo $result->toHtml(); -?> ]]> </programlisting> </example> http://cvs.php.net/diff.php/peardoc/ja/package/php/phpunit/testcase.xml?r1=1.3&r2=1.4&ty=u Index: peardoc/ja/package/php/phpunit/testcase.xml diff -u peardoc/ja/package/php/phpunit/testcase.xml:1.3 peardoc/ja/package/php/phpunit/testcase.xml:1.4 --- peardoc/ja/package/php/phpunit/testcase.xml:1.3 Wed Oct 22 11:18:32 2003 +++ peardoc/ja/package/php/phpunit/testcase.xml Wed Oct 20 07:09:00 2004 @@ -1,29 +1,30 @@ <?xml encoding="utf-8" ?> -<!-- sync: 1.2 --> -<!-- $Revision: 1.3 $ --> +<!-- $Revision: 1.4 $ --> +<!-- EN-Revision: 1.2 Maintainer: haruki Status: ready --> +<!-- CREDITS: hirokawa --> <refentry id="package.php.phpunit.testcase"> <refnamediv> <refname><classname>TestCase</classname></refname> - <refpurpose>TestCase: 複数のテストを実行するための設備(fixture)を定義する</refpurpose> + <refpurpose>TestCase: 複数のテストを実行するための試験装置</refpurpose> </refnamediv> <refsect1 id="package.php.phpunit.testcase.desc"> &title.desc; <para> &class.testcase; - TestCaseを定義する手順: + TestCase を定義する手順: - 1) PHPUnit_TestCaseのサブクラスを実装します。 - 2) 設備の状態を保存するインスタンス変数を定義します。 - 3) setUp()をオーバーライドすることにより設備の状態を初期化します。 - 4) tearDown()を上書きすることによりテスト後の清掃を行います。 + 1) PHPUnit_TestCase のサブクラスを作ります + 2) 試験装置の状態を保存するクラス変数を定義します + 3) setUp() をオーバーライドすることにより試験装置の状態を初期化します + 4) tearDown() を上書きすることによりテスト後の後片付けを行います - 各テストは、各自の設備において実行されるため、テストの実行による副 - 作用はありません。 + 各テストは、各自の試験装置において実行されるため、テストの実行による + 副作用はありません。 </para> </refsect1> </refentry> - &package.php.phpunit.testcase.example; + <!-- &package.php.phpunit.testcase.example; --> &package.php.phpunit.testcase.counttestcases; <!-- Keep this comment at the end of the file Local variables: http://cvs.php.net/co.php/peardoc/ja/package/php/phpunit/testcase/intro.xml?r=1.1&p=1 Index: peardoc/ja/package/php/phpunit/testcase/intro.xml +++ peardoc/ja/package/php/phpunit/testcase/intro.xml <?xml encoding="utf-8" ?> <!-- $Revision: 1.1 $ --> <!-- EN-Revision: 1.3 Maintainer: haruki Status: ready --> <!-- CREDITS: hirokawa --> <refentry id="packages.php.phpunit.testcase.intro"> <refnamediv> <refname>PHPUnit::TestCase</refname> <refpurpose> TestCase: 複数のテストを実行するための試験装置の抽象化 </refpurpose> </refnamediv> <refsect1> <title>TestCase を定義する手順</title> <para> <itemizedlist> <listitem> <para>1) PHPUnit_TestCase のサブクラスを作ります</para> </listitem> <listitem> <para>2) クラス変数を定義し、そこに試験装置の状態を保存できるようにします</para> </listitem> <listitem> <para>3) setUp() をオーバーライドすることにより試験装置の状態を初期化します</para> </listitem> <listitem> <para>4) tearDown() を上書きすることによりテスト後の後片付けを行います</para> </listitem> </itemizedlist> 各テストは、別個の試験装置において実行されるため、テストの実行による 副作用はありません。 </para> </refsect1> <refsect1> <title>PHPUnit::TestCase</title> <para> <programlisting role="php"> <![CDATA[ class MathTest extends PHPUnit_TestCase { var $fValue1; var $fValue2; function MathTest($name) { $this->PHPUnit_TestCase($name); } function setUp() { $this->fValue1 = 2; $this->fValue2 = 3; } } ]]> </programlisting> </para> <para> 各テストにおいては、試験装置を利用してメソッドを実装します。 正しい値が返されたかどうかは、assert 関数に boolean を渡すことで 確認します。 </para> <para> <programlisting role="php"> <![CDATA[ function testPass() { $this->assertTrue($this->fValue1 + $this->fValue2 == 5); } ]]> </programlisting> </para> </refsect1> </refentry> <!-- Keep this comment at the end of the file Local variables: mode: sgml sgml-omittag:t sgml-shorttag:t sgml-minimize-attributes:nil sgml-always-quote-attributes:t sgml-indent-step:1 sgml-indent-data:t sgml-parent-document:nil sgml-default-dtd-file:"../../../../../manual.ced" sgml-exposed-tags:nil sgml-local-catalogs:nil sgml-local-ecat-files:nil End: vim600: syn=xml fen fdm=syntax fdl=2 si vim: et tw=78 syn=sgml vi: ts=1 sw=1 -->
« previous php.pear.doc (#5005) next »