Diffs
dfDocTestPlugin/trunk/LICENSE
@@ -0,0 +1,9 @@
+Copyright (c) 2007-2008 TAKAHARA Yoshihiro <y dot takahara at gmail dot com>
+Copyright (c) 2007-2008 Dino Co.,Ltd. http://www.dino.co.jp
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
+
dfDocTestPlugin/trunk/doc/emphasis-1.png
表示できません: バイナリ形式としてマークされたファイルです。
svn:mime-type = image/png
属性に変更があったパス: dfDocTestPlugin/trunk/doc/emphasis-1.png
___________________________________________________________________
追加: svn:mime-type
+ image/png
dfDocTestPlugin/trunk/doc/emphasis-2.png
表示できません: バイナリ形式としてマークされたファイルです。
svn:mime-type = image/png
属性に変更があったパス: dfDocTestPlugin/trunk/doc/emphasis-2.png
___________________________________________________________________
追加: svn:mime-type
+ image/png
dfDocTestPlugin/trunk/doc/emphasis-1.php
@@ -0,0 +1,10 @@
+<?php
+/**
+ * #test
+ * <code>
+ * #is(emphasis("great"),"great!!","add !! emphasised.");
+ * </code>
+ *
+ */
+function emphasis($word){
+}
属性に変更があったパス: dfDocTestPlugin/trunk/doc/emphasis-1.php
___________________________________________________________________
追加: svn:mime-type
+ text/x-php
追加: svn:keywords
+ Id Rev Date
追加: svn:eol-style
+ native
dfDocTestPlugin/trunk/doc/emphasis-2.php
@@ -0,0 +1,11 @@
+<?php
+/**
+ * #test
+ * <code>
+ * #is(emphasis("great"),"great!!","add !! emphasised.");
+ * </code>
+ *
+ */
+function emphasis($word){
+ return $word."!!";
+}
属性に変更があったパス: dfDocTestPlugin/trunk/doc/emphasis-2.php
___________________________________________________________________
追加: svn:mime-type
+ text/x-php
追加: svn:keywords
+ Id Rev Date
追加: svn:eol-style
+ native
dfDocTestPlugin/trunk/doc/tracfort-plugin-release
@@ -0,0 +1,23 @@
+#!/bin/sh
+# plugin
+
+ver=0.0.2
+plugin=sfDocTestPlugin
+dir=`mktemp -d`
+root=http://svn.tracfort.jp/svn
+project=dino-symfony
+
+
+mkdir -p ${dir}
+cd ${dir} || exit
+svn cp ${root}/${project}/plugins/${plugin}\
+ ${root}/${project}/tags/${plugin}-${ver}\
+ -m ""
+
+svn export ${root}/${project}/tags/${plugin}-${ver} ${plugin}
+tar cvzf ${plugin}-${ver}.tgz ${plugin}
+mkdir -p ~/released
+cp -v ${plugin}-${ver}.tgz ~/released
+
+
+
属性に変更があったパス: dfDocTestPlugin/trunk/doc/tracfort-plugin-release
___________________________________________________________________
追加: svn:executable
+
dfDocTestPlugin/trunk/README.ja
@@ -0,0 +1,78 @@
+= sfDocTestPlugin =
+
+sfDocTestPluginは、`symfony`コマンドに`symfony doctest`タスクおよび`symfony doctesta-all`タスクを追加します。[http://d.hatena.ne.jp/kunit/20080205#1202142580 Maple_DocTest]にインスパイアされて作ってみました。
+
+
+== インストール ==
+Subversionを使ったチェックアウトをしてください。
+
+{{{
+cd plugins
+svn co http://svn.tracfort.jp/svn/dino-symfony/plugins/sfDocTestPlugin
+cd - && symfony cc
+}}}
+
+== テストの実施 ==
+
+プラグインをインストール後、単に以下のようにすればテストを実施します。
+
+{{{
+symfony doctest-all frontend
+}}}
+
+== テストの実装 ==
+テストが実装されていなければ、すべてのファイルのdoctestがパスします。
+
+例えば以下のコードにテストケースをを実装するには、PHPファイルのコメント(/** 〜 */)に以下のようにコメントを実装していきます。
+
+ * plugins/sfDocTestPlugin/doc/emphasis-1.php
+{{{
+<?php
+/**
+ * #test
+ * <code>
+ * #is(emphasis("great"),"great!!","add !! emphasised.");
+ * </code>
+ *
+ */
+function emphasis($word){
+}
+}}}
+
+`#test`の後の<code>〜</code>がテストケースとして展開されます。#isはlime_testのメソッド->is()に対応しています。
+
+このファイルのテストを実行してみます。
+
+{{{
+symfony doctest frontend emphasis-1.php
+}}}
+
+結果は以下のように失敗します。
+
+[[Image(emphasis-1.png)]]
+
+
+ * plugins/sfDocTestPlugin/doc/emphasis-2.php
+
+{{{
+<?php
+/**
+ * #test
+ * <code>
+ * #is(emphasis("great"),"great!!","add !! emphasised.");
+ * </code>
+ *
+ */
+function emphasis($word){
+ return $word."!!";
+}
+}}}
+
+今度は成功するでしょう。
+
+{{{
+symfony doctest frontend emphasis-2.php
+}}}
+
+[[Image(emphasis-2.png)]]
+
dfDocTestPlugin/trunk/lib/sfDocTest.class.php
@@ -0,0 +1,135 @@
+<?php
+/**
+ *
+ */
+class sfDocTest
+{
+ public static function getCacheDir(){
+ return "cache/".SF_APP."/".SF_ENVIRONMENT."/sfDocTestPlugin";
+ }
+
+ public static function getTestFile($file){
+ $tester = str_replace(SF_ROOT_DIR."/","",$file);
+ $dir = sfDocTest::getCacheDir()."/tests/".dirname($tester);
+ if(!is_dir($dir)){
+ mkdir($dir,0777,true);
+ }
+ return sprintf("%s/%s",$dir,basename($tester));
+ }
+ public static function compile_if_modified($file){
+ $cache = new sfFunctionCache(sfDocTest::getCacheDir());
+ $id = md5(serialize(array("sfDocTest::compile", $file)));
+ if($cache->lastModified($id) < filemtime($file)){
+ $cache->remove($id);
+ }
+ $test = $cache->call("sfDocTest::compile", $file);
+ $testfile = sfDocTest::getTestFile($file);
+ file_put_contents($testfile,$test);
+ return $testfile;
+ }
+ /**
+ */
+ public static function compile($file){
+ $body = file_get_contents($file);
+ $docs = sfDocTest::parse($body);
+ if(!count($docs)) return;
+ $out = "<?php\n";
+ $out .= "
+define('SF_ROOT_DIR', '".SF_ROOT_DIR."');
+define('SF_APP', '".SF_APP."');
+define('SF_ENVIRONMENT', '".SF_ENVIRONMENT."');
+define('SF_DEBUG', 1);
+require_once(SF_ROOT_DIR.DIRECTORY_SEPARATOR.'apps'.DIRECTORY_SEPARATOR.SF_APP.DIRECTORY_SEPARATOR.'config'.DIRECTORY_SEPARATOR.'config.php');\n
+";
+ $out .= "require_once(\$sf_symfony_lib_dir.'/vendor/lime/lime.php');\n
+
+\$databaseManager = new sfDatabaseManager();
+\$databaseManager->initialize();
+
+";
+
+
+ $out .= "
+if(!function_exists('pake_desc')){
+ function pake_desc(){}
+}
+if(!function_exists('pake_task')){
+ function pake_task(){}
+}
+require_once \"${file}\";
+";
+ $out .= "\$__test = new lime_test(null,new lime_output_color);\n
+\$__test->comment('file: $file');
+//ob_start();
+";
+
+
+
+ foreach($docs as $doc){
+ $out.=sfDocTest::compile_doc($doc);
+ }
+ return $out;
+ }
+ public static function compile_doc($doc){
+ $lines = explode("\n",$doc);
+ $start = false;
+ $compiled = "";
+ $code =false;
+ foreach($lines as $line){
+ if(preg_match("/ +\* #test *(.*)/",$line,$m)){
+ $start = true;
+ $compiled.=sprintf("#comment(\"test: %s\");\n",$m[1]);
+ continue;
+ }
+ if($start){
+ if(preg_match("/^ +\* @/",$line)){
+ break;
+ }
+ if(preg_match("/^ +\* <code> */",$line)){
+ $code = true;
+ continue;
+ }
+ if(preg_match("/^ +\* <\/code> */",$line)){
+ $code = false;
+ continue;
+ }
+ if($code){
+ if(preg_match("/^ +\* +(.*)/",$line,$m)){
+ $compiled.=$m[1];
+ $compiled.="\n";
+ }
+ }
+ }
+ }
+ return sfDocTest::expand_macro($compiled);
+ }
+ public static function expand_macro($compiled){
+ $compiled
+ = preg_replace("/^#eq\(/m","#is(",$compiled);
+ $compiled
+ = preg_replace("/^#true\(/m","#ok(",$compiled);
+ $compiled
+ = preg_replace("/^#false\(/m","#ok(!",$compiled);
+
+ return preg_replace("/^#([a-z_]+)\(/m","\$__test->\${1}(",$compiled);
+ }
+ public static function parse($body){
+ $tokens = token_get_all($body);
+ $doccoments = array();
+ foreach($tokens as $token){
+ if(!is_string($token)){
+ list($id, $text) = $token;
+ switch ($id) {
+ case T_DOC_COMMENT:
+ if(preg_match("/ +\* +#test */",$text)){
+ $doccoments[] = $text;
+ }
+ break;
+ }
+ }
+ }
+ return $doccoments;
+ }
+
+}
+
属性に変更があったパス: dfDocTestPlugin/trunk/lib/sfDocTest.class.php
___________________________________________________________________
追加: svn:mime-type
+ text/x-php
追加: svn:keywords
+ Id Rev Date
追加: svn:eol-style
+ native
dfDocTestPlugin/trunk/data/tasks/sfDocTestTask.php
@@ -0,0 +1,76 @@
+<?php
+pake_desc('doctest for all *.php in this project');
+pake_task('doctest-all','project_exists');
+pake_desc('doctest in this project');
+pake_task('doctest','project_exists');
+
+require_once(sfConfig::get('sf_symfony_lib_dir').'/vendor/lime/lime.php');
+
+function run_doctest($task,$args)
+{
+ if (count($args) < 1){
+ throw new Exception('You must provide the app to test.');
+ }
+ $app = array_shift($args);
+
+ define('SF_ROOT_DIR', sfConfig::get('sf_root_dir'));
+ define('SF_APP', $app);
+ define('SF_ENVIRONMENT', 'dev');
+ $finder = sfFinder::type('file')
+ ->ignore_version_control()
+ ->prune(array("cache","log",".*/vendor"))
+ ->follow_link();
+ foreach($args as $arg){
+ if(file_exists($arg)){
+ if(is_dir($arg)){
+ $files = $finder
+ ->name("*.php")->in($arg);
+ }else{
+ $files[] = $arg;
+ }
+ }else{
+ $finder->name($arg);
+ $files = $finder->in(sfConfig::get('sf_root_dir'));
+ }
+
+ $h = new lime_harness(new lime_output_color());
+ if (DIRECTORY_SEPARATOR == '\\' || !function_exists('posix_isatty') || !@posix_isatty(STDOUT)){
+ $tty = "";
+ }else{
+ $tty = ">".posix_ttyname(STDOUT);
+ }
+
+ foreach($files as $file){
+ if(is_readable($file)){
+ // echo sfDocTest::compile_if_modified($file);
+ passthru(sprintf
+ ("%s -d html_errors=off -d open_basedir= -q %s 2>&1 %s"
+ ,$h->php_cli
+ ,sfDocTest::compile_if_modified($file)
+ ,$tty));
+ }
+ }
+ }
+}
+function run_doctest_all($task,$args)
+{
+ if (!count($args)){
+ throw new Exception('You must provide the app to test.');
+ }
+ $app = $args[0];
+
+ define('SF_ROOT_DIR', sfConfig::get('sf_root_dir'));
+ define('SF_APP', $app);
+ define('SF_ENVIRONMENT', 'dev');
+
+ $finder = sfFinder::type('file')
+ ->ignore_version_control()
+ ->prune(array("cache","log",".*/vendor"))
+ ->follow_link()->name("*.php");
+ $files = $finder->in(sfConfig::get('sf_root_dir'));
+ $h = new lime_harness(new lime_output_color);
+ foreach($files as $file){
+ $h->register(sfDocTest::compile_if_modified($file));
+ }
+ $h->run();
+}
属性に変更があったパス: dfDocTestPlugin/trunk/data/tasks/sfDocTestTask.php
___________________________________________________________________
追加: svn:mime-type
+ text/x-php
追加: svn:keywords
+ Id Rev Date
追加: svn:eol-style
+ native
dfDocTestPlugin/trunk/README
@@ -0,0 +1,90 @@
+= sfDocTestPlugin =
+
+`sfDocTestPlugin` add `symfony doctest` task and `symfony doctesta-all` task to symfony command.
+
+== Install ==
+
+Checkout from Subversion repository as follows:
+
+{{{
+cd plugins
+svn co http://svn.tracfort.jp/svn/dino-symfony/plugins/sfDocTestPlugin
+cd - && symfony cc
+}}}
+
+Or, download or install attached file.
+
+== execute test ==
+
+{{{
+symfony doctest-all frontend
+}}}
+
+or
+
+{{{
+symfony doctest frontend target-file-name.class.php
+}}}
+
+
+
+== implement test ==
+
+All test will be passwd when test has not implemented yet.
+Test cases must write in doc-commment (from /** to */) as follows:
+
+ * plugins/sfDocTestPlugin/doc/emphasis-1.php
+
+{{{
+<?php
+/**
+ * #test
+ * <code>
+ * #is(emphasis("great"),"great!!","add !! emphasised.");
+ * </code>
+ *
+ */
+function emphasis($word){
+ // function has not implemented yet.
+}
+}}}
+
+DocTest expand as test case After `#test`.`#is` is map to `lime_test` class method `->is()`.
+
+Execute this test.
+
+{{{
+symfony doctest frontend emphasis-1.php
+}}}
+
+Result:
+
+[[Image(emphasis-1.png)]]
+
+It fails as you expects.
+
+ * plugins/sfDocTestPlugin/doc/emphasis-2.php
+
+{{{
+<?php
+/**
+ * #test
+ * <code>
+ * #is(emphasis("great"),"great!!","add !! emphasised.");
+ * </code>
+ *
+ */
+function emphasis($word){
+ return $word."!!";
+}
+}}}
+
+It is to be Success.
+
+{{{
+symfony doctest frontend emphasis-2.php
+}}}
+
+[[Image(emphasis-2.png)]]
+
+
属性に変更があったパス: dfDocTestPlugin/trunk/README
___________________________________________________________________
追加: svn:mime-type
+ text/plain
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native