/** * @param OutputInterface $output * @param array $actions * @param bool $empty */ protected function render(OutputInterface $output, array $actions, $empty = false) { $fields = ['action' => 'name', 'workers' => 'current-watching', 'reserved' => 'current-jobs-reserved', 'ready' => 'current-jobs-ready', 'urgent' => 'current-jobs-urgent', 'delayed' => 'current-jobs-delayed', 'buried' => 'current-jobs-buried']; $table = new Table($output); $table->setHeaders(array_keys($fields)); $rows = []; foreach ($actions as $action) { if (!($stats = $this->manager->getActionStats($action))) { if (!$empty) { continue; } $stats = array_combine(array_values($fields), array_fill(0, sizeof($fields), '-')); $stats['name'] = $action; } $rows[$action] = array_map(function ($field) use($stats) { return $stats[$field]; }, $fields); } ksort($rows); $table->addRows($rows); if ($this->lineCount) { // move back to the beginning $output->write("[0G"); $output->write(sprintf("[%dA", $this->lineCount)); // overwrite the complete table before rendering the new one $width = $this->getApplication()->getTerminalDimensions()[0]; $lines = array_fill(0, $this->lineCount, str_pad('', $width, ' ')); $output->writeln($lines); $output->write(sprintf("[%dA", $this->lineCount)); } // render the new table $table->render(); // top table border + header + header border + bottom table border = 4 $this->lineCount = 4 + sizeof($rows); }
/** * @expectedException \Pheanstalk\Exception\ServerException */ public function testStatsForFailingAction() { $executor = new Executor(); $action = $executor->getName(); $this->manager->addExecutor($executor); $this->pheanstalk->expects($this->once())->method('statsTube')->with($action)->will($this->throwException(new ServerException('Oh noes!'))); $this->manager->getActionStats($action); }