protected function execute(InputInterface $input, OutputInterface $output) { $path = $input->getArgument('config_file') ? $input->getArgument('config_file') : $this->configDefaultPath; $output->writeln('Linting <info>' . basename($path) . '</info>...'); if (!is_file($path)) { throw new \InvalidArgumentException('"' . $path . '" is not a file.'); } elseif (!is_readable($path)) { throw new \InvalidArgumentException('"' . $path . '" can not be read.'); } $verifyLogFiles = $input->getOption('check-files'); if ($verifyLogFiles) { $output->writeln('<comment>Also checking if the log files can be accessed.</comment>'); } $output->writeln(''); $lint = Config::lint(file_get_contents($path), $verifyLogFiles); $checkLines = []; foreach ($lint['checks'] as $check) { $checkLines = $this->prepareCheckLine($checkLines, $check); } $output->writeln('Checks:'); $table = new Table($output); $table->setStyle('compact'); $table->setRows($checkLines); $table->render(); $output->writeln(''); if ($lint['valid']) { $output->writeln('<fg=green>Your config file is valid.</>'); } else { $output->writeln('<error> Your config file is not valid. </error>'); } }
public function testLint() { $config_valid = file_get_contents(__DIR__ . '/res/config_valid.yml'); $response = \Syonix\LogViewer\Config::lint($config_valid); $this->assertArrayHasKey('valid', $response); $this->assertArrayHasKey('checks', $response); $this->assertTrue($response['valid']); $this->assertGreaterThan(0, count($response['checks'])); foreach ($response['checks'] as $check) { $this->assertArrayHasKey('message', $check); $this->assertArrayHasKey('status', $check); $this->assertEquals('ok', $check['status']); } }