Author: Fabien Potencier (fabien@blackfire.io)
Inheritance: implements IteratorAggregate
Exemple #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $logger = new ConsoleLogger($output);
     $clients = [$this->createClient($output)];
     for ($i = 1, $concurrency = $input->getOption('concurrency'); $i < $concurrency; ++$i) {
         $clients[] = $this->createClient($output);
     }
     $player = new Player($clients);
     $player->setLogger($logger);
     if ($env = $input->getOption('blackfire')) {
         $blackfireConfig = new BlackfireClientConfiguration();
         $blackfireConfig->setEnv($env);
         $blackfire = new BlackfireClient($blackfireConfig);
         $player->addExtension(new \Blackfire\Player\Extension\BlackfireExtension($blackfire, $logger));
     }
     $variables = [];
     foreach ($input->getOption('variables') as $variable) {
         list($key, $value) = explode('=', $variable, 2);
         $variables[$key] = $value;
     }
     $loader = new YamlLoader();
     $scenarios = new ScenarioSet();
     foreach ($input->getArgument('files') as $file) {
         if (!is_file($file)) {
             throw new \InvalidArgumentException(sprintf('File "%s" does not exist.', $file));
         }
         foreach ($loader->load(file_get_contents($file)) as $reference => $scenario) {
             if ($input->getOption('endpoint')) {
                 $scenario->endpoint($input->getOption('endpoint'));
             }
             foreach ($variables as $key => $value) {
                 $scenario->value($key, $value);
             }
             $scenarios->add($scenario, $reference);
         }
     }
     $results = $player->runMulti($scenarios);
     if ($output = $input->getOption('output')) {
         $values = [];
         foreach ($results as $result) {
             $values[] = $result->getValues()->all();
         }
         file_put_contents($output, json_encode($values, JSON_PRETTY_PRINT));
     }
     // any scenario with an error?
     foreach ($results as $result) {
         if ($result->isErrored()) {
             return 1;
         }
     }
     if ($logger->hasErrored()) {
         return 1;
     }
 }
Exemple #2
0
 public function load($data)
 {
     // data can be a scenario or an array of scenarios
     if (is_array($data) && isset($data['steps'])) {
         $data = [$data];
     } elseif (!is_array($data)) {
         throw new LoaderException(sprintf('Unable to load unrecognized scenarios.'));
     }
     $references = [];
     $scenarios = new ScenarioSet();
     foreach ($data as $config) {
         $scenario = $this->loadScenario($config, $references);
         if ($scenario->getKey()) {
             $references[$scenario->getKey()] = $scenario;
         } else {
             $scenarios->add($scenario);
         }
     }
     return $scenarios;
 }