/** * testMerge */ public function testMerge() { $from = array('class' => array('class' => 'class CommentsController extends BasesController', 'doc' => '/** * Comments Controller * * @package Oven * @author Kyle Robinson Young <kyle at dontkry.com> * @copyright Copyright 2011 Kyle Robinson Young. All rights reserved. */', 'uses' => array("App::uses('BasesController', 'Oven.Controller');")), 'properties' => array(), 'methods' => array('admin_index' => array('doc' => '/** * admin_index */', 'value' => ' public function admin_index($param1 = \'test\') { // I SHOULD BE OVERWRITTEN } ', 'access' => 'public'), 'admin_edit' => array('doc' => '/** * admin_edit */', 'value' => ' public function admin_edit($id = null) { // I SHOULD BE MERGED } ', 'access' => 'public'))); $PhpBakerFrom = new PhpBaker('CommentsController', 'Controller'); $PhpBakerFrom->write($from); $path = current(App::path('Controller')); copy($path . 'TestsController.php', $path . 'AnotherTestsController.php'); $file = new File($path . 'AnotherTestsController.php'); $contents = $file->read(); $contents = str_ireplace('class TestsController', 'class AnotherTestsController', $contents); $file->write($contents); $file->close(); $PhpBakerTo = new PhpBaker(); $PhpBakerTo->merge(array('CommentsController', 'Controller'), array('AnotherTestsController', 'Controller')); $result = $PhpBakerTo->read(); $expected = array('class' => array('class' => 'class AnotherTestsController extends BasesController', 'doc' => '/** * Tests Controller * * @package Oven * @author Kyle Robinson Young <kyle at dontkry.com> * @copyright Copyright 2011 Kyle Robinson Young. All rights reserved. */', 'uses' => array("App::uses('BasesController', 'Oven.Controller');", "App::import('Vendor', 'SomeTestVendor');")), 'properties' => array('name' => array('doc' => '/** * name * @var string */', 'value' => 'Tests', 'access' => 'public'), 'theme' => array('doc' => '/** * theme * @var string */', 'value' => 'Gallery', 'access' => 'public'), '_test' => array('doc' => '', 'value' => array('something' => array('nested' => 'in an array')), 'access' => 'protected')), 'methods' => array('admin_index' => array('doc' => '/** * admin_index */', 'value' => ' public function admin_index($param1 = \'test\') { // LETS DO SOME MATH! $a = 5; $b = 4; $c = $a * $b + ($a - 6); $this->set(\'c\', $c); } ', 'access' => 'public'), 'admin_edit' => array('doc' => '/** * admin_edit */', 'value' => ' public function admin_edit($id = null) { // I SHOULD BE MERGED } ', 'access' => 'public'))); $this->assertEquals($expected, $result); }
/** * Turn config into bake array for Controllers * * @param array $config * @return boolean */ public function bakeControllers($config = array()) { $config = Set::merge($this->_defaultConfig, $config); if (empty($config['recipe'])) { return false; } foreach ($config['recipe'] as $name => $node) { $className = Inflector::camelize($name); $class = $className . 'Controller'; $props = array(); if (!empty($node['controller'])) { foreach ($node['controller'] as $key => $val) { $props[$key] = array('value' => $val); } } if (empty($config['config']['code_header']['doc'])) { $config['config']['code_header']['doc'] = $className . ' Controller'; } $bake = array('class' => array('class' => 'class ' . $class . ' extends BasesController', 'doc' => $this->_buildDocHeader($config), 'uses' => array("App::uses('BasesController', 'Oven.Controller');")), 'properties' => $props, 'methods' => array()); $PhpBaker = new PhpBaker($class, 'Controller'); $PhpBaker->write($bake); } $this->_getControllers(); return true; }