Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,12 @@ protected function configure()

if ($this->getPlugin()->hasFeature('notify')) {
$this->addOption('notify', 'm', InputOption::VALUE_NONE, 'Notifies test results by using the growlnotify command in Mac OS X and Windows or the notify-send command in Linux.');

// available since Release 3.6.3X
$this->addOption('cc-file', null, InputOption::VALUE_REQUIRED, 'Outputs a test status to a specified file with CruiseControl XML format');

// available since Release 3.6.3X
$this->addOption('cc-name', null, InputOption::VALUE_REQUIRED, 'Specifies a ProjectName for a CruiseControl file. If omitted, basename of cc-file option will be used.');
}

if ($this->getPlugin()->hasFeature('detailed_progress')) {
Expand Down Expand Up @@ -226,7 +232,22 @@ protected function transformToConfiguration(InputInterface $input, OutputInterfa
if ($input->getOption('notify')) {
$transformation->setConfigurationPart(
GeneralConfiguration::getConfigurationID(),
array('notify' => true)
array('notify' => array(
'enabled' => true,
))
);
}
if ($input->getOption('cc-file')) {
$projectName = $input->getOption('cc-name') ?
$input->getOption('cc-name') :
basename($input->getOption('cc-file'), '.xml');
$transformation->setConfigurationPart(
GeneralConfiguration::getConfigurationID(),
array('notify' => array(
'enabled' => true,
'file' => $input->getOption('cc-file'),
'project_name' => $projectName
))
);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,19 @@ protected function defineGrammar(NodeBuilder $nodeBuilder)
->end()
->end()
->end()
->booleanNode('notify')
->defaultFalse()
->arrayNode('notify')
->addDefaultsIfNotSet()
->children() // available since Release 3.6.3X
->booleanNode('enabled')
->defaultFalse()
->end()
->scalarNode('file')
->defaultNull()
->end()
->scalarNode('project_name')
->defaultNull()
->end()
->end()
->end()
->arrayNode('junit_xml')
->addDefaultsIfNotSet()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ public function transform()
$this->setParameter('continuous_testing', $this->configurationPart['autotest']['enabled']);
$this->setParameter('continuous_testing_watch_dirs', $this->configurationPart['autotest']['watch_dirs']);

$this->setParameter('notify', $this->configurationPart['notify']);
$this->setParameter('notify_enabled', $this->configurationPart['notify']['enabled']);
$this->setParameter('notify_file', $this->configurationPart['notify']['file']);
$this->setParameter('notify_project_name', $this->configurationPart['notify']['project_name']);

$this->setParameter('junit_xml_file', $this->configurationPart['junit_xml']['file']);
$this->setParameter('junit_xml_realtime', $this->configurationPart['junit_xml']['realtime']);
Expand Down
65 changes: 64 additions & 1 deletion src/Stagehand/TestRunner/Notification/Notifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ class Notifier
const TITLE_FAILED = 'Test Failed';
const TITLE_STOPPED = 'Test Stopped';

const CC_STATUS_PASSED = 'Success';
const CC_STATUS_FAILED = 'Failure';
const CC_STATUS_UNKNOWN = 'Unknown';

public static $ICON_PASSED;
public static $ICON_FAILED;
public static $ICON_STOPPED;
Expand All @@ -76,6 +80,26 @@ class Notifier
*/
protected $os;

/**
* @var string
*/
protected $file;

/**
* @var string
*/
protected $projectName;

/**
* @param string
* @param string
*/
function __construct($file = null, $projectName = null)
{
$this->file = $file;
$this->projectName = $projectName;
}

/**
* @param \Stagehand\TestRunner\Util\OS $os
* @since Method available since Release 3.0.1
Expand All @@ -85,6 +109,24 @@ public function setOS(OS $os)
$this->os = $os;
}

/**
* @return string
* @since Method available since Release 3.6.3X
*/
public function getFile()
{
return $this->file;
}

/**
* @return string
* @since Method available since Release 3.6.3X
*/
public function getProjectName()
{
return $this->projectName;
}

/**
* @param \Stagehand\TestRunner\Notification\Notification $notification
*/
Expand All @@ -111,15 +153,36 @@ protected function buildNotifyCommand(Notification $notification)
if ($notification->isPassed()) {
$title = self::TITLE_PASSED;
$icon = self::$ICON_PASSED;
$CCStatus = self::CC_STATUS_PASSED;
} elseif ($notification->isFailed()) {
$title = self::TITLE_FAILED;
$icon = self::$ICON_FAILED;
$CCStatus = self::CC_STATUS_FAILED;
} elseif ($notification->isStopped()) {
$title = self::TITLE_STOPPED;
$icon = self::$ICON_STOPPED;
$CCStatus = self::CC_STATUS_UNKNOWN;
}

if ($this->os->isWin()) {
if ($this->file != null) {
$projectName = $this->projectName;
$currentDate = date(DATE_ATOM);
$xml = <<< XML
<?xml version="1.0" encoding="UTF-8"?>
<Projects>
<Project
name="$projectName"
category=""
activity="$title"
lastBuildStatus="$CCStatus"
lastBuildTime="$currentDate"
/>
</Projects>
XML;
file_put_contents($this->file, $xml);

return null;
} elseif ($this->os->isWin()) {
return sprintf(
'growlnotify /t:%s /p:-2 /i:%s /a:Stagehand_TestRunner /r:%s,%s,%s /n:%s /silent:true %s',
escapeshellarg($title),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,17 @@ class CommandLineBuilder
*/
protected $options = array();

/**
* @var string
*/
protected $cruiseControlFile;

/**
* @var string
*/
protected $projectName;


/**
* @param \Stagehand\TestRunner\Core\Environment $environment
* @param \Stagehand\TestRunner\Util\LegacyProxy $legacyProxy
Expand All @@ -113,6 +124,8 @@ class CommandLineBuilder
* @param \Stagehand\TestRunner\CLI\Terminal $terminal
* @param \Stagehand\TestRunner\Core\TestTargetRepository $testTargetRepository
* @param \Stagehand\TestRunner\Process\ContinuousTesting\CommandLineOptionBuilderInterface $commandLineOptionBuilder
* @param string available since Release 3.6.3X
* @param string available since Release 3.6.3X
*/
public function __construct(
Environment $environment,
Expand All @@ -122,7 +135,9 @@ public function __construct(
Runner $runner,
Terminal $terminal,
TestTargetRepository $testTargetRepository,
CommandLineOptionBuilderInterface $commandLineOptionBuilder = null
CommandLineOptionBuilderInterface $commandLineOptionBuilder = null,
$cruiseControlFile = null,
$projectName = null
)
{
$this->environment = $environment;
Expand All @@ -133,6 +148,8 @@ public function __construct(
$this->terminal = $terminal;
$this->testTargetRepository = $testTargetRepository;
$this->commandLineOptionBuilder = $commandLineOptionBuilder;
$this->cruiseControlFile = $cruiseControlFile;
$this->projectName = $projectName;
}

/**
Expand Down Expand Up @@ -205,6 +222,14 @@ protected function buildOptions($command)
$options[] = '-m';
}

if ($this->cruiseControlFile) {
$options[] = '--cc-file=' . escapeshellarg($this->cruiseControlFile);
}

if ($this->projectName) {
$options[] = '--cc-name=' . escapeshellarg($this->projectName);
}

if ($this->runner->shouldStopOnFailure()) {
$options[] = '--stop-on-failure';
}
Expand Down
7 changes: 6 additions & 1 deletion src/Stagehand/TestRunner/Resources/config/general.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@ parameters:
recursive: false
continuous_testing: false
continuous_testing_watch_dirs: []
notify: false
notify_enabled: false # available since Release 3.6.3X
notify_file: ~ # available since Release 3.6.3X
notify_project_name: ~ # available since Release 3.6.3X
test_methods: []
test_classes: []
junit_xml_file: null
Expand Down Expand Up @@ -117,6 +119,7 @@ services:
# Notification
notifier:
class: "%notifier.class%"
arguments: [ "%notify_file%", "%notify_project_name%" ]
calls:
- [ setLegacyProxy, [ "@legacy_proxy" ] ]
- [ setOS, [ "@os" ] ]
Expand All @@ -135,6 +138,8 @@ services:
- "@terminal"
- "@test_target_repository"
- "@?command_line_option_builder"
- "%notify_file%"
- "%notify_project_name%"
continuous_test_runner:
class: "%continuous_test_runner.class%"
arguments: [ "@preparer", "@command_line_builder" ]
Expand Down
2 changes: 1 addition & 1 deletion src/Stagehand/TestRunner/Resources/config/phpunit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ services:
- [ setDetailedProgress, [ "%detailed_progress%" ] ]
- [ setJUnitXMLFile, [ "%junit_xml_file%" ] ]
- [ setJUnitXMLRealtime, [ "%junit_xml_realtime%" ] ]
- [ setNotify, [ "%notify%" ] ]
- [ setNotify, [ "%notify_enabled%" ] ]
- [ setPHPUnitConfigurationFactory, [ "@phpunit.phpunit_configuration_factory" ] ]
- [ setStopOnFailure, [ "%stop_on_failure%" ] ]
- [ setTerminal, [ "@terminal" ] ]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,23 @@ function (\PHPUnit_Framework_TestCase $test, ApplicationContext $applicationCont
$test->assertTrue($applicationContext->createComponent('runner')->shouldNotify());
}
),
array(
array('--cc-file=path/to/somewhere'),
function (\PHPUnit_Framework_TestCase $test, ApplicationContext $applicationContext, Transformation $transformation) {
},
function (\PHPUnit_Framework_TestCase $test, ApplicationContext $applicationContext, Transformation $transformation) {
$test->assertNotNull($applicationContext->createComponent('notifier')->getFile());
$test->assertTrue($applicationContext->createComponent('runner')->shouldNotify());
}
),
array(
array('--cc-file=path/to/somewhere --cc-name="example project"'),
function (\PHPUnit_Framework_TestCase $test, ApplicationContext $applicationContext, Transformation $transformation) {
},
function (\PHPUnit_Framework_TestCase $test, ApplicationContext $applicationContext, Transformation $transformation) {
$test->assertNotNull($applicationContext->createComponent('notifier')->getProjectName());
}
),
array(
array('--config=example.yml'),
function (\PHPUnit_Framework_TestCase $test, ApplicationContext $applicationContext, Transformation $transformation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,12 @@ public static function setUpBeforeClass()
self::$configurators[] = function (ApplicationContext $applicationContext) {
$applicationContext->createComponent('runner')->setDetailedProgress(true);
};
self::$configurators[] = function (ApplicationContext $applicationContext) {
$applicationContext->createComponent('notifier');
};
self::$configurators[] = function (ApplicationContext $applicationContext) {
$applicationContext->createComponent('notifier');
};
}

/**
Expand Down Expand Up @@ -202,6 +208,8 @@ public function commandLineOptions()
array(array(escapeshellarg(strtolower($this->getPluginID())), '-R', '--stop-on-failure'), array(true, true, true)),
array(array(escapeshellarg(strtolower($this->getPluginID())), '-R', '--test-file-pattern=' . escapeshellarg('PATTERN')), array(true, true, true)),
array(array(escapeshellarg(strtolower($this->getPluginID())), '-R', '--detailed-progress'), array(true, true, true)),
array(array(escapeshellarg(strtolower($this->getPluginID())), '-R', '--cc-file=' . escapeshellarg('/path/to/somewhere')), array(true, true, false)),
array(array(escapeshellarg(strtolower($this->getPluginID())), '-R', '--cc-file=' . escapeshellarg('/path/to/somewhere') . ' --cc-name="foo project"'), array(true, true, false)),
);

return array_map(function (array $preservedConfiguration) {
Expand Down