Наследование: extends lithium\console\command\Create
Пример #1
0
    public function testRun()
    {
        $this->request->params += array('command' => 'create', 'action' => 'controller', 'args' => array('Posts'));
        $controller = new Controller(array('request' => $this->request, 'classes' => $this->classes));
        $controller->path = $this->_testPath;
        $controller->run('controller');
        $expected = "PostsController created in create_test\\controllers.\n";
        $result = $controller->response->output;
        $this->assertEqual($expected, $result);
        $expected = <<<'test'


namespace create_test\controllers;

use \create_test\models\Post;

class PostsController extends \lithium\action\Controller {

	public function index() {
		$posts = Post::all();
		return compact('posts');
	}

	public function view() {
		$post = Post::first($this->request->id);
		return compact('post');
	}

	public function add() {
		$post = Post::create();

		if (($this->request->data) && $post->save($this->request->data)) {
			$this->redirect(array('Posts::view', 'args' => array($post->id)));
		}
		return compact('post');
	}

	public function edit() {
		$post = Post::find($this->request->id);

		if (!$post) {
			$this->redirect('Posts::index');
		}
		if (($this->request->data) && $post->save($this->request->data)) {
			$this->redirect(array('Posts::view', 'args' => array($post->id)));
		}
		return compact('post');
	}
}


test;
        $replace = array("<?php", "?>");
        $result = str_replace($replace, '', file_get_contents($this->_testPath . '/create_test/controllers/PostsController.php'));
        $this->assertEqual($expected, $result);
    }