/** * testFindRecursive method * * @return void */ public function testFindRecursive() { $Folder = new Folder(CAKE); $result = $Folder->findRecursive('(config|paths)\\.php'); $expected = array(CAKE . 'Config' . DS . 'config.php'); $this->assertSame(array(), array_diff($expected, $result)); $this->assertSame(array(), array_diff($expected, $result)); $result = $Folder->findRecursive('(config|woot)\\.php', true); $expected = array(CAKE . 'Config' . DS . 'config.php'); $this->assertSame($expected, $result); $path = TMP . 'tests' . DS; $Folder = new Folder($path, true); $Folder->create($path . 'sessions'); $Folder->create($path . 'testme'); $Folder->cd($path . 'testme'); $File = new File($Folder->pwd() . DS . 'paths.php'); $File->create(); $Folder->cd($path . 'sessions'); $result = $Folder->findRecursive('paths\\.php'); $expected = array(); $this->assertSame($expected, $result); $Folder->cd($path . 'testme'); $File = new File($Folder->pwd() . DS . 'my.php'); $File->create(); $Folder->cd($path); $result = $Folder->findRecursive('(paths|my)\\.php'); $expected = array($path . 'testme' . DS . 'my.php', $path . 'testme' . DS . 'paths.php'); $this->assertSame(sort($expected), sort($result)); $result = $Folder->findRecursive('(paths|my)\\.php', true); $expected = array($path . 'testme' . DS . 'my.php', $path . 'testme' . DS . 'paths.php'); $this->assertSame($expected, $result); }
/** * Bake the plugin, create directories and files * * @param string $plugin Name of the plugin in CamelCased format * @return bool */ public function bake($plugin) { $pathOptions = App::path('Plugin'); if (count($pathOptions) > 1) { $this->findPath($pathOptions); } $this->hr(); $this->out(__d('cake_console', "<info>Plugin Name:</info> %s", $plugin)); $this->out(__d('cake_console', "<info>Plugin Directory:</info> %s", $this->path . $plugin)); $this->hr(); $looksGood = $this->in(__d('cake_console', 'Look okay?'), ['y', 'n', 'q'], 'y'); if (strtolower($looksGood) === 'y') { $Folder = new Folder($this->path . $plugin); $directories = ['Config' . DS . 'Schema', 'Model' . DS . 'Behavior', 'Model' . DS . 'Table', 'Model' . DS . 'Entity', 'Console' . DS . 'Command' . DS . 'Task', 'Controller' . DS . 'Component', 'Lib', 'View' . DS . 'Helper', 'Template', 'Test' . DS . 'TestCase' . DS . 'Controller' . DS . 'Component', 'Test' . DS . 'TestCase' . DS . 'View' . DS . 'Helper', 'Test' . DS . 'TestCase' . DS . 'Model' . DS . 'Behavior', 'Test' . DS . 'Fixture', 'webroot']; foreach ($directories as $directory) { $dirPath = $this->path . $plugin . DS . $directory; $Folder->create($dirPath); new File($dirPath . DS . 'empty', true); } foreach ($Folder->messages() as $message) { $this->out($message, 1, Shell::VERBOSE); } $errors = $Folder->errors(); if (!empty($errors)) { foreach ($errors as $message) { $this->error($message); } return false; } $controllerFileName = 'AppController.php'; $out = "<?php\n\n"; $out .= "namespace {$plugin}\\Controller;\n\n"; $out .= "use App\\Controller\\AppController as BaseController;\n\n"; $out .= "class AppController extends BaseController {\n\n"; $out .= "}\n"; $this->createFile($this->path . $plugin . DS . 'Controller' . DS . $controllerFileName, $out); $this->_modifyBootstrap($plugin); $this->_generatePhpunitXml($plugin, $this->path); $this->_generateTestBootstrap($plugin, $this->path); $this->hr(); $this->out(__d('cake_console', '<success>Created:</success> %s in %s', $plugin, $this->path . $plugin), 2); } return true; }