Beispiel #1
0
 /**
  * main
  */
 public function main()
 {
     $this->_header();
     $this->out("When a mommy and daddy class get together... ", 0);
     list($one, $two) = $this->args;
     $oneClass = substr($one, strrpos($one, '/') + 1);
     $onePath = substr($one, 0, strrpos($one, '/'));
     $twoClass = substr($two, strrpos($two, '/') + 1);
     $twoPath = substr($two, 0, strrpos($two, '/'));
     $PhpBaker = new PhpBaker();
     $PhpBaker->merge(array($oneClass, $onePath), array($twoClass, $twoPath));
     $this->out("<good>;)</good>");
 }
Beispiel #2
0
    /**
     * 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);
    }