Skip to content

Instantly share code, notes, and snippets.

@Taluu
Created November 20, 2013 14:17
Show Gist options
  • Select an option

  • Save Taluu/7563918 to your computer and use it in GitHub Desktop.

Select an option

Save Taluu/7563918 to your computer and use it in GitHub Desktop.
<?php
use Behat\Behat\Event\SuiteEvent,
Behat\Behat\Event\FeatureEvent,
Behat\Behat\Event\ScenarioEvent,
Behat\Gherkin\Node\TableNode,
Behat\Gherkin\Node\PyStringNode,
Behat\Behat\Exception\PendingException,
Behat\MinkExtension\Context\MinkContext;
use Symfony\Component\Process\Process;
class FeatureContext extends MinkContext
{
private static $parameters = [];
public function __construct(array $parameters)
{
static::$parameters = $parameters;
}
private static function runCommand($cmd, $silent = false)
{
$p = new Process($cmd, null, null, null, 300);
try {
$p->run(function ($type, $buffer) use ($silent) {
if (true === $silent) {
return;
}
if ('err' === $type) {
echo 'ERR > ';
}
echo $buffer;
});
} catch (\RuntimeException $e) {
echo '<error>There was an error while running this process : ' . $e->getMessage() . '</error>';
}
return $p;
}
/** @BeforeSuite */
public static function init(SuiteEvent $event)
{
if (isset(static::$parameters['reset_database'], static::$parameters['environment']) && true === static::$parameters['reset_database']) {
static::runCommand('sh ' . __DIR__ . '/../../../bin/create_database.sh ' . static::$parameters['environment'] . ' --ansi');
static::runCommand('rm -rf ' . __DIR__ . '/../../../app/cache/*');
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment