説明
S2Baseの新しいコマンドを作成します。作成したコマンドは、コマンドリストに表示されます。
実行例
s2base.php5 ディレクトリで phing を実行します。
% phing
Buildfile: /seasar.php/workspace/s2base.php5/build.xml
project > prepare:
[php] Evaluating PHP expression: require_once('config/environment.inc.php')
[php] Evaluating PHP expression: require_once('lib/S2Base/S2Base.cmd.php')
project > com:
[ Command list ]
0 : (exit)
1 : command
2 : dao
3 : dicon
4 : entity
5 : goya
6 : interceptor
7 : module
8 : service
choice ? : 1 <--- 1 : command を選択
command name ? : sample
[ generate information ]
command name : sample
confirm ? (y/n) : y <--- 表示される情報を確認
[INFO ] create : /seasar.php/workspace/s2base.php5/app/commands/SampleCommand.class.php
↑
[ Command list ] クラスファイルが作成されます。
0 : (exit)
1 : command
・・・
BUILD FINISHED
Total time: 18.0426 seconds
%
SampleCommand クラスの execute メソッドを編集します。
% cat app/commands/SampleCommand.class.php
<?php
class SampleCommand
implements S2Base_GenerateCommand {
public function getName(){
return "sample"; <--- コマンドリストに表示されるコマンド名
}
public function execute(){
print __METHOD__ . " called.\n"; <--- print 文を追記
}
}
?>
%
再度 phing を実行すると sample コマンドが選択できます。
% phing
Buildfile: /seasar.php/workspace/s2base.php5/build.xml
project > prepare:
[php] Evaluating PHP expression: require_once('config/environment.inc.php')
[php] Evaluating PHP expression: require_once('lib/S2Base/S2Base.cmd.php')
project > com:
[ Command list ]
0 : (exit)
1 : command
2 : dao
3 : dicon
4 : entity
5 : goya
6 : interceptor
7 : module
8 : service
9 : sample <--- 新規作成したコマンドが表示されます。
choice ? : 9
SampleCommand::execute called. <--- コマンドクラスの execute メソッドが実行されます。
BUILD FINISHED
Total time: 2.0847 seconds
%
説明
S2Dao で必要な dao インタフェース、entity クラス、dao コンポーネント定義済みの dicon ファイル、テストクラスを生成します。
実行例
dao コマンドの説明では、S2DaoのExampleで使用されているサンプルデータを用いて説明します。
mysql> desc CD;
+---------+--------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+---------+--------------+------+-----+---------+-------+
| ID | int(11) | NO | PRI | | |
| TITLE | varchar(100) | YES | | | |
| CONTENT | varchar(200) | YES | | | |
+---------+--------------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> select * from CD;
+----+----------+---------+
| ID | TITLE | CONTENT |
+----+----------+---------+
| 1 | S2Dao!!! | hello!! |
+----+----------+---------+
1 row in set (0.00 sec)
mysql>
s2base.php5 ディレクトリで phing を実行します。
% phing
Buildfile: /seasar.php/workspace/s2base.php5/build.xml
project > prepare:
[php] Evaluating PHP expression: require_once('config/environment.inc.php')
[php] Evaluating PHP expression: require_once('lib/S2Base/S2Base.cmd.php')
project > com:
[ Command list ]
0 : (exit)
1 : command
2 : dao
3 : dicon
4 : entity
5 : goya
6 : interceptor
7 : module
8 : service
choice ? : 2 <--- 2 : dao を選択
[ Module list ]
0 : (exit)
1 : Default
choice ? : 1 <--- 1 : Default モジュールを選択
dao interface name ? : CdDao <--- 英数字 [_a-zA-Z0-9] が使用可能です。
entity class name ? : CdEntity <--- 英数字 [_a-zA-Z0-9] が使用可能です。
table name ? [CdEntity] : CD <--- データベースのテーブル名を設定。
columns ? [id,name,--, , ] : id,title,content <--- カンマ区切りでカラム名を入力
[ generate information ]
module name : Default
dao interface name : CdDao
dao test class name : CdDaoTest
entity class name : CdEntity
table name : CD
columns : id, title, content
dao dicon file name : CdDao.dicon
confirm ? (y/n) : y <--- 表示される情報を確認
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/dao/CdDao.class.php
[INFO ] create : /seasar.php/workspace/s2base.php5/test/modules/Default/dao/CdDaoTest.class.php
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/dicon/CdDao.dicon
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/entity/CdEntity.class.php
[ Command list ]
0 : (exit)
1 : command
・・・
BUILD FINISHED
Total time: 30.5662 seconds
%
daoコマンドにより、PHPUnit2を用いたUnitTestクラスが作成されます。phing コマンドに test 引数を付けて実行すると、UnitTestが実行されます。
% phing test -Dtd=modules/Default/dao <--- -D オプションで test ディレクトリ以下のディレクトリを指定できます。
Buildfile: /seasar.php/workspace/s2base.php5/build.xml
project > prepare:
[php] Evaluating PHP expression: require_once('config/environment.inc.php')
[php] Evaluating PHP expression: require_once('lib/S2Base/S2Base.cmd.php')
project > test:
CdDaoTest::testA
[phpunit2] Testsuite: CdDaoTest
[phpunit2] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.07924 sec
BUILD FINISHED
Total time: 0.6863 seconds
%
dao コマンドにより生成されるDaoインタフェースは、デフォルトでいくつかのメソッドが定義済みです。
% more app/modules/Default/dao/CdDao.class.php
<?php
interface CdDao {
const BEAN = "CdEntity";
public function findAllArray();
public function update(CdEntity $entity);
public function insert(CdEntity $entity);
public function delete(CdEntity $entity);
}
?>
%
例として、findAllArrayメソッドを実行してみます。まず、テストクラスにテストメソッドを追加します。
% more test/modules/Default/dao/CdDaoTest.class.php
<?php
class CdDaoTest extends PHPUnit2_Framework_TestCase {
private $module = "Default";
private $container; <--- 各テストの前処理でS2Containerオブジェクトが設定されます。
private $dao; <--- 各テストの前処理でDaoオブジェクトが設定されます。
function __construct($name) {
parent::__construct($name);
}
function testFindAllArray() { <--- 追加テストメソッド
print __METHOD__ . "\n";
$rows = $this->dao->findAllArray();
$entity = $rows[0];
$this->assertTrue($entity instanceof CdEntity);
$this->assertEquals($entity->getId(),'1');
$this->assertEquals($entity->getTitle(),'S2Dao!!!');
$this->assertEquals($entity->getContent(),'hello!!');
print_r($entity);
}
function setUp(){
print "\n";
$moduleDir = S2BASE_PHP5_ROOT . "/app/modules/{$this->module}";
$dicon = $moduleDir . "/dicon/CdDao" . S2BASE_PHP5_DICON_SUFFIX;
include_once($moduleDir . "/{$this->module}.inc.php");
$this->container = S2ContainerFactory::create($dicon);
$this->dao = $this->container->getComponent("CdDao");
}
function tearDown() {
$this->container = null;
$this->dao = null;
}
}
?>
%
テストを実行すると、データベースから取得したデータを格納したEntitiyオブジェクトが表示されます。
% phing test -Dtd=modules/Default/dao
Buildfile: /seasar.php/workspace/s2base.php5/build.xml
project > prepare:
[php] Evaluating PHP expression: require_once('config/environment.inc.php')
[php] Evaluating PHP expression: require_once('lib/S2Base/S2Base.cmd.php')
project > test:
CdDaoTest::testFindAllArray
CdEntity Object <--- print_r($entity) でデバッグとして表示しています。
(
[id:private] => 1
[title:private] => S2Dao!!!
[content:private] => hello!!
)
[phpunit2] Testsuite: CdDaoTest
[phpunit2] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.43753 sec
BUILD FINISHED
Total time: 1.0303 second
%
説明
XML形式のdiconファイルを生成します。
実行例
s2base.php5 ディレクトリで phing を実行します。
% phing
Buildfile: /seasar.php/workspace/s2base.php5/build.xml
project > prepare:
[php] Evaluating PHP expression: require_once('config/environment.inc.php')
[php] Evaluating PHP expression: require_once('lib/S2Base/S2Base.cmd.php')
project > com:
[ Command list ]
0 : (exit)
1 : command
2 : dao
3 : dicon
4 : entity
5 : goya
6 : interceptor
7 : module
8 : service
choice ? : 3 <--- 3 : dicon を選択
[ Module list ]
0 : (exit)
1 : Default
choice ? : 1 <--- 1 : Default モジュールを選択
dicon name ? : sample <--- 英数字 [_a-zA-Z0-9] が使用可能です。
[ generate information ]
module name : Default
dicon file name : sample.dicon
confirm ? (y/n) : y <--- 表示される情報を確認
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/dicon/sample.dicon
[ Command list ]
0 : (exit)
1 : command
・・・
BUILD FINISHED
Total time: 38.8949 seconds
%
sample.dicon は空のダイコンファイルです。
% more app/modules/Default/dicon/sample.dicon
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container//EN"
"http://www.seasar.org/dtd/components21.dtd">
<components>
</components>
%
説明
S2Dao で用いる Entity クラスを作成します。columns でカンマ区切りのカラム名を入力すると、対応するプロパティとアクセッサメソッドを追加します。
実行例
s2base.php5 ディレクトリで phing を実行します。
% phing
Buildfile: /seasar.php/workspace/s2base.php5/build.xml
project > prepare:
[php] Evaluating PHP expression: require_once('config/environment.inc.php')
[php] Evaluating PHP expression: require_once('lib/S2Base/S2Base.cmd.php')
project > com:
[ Command list ]
0 : (exit)
1 : command
2 : dao
3 : dicon
4 : entity
5 : goya
6 : interceptor
7 : module
8 : service
choice ? : 4 <--- 4 : entity を選択
[ Module list ]
0 : (exit)
1 : Default
choice ? : 1 <--- 1 : Default モジュールを選択
entity class name ? : DvdEntity <--- 英数字 [_a-zA-Z0-9] が使用可能です。
table name ? [DvdEntity] : DVD <--- データベースのテーブル名を設定
columns ? [id,name,--, , ] : id,title,content <--- カンマ区切りでカラム名を入力
[ generate information ]
module name : Default
entity class name : DvdEntity
table name : DVD
columns : id, title, content
confirm ? (y/n) : y <--- 表示される情報を確認
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/entity/DvdEntity.class.php
[ Command list ]
0 : (exit)
1 : command
・・・
BUILD FINISHED
Total time: 38.7971 seconds
%
columns で、id、title、content を指定したので、3つのプロパティとそれぞのアクセッサメソッドが実装されます。
% more app/modules/Default/entity/DvdEntity.class.php
<?php
class DvdEntity {
const TABLE = "DVD";
public function __construct(){}
private $id;
public function setId($val){$this->id = $val;}
public function getId(){return $this->id;}
private $title;
public function setTitle($val){$this->title = $val;}
public function getTitle(){return $this->title;}
private $content;
public function setContent($val){$this->content = $val;}
public function getContent(){return $this->content;}
}
?>
%
説明
goya コマンドはサービス名を決めると、命名規則に従ってサービス、dao、enitity、ダイコンファイル、テストクラスを生成します。
service コマンドと dao コマンドを同時に実行することとほぼ同じ処理になります。
例えば、サービス名を「 emp 」とすると、サービスは EmpService、dao は EmpDao、entity は EmpEntitiy となります。
実行例
s2base.php5 ディレクトリで phing を実行します。
% phing
Buildfile: /seasar.php/workspace/s2base.php5/build.xml
project > prepare:
[php] Evaluating PHP expression: require_once('config/environment.inc.php')
[php] Evaluating PHP expression: require_once('lib/S2Base/S2Base.cmd.php')
project > com:
[ Command list ]
0 : (exit)
1 : command
2 : dao
3 : dicon
4 : entity
5 : goya
6 : interceptor
7 : module
8 : service
choice ? : 5 <--- 5 : goya を選択
[ Module list ]
0 : (exit)
1 : Default
choice ? : 1 <--- 1 : Default モジュールを選択
service name ? : emp <--- 英数字 [_a-zA-Z0-9] が使用可能です。
[ use commons dao ? ]
0 : (exit)
1 : yes
2 : no
choice ? : 2
table name ? [emp] : EMP <--- データベースのテーブル名を設定
columns ? [id,name,--, , ] : id,name,dept <--- カンマ区切りでカラム名を入力
[ generate information ]
module name : Default
service name : emp
service interface name : EmpService
service class name : EmpServiceImpl
service test class name : EmpServiceImplTest
dao interface name : EmpDao
dao test class name : EmpDaoTest
entity class name : EmpEntity
table name : EMP
columns : id, name, dept
service dicon file name : EmpService.dicon
confirm ? (y/n) : y <--- 表示される情報を確認
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/service/EmpServiceImpl.class.php
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/service/EmpService.class.php
[INFO ] create : /seasar.php/workspace/s2base.php5/test/modules/Default/service/EmpServiceImplTest.class.php
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/dao/EmpDao.class.php
[INFO ] create : /seasar.php/workspace/s2base.php5/test/modules/Default/dao/EmpDaoTest.class.php
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/entity/EmpEntity.class.php
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/dicon/EmpService.dicon
[ Command list ]
0 : (exit)
1 : command
・・・
BUILD FINISHED
Total time: 1 minutes 13.67 seconds
%
[ commons dao ] については、gen-dao タスクを参照下さい。
goya コマンドで生成されるダイコンファイルでは、サービスと dao コンポーネントが登録済みです。
% more app/modules/Default/dicon/EmpService.dicon
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE components PUBLIC "-//SEASAR//DTD S2Container//EN"
"http://www.seasar.org/dtd/components21.dtd">
<components>
<include path="%S2BASE_PHP5_ROOT%/app/commons/dicon/dao.dicon"/>
<component class="EmpServiceImpl"/>
<component class="EmpDao">
<aspect>dao.interceptor</aspect>
</component>
</components>
%
また、EmpServiceImplクラスでは EmpDao へのセッターメソッドが定義済みなので、サービスに dao が自動インジェクションされます。
% more app/modules/Default/service/EmpServiceImpl.class.php
<?php
class EmpServiceImpl
implements EmpService {
private $dao;
public function __construct(){}
public function setDao(EmpDao $dao){
$this->dao = $dao;
}
}
?>
%
説明
S2Aop の MethodInterceptor を実装するクラスを生成します。
実行例
s2base.php5 ディレクトリで phing を実行します。
% phing
Buildfile: /seasar.php/workspace/s2base.php5/build.xml
project > prepare:
[php] Evaluating PHP expression: require_once('config/environment.inc.php')
[php] Evaluating PHP expression: require_once('lib/S2Base/S2Base.cmd.php')
project > com:
[ Command list ]
0 : (exit)
1 : command
2 : dao
3 : dicon
4 : entity
5 : goya
6 : interceptor
7 : module
8 : service
choice ? : 6 <--- 6 : interceptor を選択
[ Module list ]
0 : (exit)
1 : Default
choice ? : 1 <--- 1 : Default モジュールを選択
interceptor class name ? : HogeInterceptor <--- 英数字 [_a-zA-Z0-9] が使用可能です。
[ generate information ]
module name : Default
interceptor class name : HogeInterceptor
confirm ? (y/n) : y <--- 表示される情報を確認
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/interceptor/HogeInterceptor.class.php
BUILD FINISHED
Total time: 17.2060 seconds
%
S2Container_AbstractInterceptor を継承した interceptor を生成します。参照:独自実装によるInterceptor
% more app/modules/Default/interceptor/HogeInterceptor.class.php
<?php
class HogeInterceptor
extends S2Container_AbstractInterceptor {
/**
* @param S2Container_MethodInvocation $invocation
* - $invocation->getThis() : return target object
* - $invocation->getMethod() : return ReflectionMethod of target method
* - $invocation->getArguments() : return array of method arguments
*/
public function invoke(S2Container_MethodInvocation $invocation) {
return $invocation->proceed();
}
}
?>
%
説明
app/modules ディレクトリと test/modules ディレクトリにモジュールディレクトリを作成します。
app/modules/モジュールディレクトリには、dao、dicon、entity、interceptor、serviceディレクトリが作成されます。
実行例
s2base.php5 ディレクトリで phing を実行します。
% phing
Buildfile: /seasar.php/workspace/s2base.php5/build.xml
project > prepare:
[php] Evaluating PHP expression: require_once('config/environment.inc.php')
[php] Evaluating PHP expression: require_once('lib/S2Base/S2Base.cmd.php')
project > com:
[ Command list ]
0 : (exit)
1 : command
2 : dao
3 : dicon
4 : entity
5 : goya
6 : interceptor
7 : module
8 : service
choice ? : 7 <--- 7 : module を選択
module name ? : Default <--- モジュール名を入力。英数字 [_a-zA-Z0-9] が使用可能です。
[ generate information ]
module name : Default <--- モジュール情報を確認
confirm ? (y/n) : y
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/dao/
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/dicon/
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/entity/
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/interceptor/
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/service/
[INFO ] create : /seasar.php/workspace/s2base.php5/test/modules/Default
[INFO ] create : /seasar.php/workspace/s2base.php5/test/modules/Default/dao/
[INFO ] create : /seasar.php/workspace/s2base.php5/test/modules/Default/service/
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/Default.inc.php
[ Command list ]
0 : (exit)
1 : command
・・・
BUILD FINISHED
Total time: 8.2091 seconds
%
app ディレクトリと test ディレクトリ以下にDefaultモジュールが作成されます。
% ls app/modules/Default
Default.inc.php dao dicon entity interceptor service
% ls test/modules/Default
dao service
%
説明
サービスインタフェース、実装クラス、ダイコンファイル、テストクラスを生成します。
実行例
s2base.php5 ディレクトリで phing を実行します。
% phing
Buildfile: /seasar.php/workspace/s2base.php5/build.xml
project > prepare:
[php] Evaluating PHP expression: require_once('config/environment.inc.php')
[php] Evaluating PHP expression: require_once('lib/S2Base/S2Base.cmd.php')
project > com:
[ Command list ]
0 : (exit)
1 : command
2 : dao
3 : dicon
4 : entity
5 : goya
6 : interceptor
7 : module
8 : service
choice ? : 8 <--- 8 : service を選択
[ Module list ]
0 : (exit)
1 : Default
choice ? : 1 <--- 1 : Default モジュールを選択
service interface name ? : CulcService <--- 英数字 [_a-zA-Z0-9] が使用可能です。
[ generate information ]
module name : Default
service interface name : CulcService
service class name : CulcServiceImpl
service test class name : CulcServiceImplTest
service dicon file name : CulcService.dicon
confirm ? (y/n) : y <--- 表示される情報を確認
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/service/CulcServiceImpl.class.php
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/service/CulcService.class.php
[INFO ] create : /seasar.php/workspace/s2base.php5/test/modules/Default/service/CulcServiceImplTest.class.php
[INFO ] create : /seasar.php/workspace/s2base.php5/app/modules/Default/dicon/CulcService.dicon
[ Command list ]
0 : (exit)
1 : command
・・・
BUILD FINISHED
Total time: 12.7848 seconds
%
service コマンドにより PHPUnit2 を用いた UnitTest クラスが作成されます。phing コマンドに test 引数を付けて実行すると UnitTest を実行できます。
% phing test -Dtd=modules/Default/service
Buildfile: /seasar.php/workspace/s2base.php5/build.xml
project > prepare:
[php] Evaluating PHP expression: require_once('config/environment.inc.php')
[php] Evaluating PHP expression: require_once('lib/S2Base/S2Base.cmd.php')
project > test:
CulcServiceImplTest::testA
[phpunit2] Testsuite: CulcServiceImplTest
[phpunit2] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.01326 sec
BUILD FINISHED
Total time: 0.5984 seconds
%
例として、サービスクラスに add メソッドを追加します。
% more app/modules/Default/service/CulcServiceImpl.class.php
<?php
class CulcServiceImpl
implements CulcService{
public function __construct(){}
public function add($a,$b){ <--- 足し算メソッドを追加
return $a + $b;
}
}
?>
%
テストクラスに add メソッドをテストするテストメソッドを追加します。
% more test/modules/Default/service/CulcServiceImplTest.class.php
<?php
class CulcServiceImplTest extends PHPUnit2_Framework_TestCase {
private $module = "Default";
private $serviceName = "CulcService";
private $container; <--- 各テストの前処理でS2Containerオブジェクトが設定されます。
private $service; <--- 各テストの前処理でサービスオブジェクトが設定されます。
function __construct($name) {
parent::__construct($name);
}
function testAdd() { <--- テストメソッドを追加
print __METHOD__ . "\n";
$a = 2;
$b = 3;
$c = $this->service->add($a,$b);
$this->assertEquals($c,5);
print "$a + $b = $c \n";
}
function setUp(){
print "\n";
$moduleDir = S2BASE_PHP5_ROOT . "/app/modules/{$this->module}";
$dicon = $moduleDir . "/dicon/CulcService" . S2BASE_PHP5_DICON_SUFFIX;
include_once($moduleDir . "/{$this->module}.inc.php");
$this->container = S2ContainerFactory::create($dicon);
$this->service = $this->container->getComponent("CulcService");
}
function tearDown() {
$this->container = null;
$this->service = null;
}
}
?>
%
phing コマンドに test 引数を付けて実行すると UnitTest を実行できます。
% phing test -Dtd=modules/Default/service
Buildfile: /seasar.php/workspace/s2base.php5/build.xml
project > prepare:
[php] Evaluating PHP expression: require_once('config/environment.inc.php')
[php] Evaluating PHP expression: require_once('lib/S2Base/S2Base.cmd.php')
project > test:
CulcServiceImplTest::testAdd
2 + 3 = 5 <--- デバッグとして、足し算式を表示します。
[phpunit2] Testsuite: CulcServiceImplTest
[phpunit2] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.01385 sec
BUILD FINISHED
Total time: 0.6278 seconds
%
説明
S2Base コマンドの service、dao、goya では、UnitTestが生成されます。これらの UnitTest を実行するタスクです。
実行例
s2base.php5 ディレクトリで phing test を実行します。test ディレクトリにある全テストを実行します。
% phing test
Buildfile: /seasar.php/workspace/s2base.php5/build.xml
project > prepare:
[php] Evaluating PHP expression: require_once('config/environment.inc.php')
[php] Evaluating PHP expression: require_once('lib/S2Base/S2Base.cmd.php')
project > test:
[echo] test directory : test/ <--- test ディレクトリ以下の全テスト
CdDaoTest::testFindAllArray
CdEntity Object
(
[id:private] => 1
[title:private] => S2Dao!!!
[content:private] => hello!!
)
[phpunit2] Testsuite: CdDaoTest
[phpunit2] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.20118 sec
CulcServiceImplTest::testAdd
2 + 3 = 5
[phpunit2] Testsuite: CulcServiceImplTest
[phpunit2] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.00723 sec
BUILD FINISHED
Total time: 0.8004 seconds
%
phing コマンドのオプション -Dプロパティ名 を使用して、test ディレクトリ以下の任意のディレクトリを指定できます。プロパティ名は「 td 」です。
% phing test -Dtd=modules/Default/dao
Buildfile: /seasar.php/workspace/s2base.php5/build.xml
project > prepare:
[php] Evaluating PHP expression: require_once('config/environment.inc.php')
[php] Evaluating PHP expression: require_once('lib/S2Base/S2Base.cmd.php')
project > test:
[echo] test directory : test/modules/Default/dao <--- dao サブディレクトリ以下の全テスト
CdDaoTest::testFindAllArray
CdEntity Object
(
[id:private] => 1
[title:private] => S2Dao!!!
[content:private] => hello!!
)
[phpunit2] Testsuite: CdDaoTest
[phpunit2] Tests run: 1, Failures: 0, Errors: 0, Time elapsed: 0.20403 sec
BUILD FINISHED
Total time: 0.7715 seconds
%
説明
S2Dao に付属の S2DaoSkeletonTask を用いて、app/commons/dao ディレクトリにデータベースの全テーブルの dao と entity を生成します。
実行例
データベースに次のようなサンプルテーブルを複数用意しています。
mysql> show tables;
+-----------------------+
| Tables_in_s2container |
+-----------------------+
| CD |
| DEPT |
| EMP |
| SHELF |
+-----------------------+
4 rows in set (0.00 sec)
mysql>
build.xml の gen-dao タスクで、DSN設定を行います。
<?xml version="1.0"?>
<project name="project" default="com" basedir=".">
・・・
<target name="gen-dao" depends="prepare">
<property name="dsn" value="mysql:host=localhost; dbname=s2container" />
<property name="user" value="root" />
<property name="password" value="test" />
<gdao toDir="app/commons/dao" />
</target>
・・・
</project>
s2base.php5 ディレクトリで phing gen-dao を実行します。
% phing gen-dao
Buildfile: /seasar.php/workspace/s2base.php5/build.xml
project > prepare:
[php] Evaluating PHP expression: require_once('config/environment.inc.php')
[php] Evaluating PHP expression: require_once('lib/S2Base/S2Base.cmd.php')
project > gen-dao:
[gdao] [create] [DAO]: CDDao
[gdao] [create] [BEAN]: CDEntity
[gdao] [create] [DAO]: DEPTDao
[gdao] [create] [BEAN]: DEPTEntity
[gdao] [create] [DAO]: EMPDao
[gdao] [create] [BEAN]: EMPEntity
[gdao] [create] [DAO]: SHELFDao
[gdao] [create] [BEAN]: SHELFEntity
[gdao] [INFO] see the files
[gdao] [file]: app/commons/dao/CDDao.class.php
[gdao] [file]: app/commons/dao/CDEntity.class.php
[gdao] [file]: app/commons/dao/DEPTDao.class.php
[gdao] [file]: app/commons/dao/DEPTEntity.class.php
[gdao] [file]: app/commons/dao/EMPDao.class.php
[gdao] [file]: app/commons/dao/EMPEntity.class.php
[gdao] [file]: app/commons/dao/SHELFDao.class.php
[gdao] [file]: app/commons/dao/SHELFEntity.class.php
BUILD FINISHED
Total time: 0.6476 seconds
%
% ls app/commons/dao
CDDao.class.php DEPTDao.class.php EMPDao.class.php SHELFDao.class.php
CDEntity.class.php DEPTEntity.class.php EMPEntity.class.php SHELFEntity.class.php
%
|