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']; }
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); }
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; } }