getMock('Cake\Console\ConsoleIo', [], [], '', false); $this->Task = $this->getMock( 'Cake\Shell\Task\CellTask', ['in', 'err', 'createFile', '_stop'], [$io] ); $this->Task->Test = $this->getMock('Cake\Shell\Task\TestTask', [], [$io] ); $this->Task->Template = new TemplateTask($io); $this->Task->Template->initialize(); $this->Task->Template->interactive = false; } /** * Test the excute method. * * @return void */ public function testMain() { $this->Task->Test->expects($this->once()) ->method('bake') ->with('cell', 'Example'); $this->Task->expects($this->at(0)) ->method('createFile') ->with( $this->_normalizePath(APP . 'Template/Cell/Example/display.ctp'), '' ); $this->Task->expects($this->at(1)) ->method('createFile') ->with( $this->_normalizePath(APP . 'View/Cell/ExampleCell.php'), $this->stringContains('class ExampleCell extends Cell') ); $this->Task->main('Example'); } /** * Test main within a plugin. * * @return void */ public function testMainPlugin() { Plugin::load('TestPlugin'); $path = Plugin::path('TestPlugin'); $this->Task->expects($this->at(0)) ->method('createFile') ->with( $this->_normalizePath($path . 'src/Template/Cell/Example/display.ctp'), '' ); $this->Task->expects($this->at(1)) ->method('createFile') ->with( $this->_normalizePath($path . 'src/View/Cell/ExampleCell.php'), $this->stringContains('class ExampleCell extends Cell') ); $this->Task->main('TestPlugin.Example'); } /** * Test baking within a plugin. * * @return void */ public function testBakePlugin() { Plugin::load('TestPlugin'); $path = Plugin::path('TestPlugin'); $this->Task->plugin = 'TestPlugin'; $this->Task->expects($this->at(0)) ->method('createFile') ->with( $this->_normalizePath($path . 'src/Template/Cell/Example/display.ctp'), '' ); $this->Task->expects($this->at(1)) ->method('createFile') ->with( $this->_normalizePath($path . 'src/View/Cell/ExampleCell.php'), $this->stringContains('class ExampleCell extends Cell') ); $result = $this->Task->bake('Example'); $this->assertContains('namespace TestPlugin\View\Cell;', $result); $this->assertContains('use Cake\View\Cell;', $result); $this->assertContains('class ExampleCell extends Cell {', $result); } }