summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xframework/prado-cli.php78
-rw-r--r--tests/test_tools/unit_tests.php7
2 files changed, 76 insertions, 9 deletions
diff --git a/framework/prado-cli.php b/framework/prado-cli.php
index f8ce826c..8d629140 100755
--- a/framework/prado-cli.php
+++ b/framework/prado-cli.php
@@ -10,12 +10,16 @@ if(!isset($_SERVER['argv']))
//command line options.
$options['create'] = array('c:', 'create=', '<directory>', 'create a new project <directory>');
+$options['tests'] = array('t', 'create-tests', '', 'create unit and function test fixtures');
+
$console = new ConsoleOptions($options, $_SERVER['argv']);
if($console->hasOptions())
{
if($dir = $console->getOption('create'))
create_new_prado_project($dir);
+ if($console->getOptions('tests'))
+ create_test_fixtures($dir);
}
else
{
@@ -51,15 +55,77 @@ function create_new_prado_project($dir)
$htaccessFile = $protectedPath.'/.htaccess';
$defaultPageFile = $pagesPath.'/Home.page';
+ $tests = $basePath.'/tests';
+ $unit_tests = $tests.'/unit';
+ $functional_tests = $tests.'/functional';
+
create_directory($basePath, 0755);
create_directory($assetPath,0777);
create_directory($protectedPath,0755);
create_directory($runtimePath,0777);
create_directory($pagesPath,0755);
+
+ create_directory($tests,0755);
+ create_directory($unit_tests,0755);
+ create_directory($functional_tests,0755);
+
+ create_file($indexFile, render_index_file());
+ create_file($htaccessFile, render_htaccess_file());
+ create_file($defaultPageFile, render_default_page());
+}
+
+function create_test_fixtures($dir)
+{
+ if(strlen(trim($dir)) == 0)
+ return;
- file_put_contents($indexFile, render_index_file());
- file_put_contents($htaccessFile, render_htaccess_file());
- file_put_contents($defaultPageFile, render_default_page());
+ $rootPath = realpath(dirname(trim($dir)));
+ $basePath = $rootPath.'/'.basename($dir);
+
+ $tests = $basePath.'/tests';
+ $unit_tests = $tests.'/unit';
+ $functional_tests = $tests.'/functional';
+
+ create_directory($tests,0755);
+ create_directory($unit_tests,0755);
+ create_directory($functional_tests,0755);
+
+ $unit_test_index = $tests.'/unit.php';
+ $functional_test_index = $tests.'/functional.php';
+
+ create_file($unit_test_index, render_unit_test_fixture());
+ create_file($functional_test_index, render_functional_test_fixture());
+}
+
+function render_unit_test_fixture()
+{
+ $tester = realpath(dirname(__FILE__).'/../tests/test_tools/unit_tests.php');
+return '<?php
+
+include_once "'.$tester.'";
+
+$app_directory = "../protected";
+$test_cases = dirname(__FILE__)."/unit";
+
+$tester = new PradoUnitTester($test_cases, $app_directory);
+$tester->run(new HtmlReporter());
+
+?>';
+}
+
+function render_functional_test_fixture()
+{
+ $tester = realpath(dirname(__FILE__).'/../tests/test_tools/functional_tests.php');
+return '<?php
+
+include_once "'.$tester.'";
+
+$test_cases = dirname(__FILE__)."/functional";
+
+$tester=new PradoFunctionalTester($test_cases);
+$tester->run(new SimpleReporter());
+
+?>';
}
function create_directory($dir, $mask)
@@ -70,6 +136,12 @@ function create_directory($dir, $mask)
chmod($dir, $mask);
}
+function create_file($filename, $content)
+{
+ if(!is_file($filename))
+ file_put_contents($filename, $content);
+}
+
function render_index_file()
{
$framework = realpath(dirname(__FILE__)).'/prado.php';
diff --git a/tests/test_tools/unit_tests.php b/tests/test_tools/unit_tests.php
index b714f452..5c1c95bd 100644
--- a/tests/test_tools/unit_tests.php
+++ b/tests/test_tools/unit_tests.php
@@ -1,7 +1,7 @@
<?php
if(!defined('PRADO_FRAMEWORK'))
- define('PRADO_FRAMEWORK',realpath(dirname(__FILE__).'/../framework'));
+ define('PRADO_FRAMEWORK',realpath(dirname(__FILE__).'/../../framework'));
$TEST_TOOLS = dirname(__FILE__);
@@ -12,11 +12,6 @@ require_once($TEST_TOOLS.'/simpletest/reporter.php');
require_once(PRADO_FRAMEWORK.'/prado.php');
-//set_include_path(get_include_path().";".PRADO_FRAMEWORK);
-
-//error_reporting(E_ALL);
-//restore_error_handler();
-
class TMockApplication extends TApplication
{
public function run()