Created
June 3, 2014 07:28
-
-
Save memememomo/a66289677843ec3d39e4 to your computer and use it in GitHub Desktop.
ComposerでPHPUnitをインストールし、FuelPHPでユニットテストを行う ref: http://qiita.com/uchiko/items/b62eafc18519a5970046
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
... | |
"require": { | |
... | |
"phpunit/phpunit": "4.1.*", | |
"piece/stagehand-testrunner": ">=3.5.0" | |
}, | |
... |
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 composer.phar update |
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
$ cp fuel/packages/oil/config/oil.php fuel/app/config/ |
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 oil test --group=Core |
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 oil test --group=App | |
Tests Running...This may take a few moments. | |
PHPUnit 4.1.1-2-ge93a391 by Sebastian Bergmann. | |
Configuration read from /home/uchiko/project/fuelphp-1.7/fuel/core/phpunit.xml | |
............... | |
Time: 1.32 seconds, Memory: 16.25Mb | |
OK (15 tests, 18 assertions) |
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 MyInputFilters | |
{ | |
// 文字エンコーディングの検証フィルタ | |
public static function check_encoding($value) | |
{ | |
// 配列の場合は再帰的に処理 | |
if (is_array($value)) | |
{ | |
array_map(['MyInputFilters', 'check_encoding'], $value); | |
return $value; | |
} | |
// 文字エンコーディングを検証 | |
if (mb_check_encoding($value, Fuel::$encoding)) | |
{ | |
return $value; | |
} | |
else | |
{ | |
// エラーの場合はログに記録 | |
static::log_error('Invalid character encoding', $value); | |
// エラーを表示してシュル用 | |
throw new HttpInvalidInputException('Invalid input data'); | |
} | |
} | |
// エラーをログに記録 | |
public static function log_error($msg, $value) | |
{ | |
Log::error( | |
$msg . ': ' . Input::uri() . ' ' . urlencode($value) . ' ' . | |
Input::ip() . ' "' . Input::user_agent() . '"' | |
); | |
} | |
} |
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 | |
/** | |
* MyInputFilters class Tests | |
* | |
* @group App | |
*/ | |
class Test_MyInputFilters extends TestCase | |
{ | |
public function test_check_encoding_invalid_sjis() | |
{ | |
$this->setExpectedException( | |
'HttpInvalidInputException', 'Invalid input data' | |
); | |
$input = mb_convert_encoding('SJISの文字列です。', 'SJIS'); | |
$test = MyInputFilters::check_encoding($input); | |
} | |
public function test_check_encoding_valid() | |
{ | |
$input = '正常なUTF-8の文字列です。'; | |
$test = MyInputFilters::check_encoding($input); | |
$expected = $input; | |
$this->assertEquals($expected, $test); | |
} | |
} |
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
'autoload_path' => '' , | |
'binary_path' => DOCROOT.'fuel/vendor/bin/phpunit' , |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment