/** * @returns \React\Promise\Promise */ public function show() { $deferred = new Deferred(); $this->io->out('hello'); $deferred->reject(false); return $deferred->promise(); }
/** * Test outputTypeChoices method * * @return void */ public function testOutputTypeChoices() { $this->io->expects($this->at(0))->method('out')->with($this->stringContains('You must provide')); $this->io->expects($this->at(1))->method('out')->with($this->stringContains('1. Entity')); $this->io->expects($this->at(2))->method('out')->with($this->stringContains('2. Table')); $this->io->expects($this->at(3))->method('out')->with($this->stringContains('3. Controller')); $this->Task->outputTypeChoices(); }
/** * Test that baking a plugin for a project that contains a composer.json, the later * will be updated * * @return void */ public function testMainUpdateComposer() { $this->Task->expects($this->at(0))->method('in')->will($this->returnValue('y')); $this->io->expects($this->any())->method('askChoice')->will($this->returnValue('y')); $this->Task->expects($this->any())->method('findComposer')->will($this->returnValue('composer.phar')); $file = TMP . 'tests' . DS . 'main-composer.json'; file_put_contents($file, '{}'); $savePath = $this->Task->path; $this->Task->path = ROOT . DS . 'tests' . DS . 'BakedPlugins/'; $this->Task->expects($this->any())->method('_rootComposerFilePath')->will($this->returnValue($file)); $this->Task->expects($this->once())->method('callProcess')->with('php ' . escapeshellarg('composer.phar') . ' dump-autoload'); $this->Task->main('ComposerExample'); $result = file_get_contents($file); $this->assertSameAsFile(__FUNCTION__ . '.json', $result); $folder = new Folder($this->Task->path); $folder->delete(); $this->Task->path = $savePath; }
/** * Render a Console Helper * * Create and render the output for a helper object. If the helper * object has not already been loaded, it will be loaded and constructed. * * @param string $name The name of the helper to render * @param array $settings Configuration data for the helper. * @return \Cake\Console\Helper The created helper instance. */ public function helper($name, array $settings = []) { return $this->_io->helper($name, $settings); }
/** * Creates a file at given path * * @param string $path Where to put the file. * @param string $contents Content to put in the file. * @return bool Success * @link http://book.cakephp.org/3.0/en/console-and-shells.html#creating-files */ public function createFile($path, $contents) { $path = str_replace(DS . DS, DS, $path); $this->_io->out(); if (is_file($path) && empty($this->params['force']) && $this->interactive) { $this->_io->out(sprintf('<warning>File `%s` exists</warning>', $path)); $key = $this->_io->askChoice('Do you want to overwrite?', ['y', 'n', 'q'], 'n'); if (strtolower($key) === 'q') { $this->_io->out('<error>Quitting</error>.', 2); return $this->_stop(); } if (strtolower($key) !== 'y') { $this->_io->out(sprintf('Skip `%s`', $path), 2); return false; } } else { $this->out(sprintf('Creating file %s', $path)); } $File = new File($path, true); if ($File->exists() && $File->writable()) { $data = $File->prepare($contents); $File->write($data); $this->_io->out(sprintf('<success>Wrote</success> `%s`', $path)); return true; } $this->_io->err(sprintf('<error>Could not write to `%s`</error>.', $path), 2); return false; }
/** * For all loaded plugins, add a short alias * * This permits a plugin which implements a shell of the same name to be accessed * Using the shell name alone * * @return array the resultant list of aliases */ public function addShortPluginAliases() { $plugins = Plugin::loaded(); $io = new ConsoleIo(); $task = new CommandTask($io); $io->setLoggers(false); $list = $task->getShellList() + ['app' => []]; $fixed = array_flip($list['app']) + array_flip($list['CORE']); $aliases = []; foreach ($plugins as $plugin) { if (!isset($list[$plugin])) { continue; } foreach ($list[$plugin] as $shell) { $aliases += [$shell => $plugin]; } } foreach ($aliases as $shell => $plugin) { if (isset($fixed[$shell])) { Log::write('debug', "command '{$shell}' in plugin '{$plugin}' was not aliased, conflicts with another shell", ['shell-dispatcher']); continue; } $other = static::alias($shell); if ($other) { $other = $aliases[$shell]; Log::write('debug', "command '{$shell}' in plugin '{$plugin}' was not aliased, conflicts with '{$other}'", ['shell-dispatcher']); continue; } static::alias($shell, "{$plugin}.{$shell}"); } return static::$_aliases; }