- Controller が DB アクセスをするのを許すと、フローのテストが遅くなる
- DB アクセスが必要な処理は Model へ追いやる
- QUERY_STRING, ENV あたりを入力とする Controller のフローのテストと、DB や memcached を入力 とする Model のテストは分離するとテストしやすい
- Controller と Model, View などの API の切れ目で抽象化してテスト可能にしておくとやりやすいので、 切れ目をフレームワークで強制したり、運用ルールで縛ると最低限のテスト可能性が確保された設計に
This file contains 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 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 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 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 |
This file contains 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
#! ruby | |
# coding: utf-8 | |
# | |
# http://d.hatena.ne.jp/nowokay/20090409#1239268405 | |
require 'expectations' | |
Expectations do | |
# boolean | |
t = (-> x { (-> y {x}) }) |
This file contains 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
#!/bin/bash | |
# .bashrc か .bash_profile に | |
# | |
# export PATH=$HOME/libexec:$PATH | |
# | |
# を追記しておく (既存の export PATH があるなら $HOME/libexec を追加) 。 | |
src_path=$HOME/.src | |
exec_dir=libexec | |
package_dir=pkg |
This file contains 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
#!/bin/bash | |
# .bashrc か .bash_profile に | |
# | |
# export PATH=$HOME/bin:$PATH | |
# | |
# を追記しておく (既存の export PATH があるなら $HOME/bin を追加) 。 | |
src_path=$HOME/.src | |
exec_dir=bin | |
package_dir=pkg |
This file contains 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
module Builder | |
def self.method_missing name, *args, &block | |
tag = Tag.new | |
tag.send(name, *args, &block).flatten.join | |
end | |
class Tag | |
def initialize | |
@tags = [] | |
end |