Last active
August 29, 2015 13:55
-
-
Save kkanazaw/8764838 to your computer and use it in GitHub Desktop.
絶対パスでrequire_onceしているクラスをなんとかテストする
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 HogeTest extends PHPUnit_Framework_TestCase { | |
// テスト実行前にtmpディレクトリ以下に*.phpファイルをコピー | |
// でtmp以下のファイルを置換する | |
public static function setUpBeforeClass() { | |
`mkdir -p tmp; cp *.php tmp/`; | |
`find tmp/ -name '*.php' | xargs perl -i -pe 's/(require_once)/\/\/$1/g;'`; | |
//改めてここでrequire_onceしてあげる(本物の代わりに、スタブを用意して呼ぶこともできる) | |
require_once("tmp/lib/Hoge.php"); | |
} | |
function testNew() { | |
$hoge = new Hoge(); | |
$this->assertTrue(is_object($hoge)); | |
} | |
//テストが終わった後は消すことも可能(残しておけばカバレッジ取ることも可能) | |
public static function tearDownAfterClass() { | |
`rm -rf ./tmp`; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment