io = $this->getMock('Cake\Console\ConsoleIo', [], [], '', false); $this->Task = $this->getMock('Cake\Console\Command\Task\PluginTask', array('in', 'err', 'createFile', '_stop', 'clear'), array($this->io) ); $this->Task->Template = new TemplateTask($this->io); $this->Task->Template->interactive = false; $this->Task->path = TMP . 'tests' . DS; $this->Task->bootstrap = TMP . 'tests' . DS . 'bootstrap.php'; if (!is_dir($this->Task->path)) { mkdir($this->Task->path); } touch($this->Task->bootstrap); $this->_path = App::path('Plugin'); } /** * tearDown() * * @return void */ public function tearDown() { if (file_exists($this->Task->bootstrap)) { unlink($this->Task->bootstrap); } parent::tearDown(); } /** * test bake() * * @return void */ public function testBakeFoldersAndFiles() { $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y')); $path = $this->Task->path . 'BakeTestPlugin'; $file = $path . DS . 'src' . DS . 'Controller' . DS . 'AppController.php'; $this->Task->expects($this->at(1))->method('createFile') ->with($file, $this->stringContains('namespace BakeTestPlugin\Controller;')); $this->Task->bake('BakeTestPlugin'); $path = $this->Task->path . 'BakeTestPlugin'; $this->assertTrue(is_dir($path), 'No plugin dir'); $directories = array( 'src/Config/Schema', 'src/Model/Behavior', 'src/Model/Table', 'src/Model/Entity', 'src/Console/Command/Task', 'src/Controller/Component', 'src/Lib', 'src/View/Helper', 'tests/TestCase/Controller/Component', 'tests/TestCase/View/Helper', 'tests/TestCase/Model/Behavior', 'tests/Fixture', 'src/Template', 'webroot' ); foreach ($directories as $dir) { $this->assertTrue(is_dir($path . DS . $dir), 'Missing directory for ' . $dir); } $Folder = new Folder($this->Task->path . 'BakeTestPlugin'); $Folder->delete(); } /** * test execute with no args, flowing into interactive, * * @return void */ public function testExecuteWithNoArgs() { $path = $this->Task->path . 'TestPlugin'; $file = $path . DS . 'Controller' . DS . 'TestPluginAppController.php'; $this->Task->expects($this->at(0)) ->method('err') ->with($this->stringContains('You must')); $this->Task->expects($this->never()) ->method('createFile'); $this->Task->main(); $Folder = new Folder($path); $Folder->delete(); } /** * Test Execute * * @return void */ public function testExecuteWithOneArg() { $this->Task->expects($this->at(0))->method('in') ->will($this->returnValue('y')); $path = $this->Task->path . 'BakeTestPlugin'; $file = $path . DS . 'src' . DS . 'Controller' . DS . 'AppController.php'; $this->Task->expects($this->at(1))->method('createFile') ->with($file, $this->stringContains('class AppController extends BaseController {')); $file = $path . DS . 'phpunit.xml'; $this->Task->expects($this->at(2))->method('createFile') ->with($file, new \PHPUnit_Framework_Constraint_IsAnything()); $file = $path . DS . 'tests' . DS . 'bootstrap.php'; $this->Task->expects($this->at(3))->method('createFile') ->with($file, new \PHPUnit_Framework_Constraint_IsAnything()); $this->Task->main('BakeTestPlugin'); $Folder = new Folder($this->Task->path . 'BakeTestPlugin'); $Folder->delete(); } /** * Test that findPath ignores paths that don't exist. * * @return void */ public function testFindPathNonExistant() { $paths = App::path('Plugin'); $last = count($paths); array_unshift($paths, '/fake/path'); $paths[] = '/fake/path2'; $this->Task = $this->getMock('Cake\Console\Command\Task\PluginTask', array('in', 'out', 'err', 'createFile', '_stop'), array($this->io) ); $this->Task->path = TMP . 'tests' . DS; // Make sure the added path is filtered out. $this->Task->expects($this->exactly($last)) ->method('out'); $this->Task->expects($this->once()) ->method('in') ->will($this->returnValue($last)); $this->Task->findPath($paths); } }