|
<?php |
|
|
|
namespace Behat\Behat\Formatter; |
|
|
|
use Behat\Gherkin\Node\FeatureNode; |
|
use Behat\Gherkin\Node\AbstractScenarioNode; |
|
use Behat\Behat\Event\BackgroundEvent; |
|
use Behat\Gherkin\Node\ScenarioNode; |
|
|
|
class TerseFormatter extends PrettyFormatter |
|
{ |
|
|
|
/** |
|
* Returns an array of event names this subscriber wants to listen to. |
|
* |
|
* The array keys are event names and the value can be: |
|
* |
|
* * The method name to call (priority defaults to 0) |
|
* * An array composed of the method name to call and the priority |
|
* * An array of arrays composed of the method names to call and respective |
|
* priorities, or 0 if unset |
|
* |
|
* For instance: |
|
* |
|
* * array('eventName' => 'methodName') |
|
* * array('eventName' => array('methodName', $priority)) |
|
* * array('eventName' => array(array('methodName1', $priority), array('methodName2')) |
|
* |
|
* @return array The event names to listen to |
|
*/ |
|
public static function getSubscribedEvents() |
|
{ |
|
$events = array( |
|
// 'beforeSuite', 'afterSuite', 'beforeFeature', 'afterFeature', 'beforeScenario', |
|
// 'afterScenario', 'beforeBackground', 'afterBackground', 'beforeOutline', 'afterOutline', |
|
// 'beforeOutlineExample', 'afterOutlineExample', 'afterStep' |
|
'beforeSuite', 'afterSuite', 'beforeFeature', 'afterFeature', 'beforeScenario', |
|
'afterScenario', 'beforeBackground', 'afterBackground', 'beforeOutline', 'afterOutline', |
|
'beforeOutlineExample', 'afterOutlineExample' |
|
); |
|
|
|
return array_combine($events, $events); |
|
} |
|
|
|
/** |
|
* Listens to "background.before" event. |
|
* |
|
* @param BackgroundEvent $event |
|
* |
|
* @uses printBackgroundHeader() |
|
*/ |
|
public function beforeBackground(BackgroundEvent $event) |
|
{ |
|
$this->inBackground = true; |
|
|
|
if ($this->isBackgroundPrinted) { |
|
return; |
|
} |
|
|
|
// $this->printBackgroundHeader($event->getBackground()); |
|
} |
|
|
|
/** |
|
* Listens to "background.after" event. |
|
* |
|
* @param BackgroundEvent $event |
|
* |
|
* @uses printBackgroundFooter() |
|
*/ |
|
public function afterBackground(BackgroundEvent $event) |
|
{ |
|
$this->inBackground = false; |
|
|
|
if ($this->isBackgroundPrinted) { |
|
return; |
|
} |
|
$this->isBackgroundPrinted = true; |
|
|
|
// $this->printBackgroundFooter($event->getBackground()); |
|
|
|
if (null !== $this->delayedScenarioEvent) { |
|
$method = $this->delayedScenarioEvent[0]; |
|
$event = $this->delayedScenarioEvent[1]; |
|
|
|
$this->$method($event); |
|
} |
|
} |
|
|
|
/** |
|
* Prints feature header. |
|
* |
|
* @param FeatureNode $feature |
|
* |
|
* @uses printFeatureOrScenarioTags() |
|
* @uses printFeatureName() |
|
* @uses printFeatureDescription() |
|
*/ |
|
protected function printFeatureHeader(FeatureNode $feature) |
|
{ |
|
// $this->printFeatureOrScenarioTags($feature); |
|
$this->printFeatureName($feature); |
|
// if (null !== $feature->getDescription()) { |
|
// $this->printFeatureDescription($feature); |
|
// } |
|
|
|
$this->writeln(); |
|
} |
|
|
|
/** |
|
* Prints feature footer. |
|
* |
|
* @param FeatureNode $feature |
|
*/ |
|
protected function printFeatureFooter(FeatureNode $feature) |
|
{ |
|
$this->writeln(); |
|
} |
|
|
|
/** |
|
* Prints scenario header. |
|
* |
|
* @param ScenarioNode $scenario |
|
* |
|
* @uses printFeatureOrScenarioTags() |
|
* @uses printScenarioName() |
|
*/ |
|
protected function printScenarioHeader(ScenarioNode $scenario) |
|
{ |
|
$this->maxLineLength = $this->getMaxLineLength($this->maxLineLength, $scenario); |
|
|
|
// $this->printFeatureOrScenarioTags($scenario); |
|
$this->printScenarioName($scenario); |
|
} |
|
|
|
/** |
|
* Prints scenario keyword and name. |
|
* |
|
* @param AbstractScenarioNode $scenario |
|
* |
|
* @uses getFeatureOrScenarioName() |
|
* @uses printScenarioPath() |
|
*/ |
|
protected function printScenarioName(AbstractScenarioNode $scenario) |
|
{ |
|
$title = explode("\n", $this->getFeatureOrScenarioName($scenario)); |
|
|
|
$this->write(array_shift($title)); |
|
// $this->printScenarioPath($scenario); |
|
|
|
if (count($title)) { |
|
$this->writeln(implode("\n", $title)); |
|
} |
|
} |
|
} |