Author: Fabien Potencier (fabien@blackfire.io)
コード例 #1
0
ファイル: BlackfireExtension.php プロジェクト: stof/player
 public function postRun(Scenario $scenario, ValueBag $values, ValueBag $extra)
 {
     if ($extra->has('blackfire_build')) {
         $build = $extra->get('blackfire_build');
         // did we profiled anything?
         if (!$build->getJobCount()) {
             // don't finish the build as it won't work with 0 profiles
             $this->logger->error(sprintf('Report "%s" aborted as it has no profiles', $scenario->getTitle()));
             $extra->remove('blackfire_build');
             return;
         }
         $extra->set('blackfire_report', $report = $this->blackfire->endBuild($build));
         $extra->remove('blackfire_build');
     }
     // avoid getting the report if not needed
     if (!$this->logger) {
         return;
     }
     try {
         if ($report->isErrored()) {
             $this->logger->critical(sprintf('Report "%s" errored', $scenario->getTitle()));
         } else {
             if ($report->isSuccessful()) {
                 $this->logger->debug(sprintf('Report "%s" pass', $scenario->getTitle()));
             } else {
                 $this->logger->error(sprintf('Report "%s" failed', $scenario->getTitle()));
             }
         }
     } catch (BlackfireException $e) {
         $this->logger->critical(sprintf('Report "%s" is not available (%s)', $scenario->getTitle(), $e->getMessage()));
     }
     $this->logger->info(sprintf('Report "%s" URL: %s', $scenario->getTitle(), $report->getUrl()));
 }
コード例 #2
0
 private function extract()
 {
     $player = new Player(new Client());
     $scenario = new Scenario();
     $scenario->endpoint('http://londonbusroutes.net')->visit("url('/changes.htm')")->expect('status_code() == 200')->extract('table_count', 'css("table").count()');
     $r = $player->run($scenario);
     return $r['table_count'];
 }
コード例 #3
0
ファイル: Scenario.php プロジェクト: mawz2042/player
 /**
  * @return Step
  */
 public function add(Scenario $scenario)
 {
     if (!($step = $scenario->getRoot())) {
         throw new LogicException('Unable to add an empty scenario.');
     }
     $options = $this->root->getOptions();
     $this->root = clone $scenario->getRoot();
     $this->root->setOptions($options);
     return $this->root;
 }
コード例 #4
0
ファイル: PlayerTest.php プロジェクト: stof/player
 public function testFoo()
 {
     $scenario = new Scenario();
     $scenario->request('/');
     $mock = new MockHandler([new Response(200, ['X-Foo' => 'Bar']), new Response(202, ['Content-Length' => 0]), new RequestException('Error Communicating with Server', new Request('GET', 'test'))]);
     $handler = HandlerStack::create($mock);
     $guzzle = new GuzzleClient(['handler' => $handler]);
     $player = new Player($guzzle);
     $player->crawl($scenario);
 }
コード例 #5
0
 private function extractRouteNumbers()
 {
     $player = $this->getPlayer();
     $scenario = new Scenario();
     $offline = false;
     $endpoint = $offline ? 'http://127.0.0.1/legacy' : 'http://londonbusroutes.net';
     $scenario->endpoint($endpoint)->visit("url('/details.htm')")->expect('status_code() == 200')->extract('route_numbers', 'css("pre > font > a").extract("_text")')->extract('nodes', 'css("pre > font > *").extract("_text")');
     $r = $player->run($scenario);
     $routeNumbers = $this->filterRouteNumbers($r['route_numbers']);
     $data = $this->filterRouteDetails($r['nodes'], $routeNumbers);
     return $data;
 }
コード例 #6
0
ファイル: Step.php プロジェクト: blackfireio/player
 public function add(Scenario $scenario)
 {
     if (!($step = $scenario->getRoot())) {
         throw new LogicException('Unable to add an empty scenario.');
     }
     if ($this->root) {
         throw new LogicException('Unable to add a scenario at the root step.');
     }
     $this->next = clone $scenario->getRoot();
     $this->next->root = false;
     $this->next->options = $this->options;
     return $this->next->getLast();
 }
コード例 #7
0
ファイル: ArrayLoader.php プロジェクト: blackfireio/player
 private function loadScenario($data, array $references)
 {
     $title = null;
     if (isset($data['options']['title'])) {
         $title = $data['options']['title'];
     }
     $scenario = new Scenario($title);
     if (isset($data['options'])) {
         if (isset($data['options']['auth'])) {
             $auth = $data['options']['auth'];
             if (is_array($auth)) {
                 $scenario->auth($auth[0], $auth[1]);
             } else {
                 $scenario->auth($auth);
             }
         }
         if (isset($data['options']['key'])) {
             $scenario->key($data['options']['key']);
         }
         if (isset($data['options']['delay'])) {
             $scenario->delay($data['options']['delay']);
         }
         if (isset($data['options']['endpoint'])) {
             $scenario->endpoint($data['options']['endpoint']);
         }
         if (isset($data['options']['variables'])) {
             foreach ($data['options']['variables'] as $key => $value) {
                 $scenario->value($key, $value);
             }
         }
         if (isset($data['options']['headers'])) {
             foreach ($data['options']['headers'] as $key => $value) {
                 $scenario->header($key, $value);
             }
         }
     }
     $first = true;
     foreach ($data['steps'] as $config) {
         if ($first) {
             if (!isset($config['visit']) && !isset($config['add'])) {
                 throw new LogicException('visit must be called as a first step.');
             }
             $step = $scenario;
             $first = false;
         }
         if (isset($config['visit'])) {
             $step = $step->visit($config['visit'], isset($config['method']) ? $config['method'] : 'GET', isset($config['params']) ? $config['params'] : []);
         } elseif (isset($config['click'])) {
             $step = $step->click($config['click']);
         } elseif (isset($config['submit'])) {
             $step = $step->submit($config['submit'], isset($config['params']) ? $config['params'] : []);
         } elseif (isset($config['follow'])) {
             $step = $step->follow();
         } elseif (isset($config['reload'])) {
             $step = $step->reload();
         } elseif (isset($config['add'])) {
             $key = $config['add'];
             if (!isset($references[$key])) {
                 throw new LogicException(sprintf('Scenario "%s" does not exist.', $key));
             }
             $step = $step->add($references[$key]);
             continue;
         } else {
             throw new LogicException(sprintf('Step "%s" must define a "visit", "click", "submit", "follow", "reload", or "add" item.', $title));
         }
         if (isset($config['title'])) {
             $step->title($config['title']);
         }
         if (isset($config['expect'])) {
             $this->ensureConfigurationPropertyIsArray($config, 'expect');
             foreach ($config['expect'] as $expectation) {
                 $step->expect($expectation);
             }
         }
         if (isset($config['delay'])) {
             $step->delay($config['delay']);
         }
         if (isset($config['assert'])) {
             $this->ensureConfigurationPropertyIsArray($config, 'assert');
             foreach ($config['assert'] as $assertion) {
                 $step->assert($assertion);
             }
         }
         if (isset($config['extract'])) {
             $this->ensureConfigurationPropertyIsArray($config, 'extract');
             foreach ($config['extract'] as $name => $cfg) {
                 if (is_array($cfg)) {
                     $step->extract($name, $cfg[0], $cfg[1]);
                 } else {
                     $step->extract($name, $cfg);
                 }
             }
         }
         if (isset($config['samples'])) {
             $step->samples($config['samples']);
         }
         if (isset($config['blackfire'])) {
             $step->blackfire($config['blackfire']);
         }
         if (isset($config['json']) && $config['json']) {
             $step->json();
         }
         if (isset($config['headers'])) {
             $this->ensureConfigurationPropertyIsArray($config, 'headers');
             foreach ($config['headers'] as $key => $value) {
                 $step->header($key, $value);
             }
         }
     }
     return $scenario;
 }