public function testProgressBar() { $progressBar = new ProgressBar(new NullOutput()); $output = new InstallOutput(null, $progressBar); $output->start('Start', 5); $this->assertEquals(5, $progressBar->getMaxSteps()); $this->assertEquals('Start', $progressBar->getMessage('message')); $output->step('Step 1'); $this->assertEquals(1, $progressBar->getProgress()); $this->assertEquals('Step 1', $progressBar->getMessage('message')); $output->end('End'); $this->assertEquals(5, $progressBar->getProgress()); $this->assertEquals('End', $progressBar->getMessage('message')); }
protected function execute(InputInterface $input, OutputInterface $output) { if (!filter_var($this->host, FILTER_VALIDATE_IP, FILTER_FLAG_IPV4)) { $host = gethostbyname($this->host); if ($host == $this->host) { throw new \InvalidArgumentException('Invalid listen address.'); } $this->host = $host; } if ($this->port < 1 || $this->port > 65535) { throw new \InvalidArgumentException('Invalid port number.'); } $result = array(); $validator = new SSLValidator(); $protocols = $validator->getProtocols(); $ciphers = $validator->getCiphers(); $length = 0; array_walk($protocols, function (&$value) use(&$length) { $length = max($length, strlen($value)); }); array_walk($ciphers, function (&$value) use(&$length) { $length = max($length, strlen($value)); }); $length += 7; $progress = new ProgressBar($output, count($ciphers) * count($protocols)); #$progress->setFormat('verbose'); $progress->start(); foreach ($protocols as $protocol) { if (!isset($result[$protocol])) { $result[$protocol] = array(); } foreach ($ciphers as $cipher) { $progress->setMessage(sprintf('%s %s', str_replace('_', '.', strtoupper($protocol)), strtoupper($cipher))); if ($validator->verifySingle($this->host, $this->port, $protocol, $cipher)) { $result[$protocol][] = $cipher; } ob_start(); $progress->advance(); $output->write(' ' . str_pad($progress->getMessage(), $length, ' ')); $output->write("\r"); ob_end_clean(); } } $progress->finish(); $output->write("\n\n"); foreach ($result as $protocol => &$ciphers) { foreach ($ciphers as $cipher) { $output->writeln(sprintf('<info>%s</info> :: <comment>%s</comment>', str_replace('_', '.', strtoupper($protocol)), strtoupper($cipher))); } } return 0; }