Skip to content

Instantly share code, notes, and snippets.

@adamelso
Created January 22, 2016 15:25
Show Gist options
  • Save adamelso/b1b8a5be3020c21e9a4a to your computer and use it in GitHub Desktop.
Save adamelso/b1b8a5be3020c21e9a4a to your computer and use it in GitHub Desktop.
<?php
namespace ArchFizz\WhateverBundle\Command;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Helper\DebugFormatterHelper;
use Symfony\Component\Console\Helper\ProcessHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Process\Process;
class BootSeleniumCommand extends ContainerAwareCommand
{
const SELENIUM_VERSION = '2.48';
const SELENIUM_PATCH = '2';
protected function configure()
{
$this->setName('boot-selenium');
$this->setAliases(['selenium']);
$this->addOption('with-update', null, InputOption::VALUE_NONE);
}
protected function execute(InputInterface $input, OutputInterface $output)
{
$filesystem = new Filesystem();
$savePath = $this->getContainer()->getParameter('kernel.root_dir')
.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'bin'.DIRECTORY_SEPARATOR.'selenium-server-standalone.jar';
$fullVersion = self::SELENIUM_VERSION.'.'.self::SELENIUM_PATCH;
if (!$filesystem->exists($savePath) || $input->getOption('with-update')) {
file_put_contents($savePath, fopen(sprintf("http://selenium-release.storage.googleapis.com/%s/selenium-server-standalone-%s.jar", self::SELENIUM_VERSION, $fullVersion), 'r'));
}
$shutdown = @file_get_contents('http://localhost:4444/selenium-server/driver/?cmd=shutDownSeleniumServer');
if ('OKOK' === $shutdown) {
$output->writeln('Shutting down already running instance of Selenium.');
}
/** @var ProcessHelper $debugFormatter */
$debugFormatter = $this->getHelper('process');
$process = new Process(sprintf('java -jar %s', $savePath));
$process->setTimeout(0);
$debugFormatter->mustRun($output, $process, 'Booting Selenium failed.', function ($type, $data) use ($output) {
$output->writeln($data);
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment