Skip to content
Browse files

more cleanup

  • Loading branch information...
1 parent a8f6b0e commit d07f2ceb2dca8c0da7b8b1389db86101bbf12b25 @joncutrer joncutrer committed Feb 7, 2012
View
27 README.md
@@ -6,21 +6,18 @@ CakeSpec is a tool to get a CakePHP Project up and running fast using an applica
specification file written in JSON format.
CakeSpec can...
-Pull CakePHP and plugins from git.
-Configure filesystem permissions
-Create PHP classes
-Set configuration variables
-Create your configuration files
-databases.php
-core.php
-routes.php
-run bake commands
-and much more.
-
-To use the tool you will need to first create a cakespec file in JSON format.
-
-In this stage of development you can find some example spec files in the tests/data
-directory.
+* Pull CakePHP and plugins from git.
+* Configure filesystem permissions
+* Create PHP classes
+* Set configuration variables
+* Create your configuration files
+ * databases.php
+ * core.php
+ * routes.php
+* run bake commands
+* and much more.
+
+To use the tool you will need to first create a cakespec file in JSON format. In this stage of development, the spec files structure may change slightly before reach beta. You can get a sneak peak of a spec file by looking in the tests/data directory.
Usage:
View
27 bootstrap.php
@@ -9,20 +9,23 @@
define('CAKESPEC_INDENT', ' ' );
define('CAKESPEC_TAGLINE', 'This file was generated using CakeSpec (http://www.cakespec.com)' );
-require_once( CAKESPEC_DIR . DS . 'libraries/functions.php');
+require_once( CAKESPEC_DIR . DS . 'Inc/functions.php');
defined( 'CAKESPEC_GIT_EXEC' ) or define('CAKESPEC_GIT_EXEC', exec('which git') );
defined( 'CAKESPEC_SVN_EXEC' ) or define('CAKESPEC_SVN_EXEC', exec('which svn') );
-require_once( CAKESPEC_DIR . DS . 'libraries/CakeSpecBuilder.php');
-require_once( CAKESPEC_DIR . DS . 'libraries/CakeSpecLint.php');
-require_once( CAKESPEC_DIR . DS . 'libraries/CakeSpecFilesystem.php');
-require_once( CAKESPEC_DIR . DS . 'libraries/CGClass.php');
-require_once( CAKESPEC_DIR . DS . 'libraries/CGCakeClass.php');
-require_once( CAKESPEC_DIR . DS . 'libraries/CGCakeController.php');
-require_once( CAKESPEC_DIR . DS . 'libraries/CGCakeModel.php');
-require_once( CAKESPEC_DIR . DS . 'libraries/CakeSpecAppConfig.php');
-require_once( CAKESPEC_DIR . DS . 'libraries/CakeSpecAppPlugin.php');
-require_once( CAKESPEC_DIR . DS . 'libraries/CakeSpecAppView.php');
-require_once( CAKESPEC_DIR . DS . 'libraries/CakeSpecAppWebroot.php');
+require_once( CAKESPEC_DIR . DS . 'Lib/ProTemplateCompiler.php');
+
+require_once( CAKESPEC_DIR . DS . 'Inc/CakeSpecBuilder.php');
+require_once( CAKESPEC_DIR . DS . 'Inc/CakeSpecLint.php');
+require_once( CAKESPEC_DIR . DS . 'Inc/CakeSpecFilesystem.php');
+require_once( CAKESPEC_DIR . DS . 'Inc/CGClass.php');
+require_once( CAKESPEC_DIR . DS . 'Inc/CGCakeClass.php');
+require_once( CAKESPEC_DIR . DS . 'Inc/CGCakeController.php');
+require_once( CAKESPEC_DIR . DS . 'Inc/CGCakeModel.php');
+require_once( CAKESPEC_DIR . DS . 'Inc/CakeSpecAppConfig.php');
+require_once( CAKESPEC_DIR . DS . 'Inc/CakeSpecAppPlugin.php');
+require_once( CAKESPEC_DIR . DS . 'Inc/CakeSpecAppView.php');
+require_once( CAKESPEC_DIR . DS . 'Inc/CakeSpecAppWebroot.php');
+
View
0 cakespec.php 100755 → 100644
File mode changed.
View
116 libraries/CGBase.php
@@ -1,116 +0,0 @@
-<?php
-/**
-* All Code Generate Classes should descend from CGBase
-*
-* A property or method added to CGBase will be inherited by all CG* classes
-*/
-class CGBase {
-
- /**
- * Indent some code passed as an array
- *
- * @param mixed $code
- * @param mixed $tabs
- */
- public function indent( $code, $tabs=1 ) {
- $indent = str_repeat( CAKESPEC_INDENT, $tabs );
- $codeArr = explode( "\n", $code );
- if ( $codeArr[count($codeArr)-1] == '') {
- array_pop( $codeArr );
- }
- $newCode = '';
- foreach( $codeArr as $line ) {
- $newCode .= $indent . $line . "\n";
- }
- return $newCode;
- }
-
- /**
- * Indent a string
- *
- * @param mixed $str
- * @param mixed $tabs
- */
- public function indentStr( $str, $tabs=1 ) {
- $indent = str_repeat( CAKESPEC_INDENT, $tabs );
- return $indent . $str;
- }
-
- /**
- * Parse and return code array
- *
- * @param array $codeArr
- */
- protected function genCode( $codeArr ) {
- $code = '';
- if ( is_array( $codeArr ) ) {
- foreach( $codeArr as $line) {
- $code .= $line . "\n";
- }
- } else {
- $code .= $codeArr . "\n";
- }
- return $code;
- }
-
- /**
- * Array generator with auto indention (recursive method)
- *
- * @param mixed $arr
- * @param mixed $depth
- */
- protected function genArray( $arr, $depth=0 ) {
- $depth++;
- if ( !is_array( $arr ) ) { return "'$arr'"; }
-
- //The following code trys to figure out when an array is long or deep
- // and insert breaks and indentions to provide readability.
- if ( count( $arr ) > 3 || $this->array_depth( $arr ) > 1 ) {
- $multiline = true;
- $m = "\n" . $this->indentStr('', $depth );
- $mm = "\n" . $this->indentStr('', $depth - 1 );
- } else {
- $multiline = false;
- $m = '';
- $mm = ' ';
- }
-
- $code = "array( ";
- $sep = '';
- foreach( $arr as $key=>$val ) {
- //when $key is alpha and value is 1 or empty then $key is a string value
- if ( !is_numeric($key) && ( $val == 1 || empty($val) ) ) {
- $code .= $sep . $m . "'$key'";
- } elseif( is_numeric($key) ) { //when $key is numeric then we assume its an array of strings
- $code .= $sep . $m . "'$val'";
- } else { // All over cases are arrays or key=>val members of an array
- $code .= $sep . $m . "'$key' => " . $this->genArray( $val, $depth++ );
- }
- $sep = ', ';
- }
- $code .= $mm . ')';
- return $code;
- }
-
- /**
- * Returns the depth of an array (recursive method)
- *
- * @param mixed $array
- */
- protected function array_depth($array) {
- $max_depth = 1;
-
- foreach ($array as $value) {
- if (is_array($value)) {
- $depth = $this->array_depth($value) + 1;
-
- if ($depth > $max_depth) {
- $max_depth = $depth;
- }
- }
- }
-
- return $max_depth;
- }
-
-} //end CGBase
View
59 libraries/CGCakeClass.php
@@ -1,59 +0,0 @@
-<?php
-require_once('CGClass.php');
-class CGCakeClass extends CGClass {
- protected $name = 'CakeClass';
- protected $vars = array();
- protected $template;
-
- public function __construct( ) {
- parent::__construct();
- }
-
- public function generate( $clsName, $spec ) {
-
- //Generate top of file comments
- $code = $this->genClassCommentBlock( $clsName, $spec );
-
- //Generate code above the class definition
- if ( array_key_exists( 'AppUses', $spec ) ) {
- foreach( $spec['AppUses'] as $key=>$val ) {
- $code .= "App::uses( '$key', '$val' );\n";
- }
- $code .= "\n";
- }
-
- //Generate class definitions
- if ( array_key_exists( 'extends', $spec ) ) {
- $extendsCls = 'extends ' . $spec['extends'];
- } elseif( $clsName == 'App' . $this->name ) {
- $extendsCls = 'extends ' . $this->name;
- } else {
- $extendsCls = 'extends App' . $this->name;
- }
- $code .= "class $clsName $extendsCls {\n";
- $code .= "\n";
-
- //Generate class properties
- if ( array_key_exists( 'properties', $spec ) ) {
- foreach( $spec['properties'] as $name=>$prop ) {
- $code .= $this->indent( $this->genProperty( $name, $prop ) );
- }
- $code .= "\n";
- }
-
- //Generate class methods
- if ( array_key_exists( 'methods', $spec ) ) {
- foreach( $spec['methods'] as $name=>$method ) {
- $code .= $this->indent( $this->genMethod( $name, $method ) );
- $code .= "\n";
- }
- }
-
- //Generate class closing tag
- $code .= "}\n";
- //Return generated code
- return $code;
-
- } //end generate()
-
-} //end CGCakeClass
View
12 libraries/CGCakeController.php
@@ -1,12 +0,0 @@
-<?php
-require_once('CGCakeClass.php');
-class CGCakeController extends CGCakeClass {
- protected $name = 'Controller';
- protected $template;
-
- public function __construct() {
- parent::__construct();
- }
-
-
-}
View
11 libraries/CGCakeModel.php
@@ -1,11 +0,0 @@
-<?php
-include_once('CGCakeClass.php');
-class CGCakeModel extends CGCakeClass {
- protected $name = 'Model';
-
- public function __construct() {
- parent::__construct();
- }
-
-
-}
View
202 libraries/CGClass.php
@@ -1,202 +0,0 @@
-<?php
-include_once('CGBase.php');
-class CGClass extends CGBase {
- protected $name = 'Class';
- protected $template;
-
- public function __construct() {
- //parent::__construct();
- }
-
- public function generate( $clsName, $spec ) {
-
- //Generate top of file comments
- $code = $this->genClassCommentBlock( $clsName, $spec );
-
- //Generate class definitions
- if ( array_key_exists( 'extends', $spec ) ) {
- $extendsCls = 'extends ' . $spec['extends'];
- } else {
- $extendsCls = '';
- }
- $code .= "class $clsName $extendsCls {\n";
- $code .= "\n";
-
- //Generate class properties
- if ( array_key_exists( 'properties', $spec ) ) {
- foreach( $spec['properties'] as $name=>$prop ) {
- $code .= $this->indent( $this->genProperty( $name, $prop ) );
- }
- $code .= "\n";
- }
-
- //Generate class methods
- if ( array_key_exists( 'methods', $spec ) ) {
- foreach( $spec['methods'] as $name=>$method ) {
- $code .= $this->indent( $this->genMethod( $name, $method ) );
- $code .= "\n";
- }
- }
-
- //Generate class closing tag
- $code .= "}\n";
-
- //Return generated code
- return $code;
-
- } //end generate()
-
- /**
- * generate a class comment block
- *
- * @param mixed $name
- * @param mixed $class
- */
- protected function genClassCommentBlock( $name, $class ) {
- $code = "/**\n";
- $code .= "* $name Class\n";
-
- //if ( array_key_exists() ) {
- // $code .="* " . $class;
- //}
- $code .= "*\n";
-
- //if ( array_key_exists('comments', $this->vars ) ) {
- // foreach( $this->vars as $key=>$val ) {
- // $code .= "* @" . $key . $val;
- // }
- //}
-
- $code .= "*\n";
- $code .= "*/\n";
- return $code;
- }
- /**
- * generate a method comment block
- *
- * @param mixed $name
- * @param mixed $method
- * @param mixed $comment
- */
- protected function genMethodCommentBlock( $name, $method ) {
- $code = "/**\n";
- $code .= "* $name Method\n";
- $code .= "*\n";
-
- if ( array_key_exists( 'comment', $method ) ) {
- $code .="* " . $method['comment'] . "\n";
- $code .= "*\n";
- }
-
- if ( array_key_exists('params', $method ) ) {
- foreach ( $method['params'] as $paramName=>$param ) {
- $code .= "* @param mixed";
- if ( preg_match( '/[0-9]+/', $paramName ) ) {
- if ( substr($param, 0, 1) == '$' ) {
- $code .= " " . $param . "\n";
- } else {
- $code .= " $" . $param . "\n";
- }
- } else {
- if ( substr($paramName, 0, 1) == '$' ) {
- $code .= " " . $paramName . "\n";
- } else {
- $code .= " $" . $paramName . "\n";
- }
- }
- }
- }
- $code .= "*/\n";
- return $code;
- }
-
- protected function genProperty( $name, $prop ) {
- $code = '';
- if ( array_key_exists( 'visibility', $prop ) ) {
- $code .= $prop['visibility'] . " ";
- } else {
- $code .= "protected ";
- }
- $code .="\$" . $name;
-
- if ( array_key_exists( 'value', $prop ) ) {
- //echo "\$prop['value'] for $name\n";
- //print_r( $prop['value'] );
- if ( is_array( $prop['value'] ) ) {
- $code .= " = " . $this->genArray( $prop['value'] ) . ";\n";
- } else {
- $code .= " = '" . $prop['value'] . "';\n";
- }
-
- } else {
- $code .=";\n";
- }
- return $code;
- } //end genProperty
-
- protected function genMethod( $name, $method ) {
- $code = '';
- //if comments key is present then override default method comment block
- if ( array_key_exists( 'comments', $method ) ) {
- $code = "//". $method['comments'] . "\n";
- } else {
- //generate method comment block
- $code .= $this->genMethodCommentBlock( $name, $method );
- }
-
- if ( array_key_exists( 'visibility', $method ) ) {
- $code .= $method['visibility'] . " ";
- } else {
- $code .= "protected ";
- }
-
- $code .= 'function ' . $name . '(';
-
- if ( array_key_exists( 'params', $method ) ) {
- $code .= $this->genMethodParams( $method['params'] );
- $code .= " ) {\n";
- } else {
- $code .= ") {\n";
- }
-
- if ( array_key_exists('callParent', $method ) && $method['callParent'] == 'before' ) {
- $code .= $this->indent( "parent::" . $name . "();\n" );
- }
-
- if ( array_key_exists( 'code', $method ) ) {
- $code .= $this->indent( $this->genCode( $method['code'] ) );
- }
- $code .= "\n";
- if ( array_key_exists('callParent', $method ) && $method['callParent'] == 'after' ) {
- $code .= $this->indent( "parent::" . $name . "();\n" );
- }
- if ( array_key_exists('return', $method ) ) {
- $code .= $this->indent( "return " . $method['return'] . ";\n" );
- }
- $code .= "} //end $name\n";
- return $code;
- }
-
- protected function genMethodParams( $params ) {
- $code = ''; $sep = '';
- foreach( $params as $paramName=>$param ) {
- if ( preg_match( '/[0-9]+/', $paramName ) ) {
- $code .= $sep;
- if ( substr($param, 0, 1) == '$' ) {
- $code .= " " . $param;
- } else {
- $code .= " $" . $param;
- }
- } else {
- if ( substr($paramName, 0, 1) == '$' ) {
- $code .= " " . $paramName;
- } else {
- $code .= " $" . $paramName;
- }
- $code .= $sep . " " . $paramName;
- }
- $sep = ',';
- }
- return $code;
- }
-} //end CGClass
View
112 libraries/CakeSpecAppConfig.php
@@ -1,112 +0,0 @@
-<?php
-/**
-* CakeSpecConfig Class
-*
-* Responsible for generating Config specific portions of a CakeSpec build
-*
-*/
-require_once('CakeSpecBase.php');
-class CakeSpecAppConfig extends CakeSpecBase {
-
-
- protected $rules = array(
- 'core.php'=> array(
- 'debug'=> array(
- 'validate'=>'/^[012]$/',
- 'match'=>"/(Configure::write\s*\(\s*'(debug)'\s*,\s*)([0-2]*)(\s*\);)/"
- ),
- 'App.encoding'=> array(
- 'validate'=>false,
- 'match'=>"/(Configure::write\s*\(\s*'(App\.encoding)'\s*,\s*)'(UTF-8)('\s*\);)/"
- ),
- 'Routing.prefixes'=>array(
- 'validate'=>false,
- 'match'=>"/\\/\\/(Configure::write\s*\(\s*'(Routing\.prefixes)'\s*,\s*)(array\('admin'\))(\s*\);)/"
- ),
- 'Cache.disable'=>array(
- 'validate'=>false,
- 'match'=>"/\\/\\/(Configure::write\s*\(\s*'(Cache\.disable)'\s*,\s*)(true)(\s*\);)/"
- ),
- 'Cache.check'=>array(
- 'validate'=>false,
- 'match'=>"/\\/\\/(Configure::write\s*\(\s*'(Cache\.check)'\s*,\s*)(true)(\s*\);)/"
- ),
- 'LOG_ERROR'=> array(
- 'validate'=>'/^[2]$/',
- 'match'=>"/(define\(\s*'(LOG_ERROR)'\s*,\s*)([0-2]*)(\s*\);)/"
- ),
- 'Security.level'=> array(
- 'validate'=>'/^(low|medium|high)$/',
- 'match'=>"/(Configure::write\s*\(\s*'(Security\.level)'\s*,\s*')(medium)('\s*\);)/"
- ),
- 'Security.salt'=> array(
- 'validate'=>'/^[A-Za-z0-9]+$/',
- 'match'=>"/(Configure::write\s*\(\s*'(Security\.salt)'\s*,\s*')([A-Za-z0-9]*)('\s*\);)/"
- ),
- 'Security.cipherSeed'=> array(
- 'validate'=>'/^[0-9]+$/',
- 'match'=>"/(Configure::write\s*\(\s*'(Security\.cipherSeed)'\s*,\s*')([0-9]*)('\s*\);)/"
- ),
- 'Asset.timestamp'=>array(
- 'validate'=>false,
- 'match'=>"/\\/\\/(Configure::write\s*\(\s*'(Asset\.timestamp)'\s*,\s*)(true)(\s*\);)/"
- ),
- 'Asset.filter.css'=>array(
- 'validate'=>false,
- 'match'=>"/\\/\\/(Configure::write\s*\(\s*'(Asset\.filter\.css)'\s*,\s*')(css\.php)('\s*\);)/"
- ),
- 'Asset.filter.js'=>array(
- 'validate'=>false,
- 'match'=>"/\\/\\/(Configure::write\s*\(\s*'(Asset\.filter\.js)'\s*,\s*')(custom_javascript_output_filter\.php)('\s*\);)/"
- ),
- 'Acl.classname'=> array(
- 'validate'=>false,
- 'match'=>"/(Configure::write\s*\(\s*'(Acl\.classname)'\s*,\s*')([A-Za-z]*)('\s*\);)/"
- ),
- 'Acl.database'=> array(
- 'validate'=>false,
- 'match'=>"/(Configure::write\s*\(\s*'(Acl\.database)'\s*,\s*')([a-z]*)('\s*\);)/"
- ),
- 'date_default_timezone_set'=> array(
- 'validate'=>false,
- 'match'=>"/\\/\\/((date_default_timezone_set)\s*\(\s*')(UTC)('\s*\);)/"
- )
- ) //end $rules['core.php']
- );
-
- public function __construct( ) {
-
- parent::__construct();
- }
-
- protected function replaceWithVariableCallback( $matches ) {
- return $matches[1] . '{$' . $matches[2] . '}' . $matches[4];
- }
-
-
- public function prepareTemplate( $filename, $src, $vars, $rules ) {
- $tmpl = $src;
- foreach( $vars as $key=>$val ) {
- if ( array_key_exists($key, $this->rules[$filename] ) ) {
- $tmpl = preg_replace_callback(
- $this->rules[$filename][$key]['match'],
- 'CakeSpecAppConfig::replaceWithVariableCallback',
- $tmpl
- );
- }
- }
- return $tmpl;
- }
-
- public function compileTemplate( $filename, $template, $vars ) {
- $compiled_template = $template;
- foreach( $vars as $key=>$val ) {
- $compiled_template = preg_replace(
- "/{\\$" . preg_quote($key) . "}/",
- $val,
- $compiled_template
- );
- }
- return $compiled_template;
- }
-}
View
15 libraries/CakeSpecAppPlugin.php
@@ -1,15 +0,0 @@
-<?php
-/**
-* CakeSpecPlugin Class
-*
-* Responsible for generating Plugin specific portions of a CakeSpec build
-*
-*/
-require_once('CakeSpecBase.php');
-class CakeSpecAppPlugin extends CakeSpecBase {
-
- public function __construct() {
- parent::__construct();
- }
-
-}
View
15 libraries/CakeSpecAppView.php
@@ -1,15 +0,0 @@
-<?php
-/**
-* CakeSpecView Class
-*
-* Responsible for generating View specific portions of a CakeSpec build
-*
-*/
-require_once('CakeSpecBase.php');
-class CakeSpecAppView extends CakeSpecBase {
-
- public function __construct() {
- parent::__construct();
- }
-
-}
View
15 libraries/CakeSpecAppWebroot.php
@@ -1,15 +0,0 @@
-<?php
-/**
-* CakeSpecWebroot Class
-*
-* Responsible for generating webroot specific portions of a CakeSpec build
-*
-*/
-require_once('CakeSpecBase.php');
-class CakeSpecAppWebroot extends CakeSpecBase {
-
- public function __construct() {
- parent::__construct();
- }
-
-}
View
43 libraries/CakeSpecBase.php
@@ -1,43 +0,0 @@
-<?php
-/**
- CakeSpecBase class
-*/
-
-class CakeSpecBase {
- public function __construct( ) {
- defined('CAKESPEC_DEBUG') or define( 'CAKESPEC_DEBUG', 0);
- }
-
- protected function exec( $cmd ) {
- cakespec_debug( 'Executing ' . $cmd );
- return exec( $cmd );
- }
-
- protected function checkDependencies() {
- //TODO Check basic dependencies of CakeSpecBuilder
- $pass = true;
- $depErrors = array();
- if ( !function_exists('json_decode') ) {
- $pass = false;
- $depErrors[] = 'json_decode function not present, install PHP json extension';
- }
-
- if ( !$this->gitExec = exec('which git') ) {
- $pass = false;
- $depErrors[] = "git not installed: \n try sudo apt-get install git\n or sudo yum install git";
- }
-
- if ( !$this->svnExec = exec('which svn') ) {
- $pass = false;
- $depErrors[] = "svn not installed: \n try sudo apt-get install subversion\n or sudo yum install subversion";
- }
-
- if ( $pass === false ) {
- echo "CakeSpec dependencies not found\n";
- foreach( $depErrors as $error ) {
- echo " " . $error . "\n";
- }
- }
- return $pass;
- }
-}
View
342 libraries/CakeSpecBuilder.php
@@ -1,342 +0,0 @@
-<?php
-/**
- CakeSpecBuilder class
-*/
-include_once('CakeSpecBase.php');
-
-class CakeSpecBuilder extends CakeSpecBase {
-
- protected $CakeSpec; //CakeSpec object, set in ::__construct()
- protected $path; //path to specfile
-
- /**
- * Class Constructor
- *
- */
- public function __construct( $specfile ) {
-
- //Define Constants if not already defined
- defined('CAKESPEC_DEBUG') or define( 'CAKESPEC_DEBUG', 0);
-
- //Check CakeSpec dependencies
- if (!defined('CAKESPEC_NODEP') ) {
- $this->checkDependencies();
- }
-
- //set ::path
- if ( substr( $specfile, 0 ,1) == '/' ) {
- $this->path = dirname( $specfile ) . DS;
- } else {
- $this->path = dirname( getcwd() . DS . $specfile ) . DS;
- }
-
- //if specfile does not exist on disk, exit(1)
- if ( !file_exists( $specfile ) ) {
- cakespec_out( 'File not found: ' . $specfile );
- exit(1);
- }
-
- //read in specfile from disk
- cakespec_debug( 'Reading ' . $specfile .", " . filesize($specfile) . " bytes" );
- $json = file_get_contents( $specfile );
-
- //decode specfile json, if parse error exit(1)
- if ( !$spec = json_decode( $json, true ) ) {
- cakespec_out( 'Invalid spec file' );
- cakespec_out( 'Try running cakespec with the --lint flag' );
- cakespec_out( );
- exit(1);
- }
- //set ::CakeSpec
- $this->CakeSpec = $spec['CakeSpec'];
- }
-
- /**
- *
- *
- */
- public function build() {
- cakespec_out( 'Building ' . $this->CakeSpec['App']['name'] );
- cakespec_out('Please be patient, this could take a few minutes', false);
- $this->processCake();
- cakespec_out('.', false); //progress
- $this->processAppConfig();
- cakespec_out('.', false); //progress
- $this->processAppConsole();
- cakespec_out('.', false); //progress
- $this->processAppPlugin();
- cakespec_out('.', false); //progress
- $this->processAppVendor();
- cakespec_out('.', false); //progress
- $this->processAppController();
- cakespec_out('.', false); //progress
- $this->processAppModel();
- cakespec_out('.', false); //progress
- $this->processAppView();
- cakespec_out('.', false); //progress
- $this->processAppWebroot();
- cakespec_out('.', false); //progress
- cakespec_out('done'); //done
- }
-
- /**
- *
- *
- */
- protected function processCake() {
- if ( !array_key_exists( 'Cake', $this->CakeSpec ) ) {
- return false;
- }
-
- cakespec_debug( 'Building Cake' );
- if ( file_exists( $this->path . $this->CakeSpec['App']['name'] ) ) {
- return;
- }
- //Clone from github repo
- if ( array_key_exists( 'git', $this->CakeSpec['Cake'] ) ) {
- cakespec_debug( 'Cloning CakePHP from github' );
- $this->exec( CAKESPEC_GIT_EXEC . ' clone -q ' . $this->CakeSpec['Cake']['git']['repo'] . ' ' . $this->path . $this->CakeSpec['App']['name'] );
-
- //Show a little progress
- cakespec_out('.', false);
-
- //Switch to specified tag
- if ( array_key_exists( 'tag', $this->CakeSpec['Cake']['git'] ) ) {
- chdir( $this->path . $this->CakeSpec['App']['name'] );
- cakespec_debug( CAKESPEC_GIT_EXEC . ' checkout ' . $this->CakeSpec['Cake']['git']['tag'] );
- $this->exec( CAKESPEC_GIT_EXEC . ' checkout -q ' . $this->CakeSpec['Cake']['git']['tag'] );
- }
- //Show a little progress
- cakespec_out('.', false);
-
- }
-
- //Process any filesystem directives
- if ( array_key_exists( 'filesystem', $this->CakeSpec['Cake'] ) ) {
- $this->processFilesystemDirectives(
- $this->path . $this->CakeSpec['App']['name'],
- $this->CakeSpec['Cake']['filesystem']
- );
- }
- }
-
- /**
- *
- *
- */
- protected function processAppConfig() {
- if ( !array_key_exists( 'Config', $this->CakeSpec['App'] ) ) {
- return false;
- }
- cakespec_debug( 'Building App/Config' );
-
- $CConfig = new CakeSpecAppConfig( );
- $configPath = $this->path . $this->CakeSpec['App']['name'] . DS . 'app' . DS . 'Config';
-
- if ( array_key_exists( 'core.php', $this->CakeSpec['App']['Config'] ) ) {
- cakespec_debug( 'Building App/Config/core.php' );
- $prepared_template = $CConfig->prepareTemplate(
- 'core.php',
- file_get_contents($configPath . DS . 'core.php'),
- $this->CakeSpec['App']['Config']['core.php']
- );
-
- $code = $CConfig->compileTemplate(
- 'core.php',
- $prepared_template,
- $this->CakeSpec['App']['Config']['core.php']
- );
- echo $code;
- }
- /**
- if ( array_key_exists( 'bootstrap.php', $this->CakeSpec['App']['Config'] ) ) {
- cakespec_debug( 'Building App/Config/bootstrap.php' );
- $code = $CConfig->bootstrap( $this->CakeSpec['App']['Config']['bootstrap.php'] );
- echo $code;
- }
-
- if ( array_key_exists( 'database.php', $this->CakeSpec['App']['Config'] ) ) {
- cakespec_debug( 'Building App/Config/database.php' );
- $CConfig->database( $this->CakeSpec['App']['Config']['database.php'] );
- }
-
- if ( array_key_exists( 'email.php', $this->CakeSpec['App']['Config'] ) ) {
- cakespec_debug( 'Building App/Config/email.php' );
- $CConfig->email( $this->CakeSpec['App']['Config']['email.php'] );
- }
-
- if ( array_key_exists( 'routes.php', $this->CakeSpec['App']['Config'] ) ) {
- cakespec_debug( 'Building App/Config/routes.php' );
- $CConfig->routes( $this->CakeSpec['App']['Config']['routes.php'] );
-
- }
- */
-
- }
-
- /**
- *
- *
- */
- protected function processAppConsole() {
- if ( !array_key_exists( 'Console', $this->CakeSpec['App'] ) ) {
- return false;
- }
-
- cakespec_debug( 'Building App/Console' );
- }
-
- /**
- *
- *
- */
- protected function processAppController() {
- if ( !array_key_exists( 'Controller', $this->CakeSpec['App'] ) ) {
- return false;
- }
-
- cakespec_debug( 'Building App/Controller' );
- $Controller = $this->CakeSpec['App']['Controller'];
- unset( $Controller['Component'] );
-
- foreach( $Controller as $clsName=>$obj ) {
- cakespec_debug( 'Building App/Controller/' . $clsName . '.php' );
- $cg = new CGCakeController();
- $code = "<?php\n";
- $code .= $cg->generate( $clsName, $obj );
- $code .= $this->tagline();
-
- cakespec_debug( 'Writing ' . $clsName . '.php to disk.');
- file_put_contents(
- $this->path . $this->CakeSpec['App']['name'] . DS . 'app' . DS . 'Controller' . DS . $clsName . '.php',
- $code
- );
- $code='';
- } //end foreach
-
- $this->processAppControllerComponent();
-
- }
-
- /**
- *
- *
- */
- protected function processAppControllerComponent() {
- if ( !array_key_exists( 'Component', $this->CakeSpec['App']['Controller'] ) ) {
- return false;
- }
-
- cakespec_debug( 'Building App/Controller/Component' );
- //print_r( $this->CakeSpec['App']['Controller']['Component'] );
- }
-
- /**
- *
- *
- */
- protected function processAppModel() {
- if ( !array_key_exists( 'Model', $this->CakeSpec['App'] ) ) {
- return false;
- }
-
- cakespec_debug( 'Building App/Model' );
- $Model = $this->CakeSpec['App']['Model'];
- unset( $Model['Behavior'] );
-
- foreach( $Model as $clsName=>$obj ) {
- cakespec_debug( 'Building App/Model/' . $clsName . '.php' );
- $cg = new CGCakeModel();
- $code = "<?php\n";
- $code .= $cg->generate( $clsName, $obj );
- $code .= $this->tagline();
-
- cakespec_debug( 'Writing ' . $clsName . '.php to disk.');
- file_put_contents(
- $this->path . $this->CakeSpec['App']['name'] . DS . 'app' . DS . 'Model' . DS . $clsName . '.php',
- $code
- );
- $code='';
- } //end foreach
-
- $this->processAppModelBehavior();
- }
-
- /**
- *
- *
- */
- protected function processAppModelBehavior() {
- if ( !array_key_exists( 'Behavior', $this->CakeSpec['App']['Model'] ) ) {
- return false;
- }
-
- cakespec_debug( 'Building App/Model/Behavior' );
-
- }
-
- /**
- *
- *
- */
- protected function processAppPlugin() {
- cakespec_debug( 'Building App/Plugin' );
- }
-
- /**
- *
- *
- */
- protected function processAppVendor() {
- cakespec_debug( 'Building App/Vendor' );
- }
-
- /**
- *
- *
- */
- protected function processAppView() {
- cakespec_debug( 'Building App/View' );
- }
-
- /**
- *
- *
- */
- protected function processAppViewHelper() {
- cakespec_debug( 'Building App/View/Helper' );
- }
-
- /**
- *
- *
- */
- protected function processAppWebroot() {
- cakespec_debug( 'Building App/webroot' );
- }
-
- protected function tagline() {
- if ( !defined('CAKESPEC_NOTAGLINE') ) {
- return "\n/** " . CAKESPEC_TAGLINE . " */";
- }
- }
-
- protected function processFilesystemDirectives( $path, $directives ) {
- cakespec_debug( 'Processing Filesystem directives on ' . $path );
- $csfs = new CakeSpecFilesystem( $path );
- foreach ( $directives as $cmd=>$args ) {
- switch( $cmd ) {
- case 'chmod':
- $csfs->$cmd( $args );
- break;
- case 'chown':
- $csfs->$cmd( $args );
- break;
- default:
- cakespec_debug( 'Unknown filesystem directive ' . $cmd );
- }
- }
-
- }
-
-} //end CakeSpecBuilder
View
117 libraries/CakeSpecFilesystem.php
@@ -1,117 +0,0 @@
-<?php
-/**
-* FileSystem operations
-* chown and chmod
-*/
-class CakeSpecFilesystem {
- protected $basePath = '.';
-
- public function __construct( $path='' ) {
- // IMPORTANT
- // We must be very careful with paths we will accept here
- if ( !empty($path) ) {
- $this->basePath = $path;
- }
- } //enc __construct
-
- /**
- * Process a chown directive
- *
- * @param mixed $file
- * @param mixed $args
- */
- public function chown( $args ) {
- if ( !array_key_exists( 'user', $args ) || !array_key_exists( 'group', $args ) ) {
- return false;
- }
-
- if ( array_key_exists( 'recursive', $args ) && $args['recursive'] == true ) {
- cakespec_debug( 'Filesystem: chown -R ' . $args['user'] . ":" . $args['group'] . $this->basePath );
- return $this->chownr( $this->basePath, $args['user'], $args['group'] );
- } else {
- cakespec_debug( 'Filesystem: chown ' . $args['user'] . ":" . $args['group'] . $this->basePath . ' ' );
- $result = false;
- $result = chown( $this->basePath , $args['user'] );
- return $result and chgrp( $this->basePath, $args['group'] );
- }
- } //end chown
-
- /**
- * Process a chmod directive
- *
- * @param mixed $file
- * @param mixed $args
- */
- public function chmod( $args ) {
- if ( !array_key_exists( 'mask', $args ) || !preg_match('/^0?[0-7]{3}$/', $args['mask'] ) ) {
- return false;
- }
- if ( array_key_exists( 'recursive', $args ) && $args['recursive'] == true ) {
- cakespec_debug( 'Filesystem: chmod -R ' . $this->basePath . ' ' . $args['mask'] );
- return $this->chmodr( $this->basePath , $args['mask'] );
- } else {
- cakespec_debug( 'Filesystem: chmod ' . $this->basePath . ' ' . $args['mask'] );
- return chmod( $this->basePath , $args['mask'] );
- }
- } //end chmod
-
- /**
- * Recursive chmod
- *
- * @param mixed $path
- * @param mixed $filemode
- */
- protected function chmodr($path, $filemode) {
- if (!is_dir($path))
- return chmod($path, $filemode);
-
- $dh = opendir($path);
- while (($file = readdir($dh)) !== false) {
- if($file != '.' && $file != '..') {
- $fullpath = $path.'/'.$file;
- if(is_link($fullpath))
- return FALSE;
- elseif(!is_dir($fullpath) && !chmod($fullpath, $filemode))
- return FALSE;
- elseif(!$this->chmodr($fullpath, $filemode))
- return FALSE;
- }
- }
-
- closedir($dh);
-
- if(chmod($path, $filemode))
- return TRUE;
- else
- return FALSE;
- } //end chmodr
-
- /**
- * Recursive chown
- *
- * @param mixed $path2dir
- * @param mixed $uid
- * @param mixed $gid
- */
- protected function chownr($mypath, $uid, $gid) {
- $d = opendir ($mypath) ;
- while(($file = readdir($d)) !== false) {
- if ($file != "." && $file != "..") {
-
- $typepath = $mypath . "/" . $file ;
-
- //print $typepath. " : " . filetype ($typepath). "<BR>" ;
- if (filetype ($typepath) == 'dir') {
- $this->chownr($typepath, $uid, $gid);
- }
- chown($typepath, $uid);
- chgrp($typepath, $gid);
-
- }
- }
- chown($mypath, $uid);
- chgrp($mypath, $gid);
-
- } //end chownr
-
-}
View
212 libraries/CakeSpecLint.php
@@ -1,212 +0,0 @@
-<?php
-/**
- CakeSpecLint class
-*/
-require_once('CakeSpecBase.php');
-
-class CakeSpecLint extends CakeSpecBase {
-
- protected $CakeSpec;
- protected $stopOnError;
- protected $errorCount = 0;
- protected $errors = array();
-
- public function __construct( $specfile, $stopOnError=true ) {
-
- $this->stopOnError = $stopOnError;
- defined('CAKESPEC_DEBUG') or define( 'CAKESPEC_DEBUG', 0);
-
- //Check CakeSpec dependencies
- if (!defined('CAKESPEC_NODEP') ) {
- $this->checkDependencies();
- }
-
- //set ::path
- if ( substr( $specfile, 0 ,1) == '/' ) {
- $this->path = dirname( $specfile ) . DS;
- } else {
- $this->path = dirname( getcwd() . DS . $specfile ) . DS;
- }
-
- if ( !file_exists( $specfile ) ) {
- $this->addError( "File not found: " . $specfile );
- if ( $this->stopOnError ) { return false; }
- }
-
- if ( !$spec = json_decode( file_get_contents( $specfile ), true ) ) {
- switch (json_last_error()) {
- case JSON_ERROR_NONE:
- break;
- case JSON_ERROR_DEPTH:
- $this->addError( "JSON Error: Maximum stack depth exceeded" );
- break;
- case JSON_ERROR_STATE_MISMATCH:
- $this->addError( "JSON Error: Underflow or the modes mismatch" );
- break;
- case JSON_ERROR_CTRL_CHAR:
- $this->addError( "JSON Error: Unexpected control character found" );
- break;
- case JSON_ERROR_SYNTAX:
- $this->addError( "JSON Error: Syntax error, malformed JSON" );
- break;
- case JSON_ERROR_UTF8:
- $this->addError( "JSON Error: Malformed UTF-8 characters, possibly incorrectly encoded" );
- break;
- default:
- $this->addError( "JSON Error: Unknown error" );
- break;
- }
-
- if ( $this->errorCount > 0 ) {
- if ( $this->stopOnError ) { return false; }
- }
- }
-
- if ( !array_key_exists('CakeSpec', $spec ) ) {
- $this->addError( "CakeSpec object missing, { \"CakeSpec\": { /* spec */ } }" );
- if ( $this->stopOnError ) { return false; }
- }
-
- $this->CakeSpec = $spec['CakeSpec'];
- $this->lintApp();
- $this->lintCake();
- $this->lintAppConfig();
- $this->lintAppController();
- $this->lintAppLib();
- $this->lintAppModel();
- $this->lintAppPlugin();
- $this->lintAppTest();
- $this->lintAppTmp();
- $this->lintAppView();
- $this->lintAppWebroot();
-
- return true;
-
- }
-
- /**
- * getter for Error Count
- *
- */
- public function getErrorCount() {
- return $this->errorCount;
- }
-
- /**
- * getter for last error
- *
- */
- public function getLastError() {
- $errtmp = $this->errors;
- return array_pop( $errtmp );
- }
-
- /**
- * getter for error text
- *
- * @param mixed $id
- */
- public function getError( $id=null ) {
- if ( is_null( $id ) ) {
- return $this->getErrors();
- }
- if ( array_key_exists( $id, $this->errors ) ) {
- return $this->errors[$id];
- }
- return false;
- }
-
- /**
- * getter for error text
- *
- * @param mixed $id
- */
- public function getErrors( ) {
- if ( $this->errorCount > 0 ) {
- return $this->errors;
- }
- return false;
- }
-
- /**
- * Pushes error onto errors array and increments errorCount
- *
- * @param mixed $errStr
- */
- protected function addError( $errStr ) {
- if (!empty( $errStr ) ) {
- $this->errors[] = $errStr;
- $this->errorCount++;
- }
- }
-
- protected function lintApp() {
- //cakespec_debug( $this->CakeSpec['App']['name'] );
-
- if ( !$this->isValidFilename( $this->CakeSpec['App']['name'] ) ) {
- $this->addError( "CakeSpec.App.name contains illegal characters" );
- if ( $this->stopOnError ) { return false; }
- }
- }
- protected function lintCake() {
- cakespec_debug( 'Checking CakeSpec.Cake' );
-
- if ( !array_key_exists( 'Cake', $this->CakeSpec ) ) {
- $this->addError( "CakeSpec.Cake object missing" );
- if ( $this->stopOnError ) { return false; }
- }
-
- if ( !array_key_exists( 'git', $this->CakeSpec['Cake'] ) ) {
- $this->addError( "CakeSpec.Cake.git object missing" );
- if ( $this->stopOnError ) { return false; }
- }
-
- if ( !array_key_exists( 'repo', $this->CakeSpec['Cake']['git'] ) ) {
- $this->addError( "CakeSpec.Cake.git.repo member missing" );
- if ( $this->stopOnError ) { return false; }
- }
-
- }
- protected function lintAppConfig() {
-
- }
-
- protected function lintAppController() {
-
- }
-
- protected function lintAppLib() {
-
- }
-
- protected function lintAppModel() {
-
- }
-
- protected function lintAppPlugin() {
-
- }
-
- protected function lintAppTest() {
-
- }
-
- protected function lintAppTmp() {
-
- }
-
- protected function lintAppView() {
-
- }
-
- protected function lintAppWebroot() {
-
- }
-
- protected function isValidFilename( $str ) {
- if ( preg_match( '/^\./', $str ) ) {
- return false;
- }
- return !preg_match( '/[\t\\\?{}\:\;\/\*]+/', $str );
- }
-}
View
72 libraries/functions.php
@@ -1,72 +0,0 @@
-<?php
-
-
-function cakespec_debug( $data ) {
- if ( !defined( 'CAKESPEC_DEBUG' ) ) {
- return;
- }
-
- if ( CAKESPEC_DEBUG > 0 ) {
- cakespec_out( ">>>DEBUG: " . $data );
- }
-}
-
-function cakespec_out( $data='', $newline=true ) {
- if ( !defined( 'CAKESPEC_QUIET' ) ) {
- return;
- }
-
- if ( CAKESPEC_QUIET < 1 ) {
- echo $data;
- if ( $newline === true ) {
- echo "\n";
- }
- }
-}
-
-function cakespec_getargs( $argv ) {
- foreach( $argv as $key=>$arg ) {
- if ( substr( $arg, 0, 1) != '-' ) {
- $args[] = $arg;
- }
- }
- return $args;
-
-}
-
-function cakespec_checkDependencies() {
- //TODO Check basic dependencies of CakeSpecBuilder
- $pass = true;
- $depErrors = array();
- if ( !function_exists('json_decode') ) {
- $pass = false;
- $depErrors[] = 'json_decode function not present, install PHP json extension';
- }
-
- if ( !exec('which git') ) {
- $pass = false;
- $depErrors[] = "git not installed: \n try sudo apt-get install git\n or sudo yum install git";
- }
-
- if ( !exec('which svn') ) {
- $pass = false;
- $depErrors[] = "svn not installed: \n try sudo apt-get install subversion\n or sudo yum install subversion";
- }
-
- if ( $pass === false ) {
- echo "CakeSpec dependencies not found\n";
- foreach( $depErrors as $error ) {
- echo " " . $error . "\n";
- }
- exit(1);
- }
- return $pass;
-}
-
-
-if ( !function_exists('__') ) {
- function __( $message ) {
- return $message;
- }
-}
-
View
110 tests/CG/CGBaseTests.php
@@ -1,110 +0,0 @@
-<?php
-/**
-*
-*
-*/
-require_once( CAKESPEC_TEST_DIR . DS .'../libraries/CGBase.php' );
-require_once('Classes/CGBaseInternals.php');
-require_once( 'CGTestCase.php' );
-class CGBaseTests extends CGTestCase {
-
- protected $tClass;
- protected $tiClass;
-
- function SetUp() {
- $this->tClass = new CGBase();
- $this->tiClass = new CGBaseInternals();
-
- }
-
- function testIndent() {
- $code = "echo 'Hello World';\n";
- $expected = " echo 'Hello World';\n";
- $this->assertEquals( $expected, $this->tClass->indent( $code ) );
-
- $code = "echo 'Hello World';\n";
- $code .= "\$a = 1 + 2;";
- $expected = " echo 'Hello World';\n";
- $expected .= " \$a = 1 + 2;\n";
- $this->assertEquals( $expected, $this->tClass->indent( $code ) );
-
- $code = "echo 'Hello World';\n";
- $code .= "\$a = 1 + 2;";
- $expected = " echo 'Hello World';\n";
- $expected .= " \$a = 1 + 2;\n";
- $this->assertEquals( $expected, $this->tClass->indent( $code, 2 ) );
-
- }
-
- function testIndentStr() {
- $this->assertEquals( ' hello world', $this->tiClass->indentStr('hello world') );
- $this->assertEquals( ' hello world', $this->tiClass->indentStr('hello world', 2) );
- $this->assertEquals( ' hello world', $this->tiClass->indentStr('hello world', 3) );
- }
-
- function testGenCode() {
- $arr = array(
- 'echo "Hello World";'
- );
-
- $expected = "echo \"Hello World\";\n";
- $this->assertEquals( $expected, $this->tiClass->genCode( $arr ) );
-
- $arr = array(
- 'echo "Hello World";',
- '$a = 1 + 3;',
- 'echo $a;',
- '$b = $a - 4;',
- 'echo $b;',
- );
-
- $expected = "echo \"Hello World\";\n\$a = 1 + 3;\necho \$a;\n\$b = \$a - 4;\necho \$b;\n";
- $this->assertEquals( $expected, $this->tiClass->genCode( $arr ) );
-
- }
-
- function testGenArray() {
-
- $arr = array( 'hello', 'world' );
- $this->assertEquals( "array( 'hello', 'world' )", $this->tiClass->genArray( $arr ) );
-
- $arr = array( 'hello'=>'world', 'world'=>'hello' );
- $this->assertEquals( "array( 'hello' => 'world', 'world' => 'hello' )", $this->tiClass->genArray( $arr ) );
-
- $arr = array( 'hello'=>'world', 'nested'=>array( 'hello'=>'world') );
- $expected = "array( 'hello' => 'world', 'nested' => array( 'hello' => 'world' ))";
- $this->assertEquals( $expected , str_replace( "\n", "", $this->tiClass->genArray( $arr ) ) );
-
- $arr = array( '1','2','3' );
- $this->assertEquals( "array( '1', '2', '3' )", $this->tiClass->genArray( $arr ) );
-
- $arr = array( 1=>"string",2=>"two",3=>"three" );
- $this->assertEquals( "array( 'string', 'two', 'three' )", $this->tiClass->genArray( $arr ) );
-
- $arr = array( 1,2,3 );
- $this->assertEquals( "array( '1', '2', '3' )", $this->tiClass->genArray( $arr ) );
-
- $arr = array( 5=>1,10=>'string',15=>3 );
- $this->assertEquals( "array( '1', 'string', '3' )", $this->tiClass->genArray( $arr ) );
-
- }
-
-
- function testArrayDepth() {
- $arr = array( 1, 2, 3, 4);
- $this->assertEquals( 1, $this->tiClass->array_depth( $arr ) );
-
- $arr = array( array(1,2,3), array(1,2,3), array(1,2,3) );
- $this->assertEquals( 2, $this->tiClass->array_depth( $arr ) );
-
- $arr = array( array( array() ), );
- $this->assertEquals( 3, $this->tiClass->array_depth( $arr ) );
-
- $arr = array( array( array( array() ) ), );
- $this->assertEquals( 4, $this->tiClass->array_depth( $arr ) );
-
- $arr = array( array( array( array( array() ) ) ), );
- $this->assertEquals( 5, $this->tiClass->array_depth( $arr ) );
- }
-
-}
View
13 tests/CG/CGCakeClassTests.php
@@ -1,13 +0,0 @@
-<?php
-/**
-*
-*
-*/
-
-require_once( CAKESPEC_TEST_DIR . DS . '../libraries/CGCakeClass.php' );
-require_once( 'CGTestCase.php' );
-class CGCakeClassTests extends CGTestCase {
-
-
-
-}
View
27 tests/CG/CGCakeControllerTests.php
@@ -1,27 +0,0 @@
-<?php
-/**
-*
-*
-*/
-require_once( CAKESPEC_TEST_DIR . DS . '../libraries/CGCakeController.php' );
-require_once( 'CGTestCase.php' );
-class CGCakeControllerTests extends CGTestCase {
-
- protected $tClass;
- protected $teClass;
-
- function SetUp() {
- $this->tClass = new CGCakeController();
- }
-
- function testGenerate() {
- $cName = 'MyClass';
- $cArr = array(
- 'AppUses' => array( 'AppController'=>'Controller' ),
- 'visibility'=>'public'
- );
- $expected = "/**\n* MyClass Class\n*\n*\n*/\nApp::uses( 'AppController', 'Controller' );\n\nclass MyClass extends AppController {\n\n}\n";
- $this->assertEquals( $expected, $this->tClass->generate( $cName, $cArr ) );
- }
-
-}
View
27 tests/CG/CGCakeModelTests.php
@@ -1,27 +0,0 @@
-<?php
-/**
-*
-*
-*/
-require_once( CAKESPEC_TEST_DIR . DS . '../libraries/CGCakeModel.php' );
-require_once( 'CGTestCase.php' );
-class CGCakeModelTests extends CGTestCase {
-
- protected $tClass;
- protected $tiClass;
-
- function SetUp() {
- $this->tClass = new CGCakeModel();
- }
-
- function testGenerate() {
- $cName = 'MyClass';
- $cArr = array(
- 'AppUses' => array( 'AppModel'=>'Model' ),
- 'visibility'=>'public'
- );
- $expected = "/**\n* MyClass Class\n*\n*\n*/\nApp::uses( 'AppModel', 'Model' );\n\nclass MyClass extends AppModel {\n\n}\n";
- $this->assertEquals( $expected, $this->tClass->generate( $cName, $cArr ) );
- }
-
-}
View
194 tests/CG/CGClassTests.php
@@ -1,194 +0,0 @@
-<?php
-/**
-*
-*
-*/
-require_once( CAKESPEC_TEST_DIR . DS .'../libraries/CGClass.php' );
-require_once( 'CGTestCase.php' );
-require_once( 'Classes/CGClassInternals.php' );
-class CGClassTests extends CGTestCase {
-
- protected $tClass;
- protected $tiClass;
-
- function SetUp() {
- $this->tClass = new CGClass();
- $this->tiClass = new CGClassInternals();
- }
-
- function testGenerate() {
- $cName = 'MyClass';
- $cArr = array(
- 'visibility'=>'public'
- );
- $expected = "/**\n* MyClass Class\n*\n*\n*/\nclass MyClass {\n\n}\n";
- $this->assertEquals( $expected, $this->tClass->generate( $cName, $cArr ) );
- }
-
- function testGenClassCommentBlock() {
- $cName = 'MyClass';
- $cArr = array(
-
- );
- $expected = "/**\n* MyClass Class\n*\n*\n*/\n";
- $this->assertEquals( $expected, $this->tiClass->genClassCommentBlock( $cName, $cArr ) );
-
- }
-
- function testGenMethodCommentBlock() {
- //Test Method comment block
- $mName = 'myMethod';
- $mArr = array();
- $mComment = '';
- $expected = "/**\n* myMethod Method\n*\n*/\n";
- $this->assertEquals(
- $expected,
- $this->tiClass->genMethodCommentBlock( $mName, $mArr, $mComment )
- );
-
- //Test Method comment block with custom comment
- $mName = 'myMethod';
- $mArr = array( 'comment'=>'testing 1 2 3');
- $mComment = '';
- $expected = "/**\n* myMethod Method\n*\n* testing 1 2 3\n*\n*/\n";
- $this->assertEquals(
- $expected,
- $this->tiClass->genMethodCommentBlock( $mName, $mArr, $mComment )
- );
-
- //Test Method comment block with params
- $mName = 'myMethod';
- $mArr = array( 'comment'=>'testing 1 2 3', 'params'=>array('a', 'b') );
- $mComment = '';
- $expected = "/**\n* myMethod Method\n*\n* testing 1 2 3\n*\n* @param mixed \$a\n* @param mixed \$b\n*/\n";
- $this->assertEquals(
- $expected,
- $this->tiClass->genMethodCommentBlock( $mName, $mArr, $mComment )
- );
-
- }
-
- function testGenProperty() {
- $pName = 'foo';
- $pArr = array();
- $this->assertEquals( "protected \$foo;\n", $this->tiClass->genProperty( $pName, $pArr ) );
-
-
- $pName = 'foo';
- $pArr = array('value'=>'bar');
- $this->assertEquals( "protected \$foo = 'bar';\n", $this->tiClass->genProperty( $pName, $pArr ) );
-
- $pName = 'foo';
- $pArr = array('value'=>array('abc', 'def'));
- $this->assertEquals( "protected \$foo = array( 'abc', 'def' );\n", $this->tiClass->genProperty( $pName, $pArr ) );
-
- $pName = 'foo';
- $pArr = array( 'value'=>array( 'abc'=>array( '123', '456' ) ) );
- $this->assertEquals( "protected \$foo = array( \n 'abc' => array( '123', '456' )\n);\n", $this->tiClass->genProperty( $pName, $pArr ) );
-
- $pName = 'foo';
- $pArr = array(
- 'visibility'=>'private',
- 'value'=>array( 'abc'=>array( '123', '456' ) )
- );
- $this->assertEquals( "private \$foo = array( \n 'abc' => array( '123', '456' )\n);\n", $this->tiClass->genProperty( $pName, $pArr ) );
-
- $pName = 'foo';
- $pArr = array(
- 'visibility'=>'public',
- 'value'=>array( 'abc'=>array( '123', '456' ) )
- );
- $this->assertEquals( "public \$foo = array( \n 'abc' => array( '123', '456' )\n);\n", $this->tiClass->genProperty( $pName, $pArr ) );
- }
-
- function testGenMethod() {
- //Testing genMethod, defaults to visibility protected
- $mName = 'myMethod';
- $mArr = array(
- 'comments'=>'Testing 1 2 3',
- 'params'=>array('a', 'b')
- );
- $expected = "//Testing 1 2 3\nprotected function myMethod( \$a, \$b ) {\n\n} //end myMethod\n";
- $this->assertEquals( $expected, $this->tiClass->genMethod( $mName, $mArr ) );
-
- //Testing genMethod, visibility private
- $mName = 'myMethod';
- $mArr = array(
- 'comments'=>'Testing 1 2 3',
- 'visibility'=>'private',
- 'params'=>array('a', 'b')
- );
- $expected = "//Testing 1 2 3\nprivate function myMethod( \$a, \$b ) {\n\n} //end myMethod\n";
- $this->assertEquals( $expected, $this->tiClass->genMethod( $mName, $mArr ) );
-
- //Testing genMethod, visibility public
- $mName = 'myMethod';
- $mArr = array(
- 'comments'=>'Testing 1 2 3',
- 'visibility'=>'public',
- 'params'=>array('a', 'b')
- );
- $expected = "//Testing 1 2 3\npublic function myMethod( \$a, \$b ) {\n\n} //end myMethod\n";
- $this->assertEquals( $expected, $this->tiClass->genMethod( $mName, $mArr ) );
-
- //Testing callParent before
- $mName = 'myMethod';
- $mArr = array(
- 'comments'=>'Testing 1 2 3',
- 'params'=>array('a', 'b'),
- 'callParent' => 'before',
- 'code' => array(
- '//A Comment',
- 'echo "Hello World";'
- ),
- 'return' => '$foo'
- );
- $expected = "//Testing 1 2 3\nprotected function myMethod( \$a, \$b ) {\n";
- $expected .= " parent::myMethod();\n";
- $expected .= " //A Comment\n";
- $expected .= " echo \"Hello World\";\n";
- $expected .= "\n return \$foo;";
- $expected .= "\n} //end myMethod\n";
-
- $this->assertEquals( $expected, $this->tiClass->genMethod( $mName, $mArr ) );
-
- //Testing callParent after
- $mName = 'myMethod';
- $mArr = array(
- 'comments'=>'Testing 1 2 3',
- 'params'=>array('a', 'b'),
- 'callParent' => 'after',
- 'code' => array(
- '//A Comment',
- 'echo "Hello World";'
- ),
- 'return' => '$foo'
- );
- $expected = "//Testing 1 2 3\nprotected function myMethod( \$a, \$b ) {\n";
- $expected .= " //A Comment\n";
- $expected .= " echo \"Hello World\";\n";
- $expected .= "\n parent::myMethod();\n";
- $expected .= " return \$foo;";
- $expected .= "\n} //end myMethod\n";
-
- $this->assertEquals( $expected, $this->tiClass->genMethod( $mName, $mArr ) );
- }
-
- function testGenMethodParams() {
- $pArr = array('a','b','c');
- $expected = ' $a, $b, $c';
- $this->assertEquals( $expected, $this->tiClass->genMethodParams( $pArr ) );
-
- $pArr = array('$a','$b','$c');
- $expected = ' $a, $b, $c';
- $this->assertEquals( $expected, $this->tiClass->genMethodParams( $pArr ) );
-
- $pArr = array('one','two','three=\'\'');
- $expected = ' $one, $two, $three=\'\'';
- $this->assertEquals( $expected, $this->tiClass->genMethodParams( $pArr ) );
-
- $pArr = array('$one','$two','$three=\'\'');
- $expected = ' $one, $two, $three=\'\'';
- $this->assertEquals( $expected, $this->tiClass->genMethodParams( $pArr ) );
- }
-}
View
13 tests/CG/CGTestCase.php
@@ -1,13 +0,0 @@
-<?php
-
-class CGTestCase extends PHPUnit_Framework_TestCase {
-
- protected $tClass;
- function SetUp() {
-
- }
-
- function testNothing() {
- //There are currently no tests that need to be run on this class
- }
-}
View
15 tests/CG/Classes/CGBaseInternals.php
@@ -1,15 +0,0 @@
-<?php
-class CGBaseInternals extends CGBase {
-
-
- public function genCode( $codeArr ) {
- return parent::genCode( $codeArr );
- }
-
- public function genArray( $arr, $depth=0 ) {
- return parent::genArray( $arr, $depth=0 );
- }
- public function array_depth($array) {
- return parent::array_depth( $array );
- }
-}
View
24 tests/CG/Classes/CGClassInternals.php
@@ -1,24 +0,0 @@
-<?php
-class CGClassInternals extends CGClass {
-
- public function genClassCommentBlock( $name, $class ) {
- return parent::genClassCommentBlock( $name, $class );
- }
-
- public function genMethodCommentBlock( $name, $method, $comment='' ) {
- return parent::genMethodCommentBlock( $name, $method, $comment );
- }
-
- public function genProperty( $name, $prop ) {
- return parent::genProperty( $name, $prop );
- }
-
- public function genMethod( $name, $method ) {
- return parent::genMethod( $name, $method );
- }
-
- public function genMethodParams( $params ) {
- return parent::genMethodParams( $params );
- }
-
-}
View
27 tests/CakeSpec/CakeSpecBaseTests.php
@@ -1,27 +0,0 @@
-<?php
-/**
-*
-*
-*/
-
-require_once( 'Classes/CakeSpecBaseInternals.php' );
-require_once( 'CakeSpecTestCase.php' );
-class CakeSpecBaseTests extends CakeSpecTestCase {
- protected $tClass;
- protected $tiClass;
-
- function SetUp() {
- $this->tClass = new CakeSpecBase();
- $this->tiClass = new CakeSpecBaseInternals();
-
- }
-
- function testExec() {
- $this->assertEquals( '/bin/ls', $this->tiClass->exec('which ls') );
- }
-
- function testCheckDep() {
- $this->assertTrue( $this->tiClass->checkDependencies() );
- }
-
-}
View
19 tests/CakeSpec/CakeSpecBuilderTests.php
@@ -1,19 +0,0 @@
-<?php
-/**
-*
-*
-*/
-require_once( CAKESPEC_TEST_DIR . DS .'../libraries/CakeSpecBuilder.php' );
-require_once( 'CakeSpecTestCase.php' );
-class CakeSpecBuilderTests extends CakeSpecTestCase {
-
- protected $tClass;
-
- function SetUp() {
- $this->datadir = CAKESPEC_TEST_DATA . DS . 'CakeSpecBuilder';
- }
- function testBuildSimple() {
- $csb = new CakeSpecBuilder( $this->datadir . DS . 'simple.cakespec' );
- //$csb->build();
- }
-}
View
42 tests/CakeSpec/CakeSpecFilesystemTests.php
@@ -1,42 +0,0 @@
-<?php
-/**
-*
-*
-*/
-require_once( 'CakeSpecTestCase.php' );
-
-class CakeSpecFilesystemTests extends CakeSpecTestCase {
-
- protected $tClass;
- function testTest() {
-
- }
- /*
- function SetUp() {
- mkdir( CAKESPEC_TEST_TMP );
- mkdir( CAKESPEC_TEST_TMP . DS . 'chmodtest' );
- mkdir( CAKESPEC_TEST_TMP . DS . 'chowntest' );
- touch( CAKESPEC_TEST_TMP . DS . 'chmodtest' . DS . 'file.txt' );
- touch( CAKESPEC_TEST_TMP . DS . 'chowntest' . DS . 'file.txt' );
- }
-
- function TearDown() {
- unlink( CAKESPEC_TEST_TMP . DS . 'chmodtest' . DS . 'file.txt' );
- unlink( CAKESPEC_TEST_TMP . DS . 'chowntest' . DS . 'file.txt' );
- rmdir( CAKESPEC_TEST_TMP . DS . 'chmodtest' );
- rmdir( CAKESPEC_TEST_TMP . DS . 'chowntest' );
- rmdir( CAKESPEC_TEST_TMP );
- }
-
- function testChmod() {
- touch( CAKESPEC_TEST_TMP . DS . 'chmodtest' . DS . 'file.txt' );
- $csfs = new CakeSpecFilesystem( CAKESPEC_TEST_TMP . DS . 'chmodtest' . DS . 'file.txt' );
- $csfs->chmod( array('mask'=>0777, 'recursive'=>true ) );
- }
-
- function testChown() {
- $csfs = new CakeSpecFilesystem( CAKESPEC_TEST_TMP . DS . 'chowntest' . DS . 'file.txt' );
- $csfs->chown( array( 'username'=>'nobody', 'nogroup'=>'nogroup', 'recursive'=>true ) );
- }
- */
-}
View
121 tests/CakeSpec/CakeSpecLintTests.php
@@ -1,121 +0,0 @@
-<?php
-/**
-*
-*
-*/
-
-require_once('Classes/CakeSpecLintInternals.php');
-require_once( 'CakeSpecTestCase.php' );
-class CakeSpecLintTests extends CakeSpecTestCase {
- protected $tClass;
-
- function SetUp() {
- $this->datadir = CAKESPEC_TEST_DATA . DS . 'CakeSpecLint';
- }
-
- function testErrorStack() {
- $cslint = new CakeSpecLintInternals( $this->datadir . DS . 'valid.cakespec' );
- $prevCount = $cslint->getErrorCount();
- $cslint->addError('Testing Error Stack');
- $this->assertEquals( $prevCount + 1, $cslint->getErrorCount() );
-
- $this->assertContains("Testing Error Stack", $cslint->getError(0) );
- $this->assertContains("Testing Error Stack", $cslint->getLastError() );
-
- $prevCount = $cslint->getErrorCount();
- $cslint->addError('A 2nd Error to the Stack');
- $this->assertEquals( $prevCount + 1, $cslint->getErrorCount() );
-
- $this->assertContains("A 2nd Error to the Stack", $cslint->getError(1) );
- $this->assertContains("A 2nd Error to the Stack", $cslint->getLastError() );