Esempio n. 1
0
 /**
  * @depends testComponent
  */
 public function testRun()
 {
     $this->configSkeleton[Manager::CFG_TITLE] = 'Dummy configuration for running test.';
     $this->configSkeleton[Manager::CFG_COMPONENTS][Manager::COMMON]['FinishBlock'] = [FinishBlock::CFG_COUNT => 2];
     $this->configSkeleton[Manager::CFG_COMPONENTS][self::NS_APP]['PrintMessage'] = [PrintMessage::CFG_MESSAGE => 'Test Action Message'];
     $this->configSkeleton[Manager::CFG_ACTIONS] = [Manager::ACTION_INIT => ['PrintMessage', self::NS_APP . '\\PrintMessage', [Manager::RES_CONFIG_CLASS => self::NS_APP . '\\RetryAction', Manager::RES_CONFIG_RETRY => 2, Manager::RES_CONFIG_RETRY_DELAY => 2000]], Manager::ACTION_LOOP => [[Manager::RES_CONFIG_CLASS => 'PrintMessage', PrintMessage::CFG_MESSAGE => 'Loop message'], 'FinishBlock'], Manager::ACTION_FINAL => [self::NS_APP . '\\TestAction']];
     $this->assertEquals(Manager::RET_LOOP, Manager::run($this->configSkeleton, $this->logger));
     $this->configSkeleton[Manager::CFG_ACTIONS] = [Manager::ACTION_LOOP => ['FinishBlock', [Manager::RES_CONFIG_CLASS => 'NextLoop', PrintMessage::CFG_MESSAGE => 'Enter next loop'], [Manager::RES_CONFIG_CLASS => 'PrintMessage', PrintMessage::CFG_MESSAGE => 'This message should be never shown.']], Manager::ACTION_FINAL => [[Manager::RES_CONFIG_CLASS => 'AbortExecution', PrintMessage::CFG_MESSAGE => 'Exit script.']]];
     $this->assertEquals(Manager::RET_EXIT, Manager::run($this->configSkeleton, $this->logger));
 }
Esempio n. 2
0
File: Run.php Progetto: acgrid/adbot
    $options['verbose'] = null;
}
if ($options['v'] === 'vv' || strcasecmp($options['verbose'], 'debug') === 0) {
    $log_level = Logger::DEBUG;
} elseif ($options['v'] === 'v' || strcasecmp($options['verbose'], 'info') === 0) {
    $log_level = Logger::INFO;
} elseif ($options['v'] === false || $options['verbose'] === false) {
    $log_level = Logger::NOTICE;
} else {
    $log_level = Logger::WARNING;
}
$logger = new Logger('main');
$logger->pushHandler(new StreamHandler(sprintf('%s/log/%s.log', __DIR__, date('Ymd-His')), min($log_level, Logger::INFO)));
$logger->pushHandler(new StreamHandler('php://output', $log_level));
try {
    if (!isset($argv[++$opt_num])) {
        throw new \InvalidArgumentException(sprintf("Usage: %s [-v[v|vv]|--verbose [debug|info]] CONFIG.json", $argv[0]));
    }
    $config_file = $argv[$opt_num];
    if (!is_readable($config_file)) {
        throw new \RuntimeException("Config file is not readable.");
    }
    $config = json_decode(file_get_contents($config_file), true);
    if (!is_array($config)) {
        throw new \InvalidArgumentException('Config file is not valid JSON: ' . json_last_error_msg());
    }
    exit(Manager::run($config, $logger));
} catch (\Exception $e) {
    $logger->error($e->getMessage());
    echo $e->getTraceAsString();
}