Skip to content

Instantly share code, notes, and snippets.

@testingbot
Created May 17, 2012 19:53
Show Gist options
  • Save testingbot/2721226 to your computer and use it in GitHub Desktop.
Save testingbot/2721226 to your computer and use it in GitHub Desktop.
phpunit custom junit logger
phpunit.xml
------------------
<?xml version="1.0" encoding="UTF-8"?>
<phpunit
backupGlobals="false"
colors="true">
<testsuites>
<testsuite name="PHPUnitee">
<file>SimpleTest.php</file>
</testsuite>
</testsuites>
<listeners>
<listener class="MyListener" file="MyListener.php">
<arguments>
<string>results.xml</string>
</arguments>
</listener>
</listeners>
</phpunit>
--------------------------------
SimpleTest.php
-------------------------------
<?php
class SimpleTest extends PHPUnit_Extensions_TestingBotTestCase
{
public static $browsers = array(
array(
'name' => 'FireFox',
'browser' => 'firefox',
'platform' => 'WINDOWS',
'browserVersion' => '12',
'timeout' => 1000,
)
);
protected function setUp()
{
$this->setHost('hub.testingbot.com');
$this->setPort(4444);
$this->setBrowserUrl('http://www.google.com/');
$this->setDesiredCapabilities(array(
'screenrecorder' => false,
));
}
public function testTitle()
{
$this->open('/');
$this->assertTitle('bla2');
}
}
?>
-------------------------------
MyListener
-------------------------------
<?php
class MyListener extends PHPUnit_Util_Log_JUnit implements PHPUnit_Framework_TestListener
{
/**
* A test ended.
*
* @param PHPUnit_Framework_Test $test
* @param float $time
*/
public function endTest(PHPUnit_Framework_Test $test, $time)
{
if (!$test instanceof PHPUnit_Framework_Warning) {
if ($this->attachCurrentTestCase) {
if ($test instanceof PHPUnit_Framework_TestCase) {
$numAssertions = $test->getNumAssertions();
$this->testSuiteAssertions[$this->testSuiteLevel] += $numAssertions;
$this->currentTestCase->setAttribute(
'assertions', $numAssertions
);
}
$this->currentTestCase->setAttribute(
'time', sprintf('%F', $time)
);
// add custom timestamp
$this->currentTestCase->setAttribute(
'timestamp', time()
);
$this->testSuites[$this->testSuiteLevel]->appendChild(
$this->currentTestCase
);
$this->testSuiteTests[$this->testSuiteLevel]++;
$this->testSuiteTimes[$this->testSuiteLevel] += $time;
}
}
$this->attachCurrentTestCase = TRUE;
$this->currentTestCase = NULL;
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment