- Controller が DB アクセスをするのを許すと、フローのテストが遅くなる
- DB アクセスが必要な処理は Model へ追いやる
- QUERY_STRING, ENV あたりを入力とする Controller のフローのテストと、DB や memcached を入力 とする Model のテストは分離するとテストしやすい
- Controller と Model, View などの API の切れ目で抽象化してテスト可能にしておくとやりやすいので、 切れ目をフレームワークで強制したり、運用ルールで縛ると最低限のテスト可能性が確保された設計に
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
RewriteRule ^ja/man/html/_A4CFA4B8A4E1A4CB.html(.*)$ http://doc.ruby-lang.org/ja/1.9.2/doc/spec=2fintro.html$1 [L,R=301] | |
RewriteRule ^ja/man/html/_A5B3A5DEA5F3A5C9.html(.*)$ http://doc.ruby-lang.org/ja/1.9.2/doc/spec=2fcommands.html$1 [L,R=301] | |
RewriteRule ^ja/man/html/Ruby_A4CEB5AFC6B0.html(.*)$ http://doc.ruby-lang.org/ja/1.9.2/doc/spec=2frubycmd.html$1 [L,R=301] | |
RewriteRule ^ja/man/html/-(.*)$ http://doc.ruby-lang.org/ja/-$1 [L,R=301] | |
RewriteRule ^ja/man/html/-(.*)$ http://doc.ruby-lang.org/ja/-$1 [L,R=301] | |
RewriteRule ^ja/man/html/_B4C4B6ADCAD1BFF4.html(.*)$ http://doc.ruby-lang.org/ja/1.9.2/doc/spec=2fenvvars.html$1 [L,R=301] | |
RewriteRule ^ja/man/html/-(.*)$ http://doc.ruby-lang.org/ja/-$1 [L,R=301] | |
RewriteRule ^ja/man/html/_A5AAA5D6A5B8A5A7A5AFA5C8.html(.*)$ http://doc.ruby-lang.org/ja/1.9.2/doc/spec=2fobject.html$1 [L,R=301] | |
RewriteRule ^ja/man/html/_A5AFA5E9A5B9.html(.*)$ http://doc.ruby-lang.org/ja/1.9.2/doc/spec=2fclass.html$1 [L,R=301] | |
RewriteRule ^ja/man/html/_BCC2B9D4.html(.*)$ http://doc.ruby-lan |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// public ReflectionMethod::getClosure ( object $object ) alternative | |
function toClosure($class_name, $method_name, $obj = null) { | |
if (!is_null($obj) and !is_a($obj, $class_name)) throw new \InvalidArgumentException('invalid object is given.'); | |
$func = new ReflectionMethod($class_name, $method_name); | |
if ($func->isStatic()) { | |
return function() use($func) { | |
$func->invokeArgs(null, func_get_args()); | |
}; | |
} else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// see https://gist.github.com/1106254 about toClosure() function. | |
class SpecificException extends Exception {}; | |
class Sample | |
{ | |
// Exectute Around Method and try-catch-finally sample in PHP. | |
function inLock($callback) { | |
$unlock = \toClosure(get_class(), 'unlock', $this); | |
$ensure = function() use($unlock) { $unlock(); }; | |
$this->lock(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// スゴロク | |
// Start Goal | |
// 0 -- 1 -- 2 -- 3 -- 4 | |
// dice! | |
// | |
// * 0 から 4 までのマスがあります | |
// * 0 から 2 のマスにいるとき、1 ターンにつき 1 進みます | |
// * 3 のマスにいるときは、サイコロを振り、1 か 6 のときのみ 1 進みます。 2 から 5 が出たときは 3 のマスへ残ったまま次のターンへ進みます | |
// * 4 まで来たらゴールなので、ゲームを終えます | |
// * ターンはループで回る一回を 1 ターンにします |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Base | |
{ | |
static public $name = 'BASE'; | |
function stamp($name) { | |
static::$name = $name; | |
} | |
} | |
class A extends Base |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Sample | |
{ | |
static private $value = 0; | |
static function privateHack() { | |
$hack =& static::$value; | |
return function($val) use (&$hack) { | |
$hack = $val; | |
}; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class HackObject | |
{ | |
public $_entityName; | |
public $_attributeNames; | |
function entityName($val) { $func = $this->_entityName; $func($val); } | |
function attributeNames($val) { $func = $this->_attributeNames; $func($val); } | |
} | |
class EntityBase |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- id num id+1 num | |
------------------------- | |
-- 1 1 2 2 | |
-- 2 2 3 3 | |
-- 3 3 4 4 | |
-- 4 4 5 5 | |
-- 5 5 6 6 | |
-- 6 6 7 7 | |
-- 7 7 8 8 | |
-- 8 8 9 9 |