Skip to content

Commit

Permalink
add config file umpirsky#2 with ignore url
Browse files Browse the repository at this point in the history
  • Loading branch information
prophet777 committed Dec 17, 2014
1 parent a2be136 commit 0161a1e
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 5 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@
"require": {
"php": "~5.4",
"symfony/console": "~2.6",
"umpirsky/centipede-crawler": "dev-master"
"umpirsky/centipede-crawler": "dev-master",
"symfony/yaml": "~2.3"
},
"require-dev": {
"phpspec/phpspec": "~2.0"
Expand Down
26 changes: 22 additions & 4 deletions src/Centipede/Console/Command/Run.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\BrowserKit\Response;
use Centipede\Crawler;
use Symfony\Component\Yaml\Yaml;

class Run extends Command
{
Expand All @@ -25,7 +26,7 @@ protected function configure()
new InputOption('auth-method', null, InputOption::VALUE_OPTIONAL, 'Authentication method'),
new InputOption('session-name', null, InputOption::VALUE_OPTIONAL, 'Session name', 'PHPSESSID'),
new InputOption('session-id', null, InputOption::VALUE_OPTIONAL, 'Session id'),
new InputOption('ignore-url', null, InputOption::VALUE_OPTIONAL | InputOption::VALUE_IS_ARRAY, 'Ignore url'),
new InputOption('config', 'c', InputOption::VALUE_OPTIONAL, 'load centipede yaml config'),
])
->setDescription('Runs specifications')
;
Expand All @@ -48,12 +49,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$authenticator
);

$excludeUrls = $input->getOption('ignore-url');
$config = $this->getConfig($input->getOption('config'));

$crawler->crawl(function ($url, Response $response) use ($excludeUrls, $output) {
$crawler->crawl(function ($url, Response $response) use ($config, $output) {
$tag = 'info';

if (in_array($url, $excludeUrls)) {
if (in_array($url, $config['ignore'])) {
return;
}

Expand All @@ -73,4 +74,21 @@ protected function execute(InputInterface $input, OutputInterface $output)

return $this->exitCode;
}

protected function getConfig($configFilePath)
{
$config = array();

if (null !== $configFilePath) {
if (!file_exists($configFilePath)) {
throw new \Exception('Config file not found');
}

$parsedContent = (new Yaml())->parse(file_get_contents($configFilePath));

$config['ignore'] = isset($parsedContent['ignore']) ? $parsedContent['ignore'] : array();
}

return $config;
}
}

0 comments on commit 0161a1e

Please sign in to comment.