/** * Create PHPUnit test classes with optional methods * * USAGE: * * php artisan generate:test membership * php artisan generate:test membership can_disable_user can_reset_user_password * * @param $args array * @return void */ public function test($args) { if (empty($args)) { echo "Please specify a name for your test class.\n"; return; } $class_name = ucwords(array_shift($args)); $file_path = $this->path('tests'); if (isset($this->should_include_tests)) { $file_path .= 'controllers/'; } $file_path .= strtolower("{$class_name}.test.php"); // Begin building up the file's content Template::new_class($class_name . '_Test', 'PHPUnit_Framework_TestCase'); // add the functions $tests = ''; foreach ($args as $test) { // Don't worry about tests for non-get methods for now. if (strpos($test, ':') !== false) { continue; } if ($test === 'restful') { continue; } // make lower case $func = Template::func("test_{$test}"); // Only if we're generating a resource. if (isset($this->should_include_tests)) { $func = Template::test($class_name, $test); } $tests .= $func; } // add funcs to class Content::add_after('{', $tests); // Create the file $this->write_to_file($file_path, $this->prettify()); }