Skip to content

Commit

Permalink
don't know what's included, sorry
Browse files Browse the repository at this point in the history
  • Loading branch information
Nils Langner committed Jul 12, 2011
1 parent 2b783b6 commit d1bfba9
Show file tree
Hide file tree
Showing 9 changed files with 174 additions and 148 deletions.
52 changes: 26 additions & 26 deletions src/LiveTest/Cli/Runner.php
Expand Up @@ -44,31 +44,31 @@ class Runner extends ArgumentRunner
* @var ConfigConfig
*/
private $config;

/**
* The event dispatcher
* @var Dispatcher
*/
private $eventDispatcher;

/**
* The test run instance
* @var TestRun
*/
private $testRun;

/**
* The unique run id
* @var string
*/
private $runId;

/**
* Can the run method be called
* @var boolean
*/
private $runAllowed = true;

/**
* This function intializes the runner. It sets the runId, inits the configuration
* and registers the assigned listeners. Afterwards all listeners are notified. If
Expand All @@ -85,35 +85,35 @@ public function __construct($arguments, Dispatcher $dispatcher)
$this->eventDispatcher = $dispatcher;
$this->initRunId();
$this->initCoreListener($arguments);

parent::__construct($arguments);

$this->initConfig();
$this->eventDispatcher->simpleNotify('LiveTest.Runner.InitConfig', array ('config' => $this->config));

$this->initListeners();
$event = new Event('LiveTest.Runner.Init', array ('arguments' => $arguments));
$this->eventDispatcher->notifyUntil($event);
$this->runAllowed = !$event->isProcessed();
}

private function initCoreListener($arguments)
{
$this->eventDispatcher->connectListener(new \LiveTest\Packages\Debug\Listeners\Debug($this->runId, $this->eventDispatcher), 10);
$this->eventDispatcher->connectListener(new \LiveTest\Packages\Feedback\Listener\Send($this->runId, $this->eventDispatcher), 10);
$this->eventDispatcher->connectListener(new \LiveTest\Packages\Runner\Listeners\Credentials($this->runId, $this->eventDispatcher), 10);
$this->eventDispatcher->connectListener(new \LiveTest\Packages\Runner\Listeners\DefaultDomain($this->runId, $this->eventDispatcher), 10);
$this->eventDispatcher->connectListener(new \LiveTest\Packages\Runner\Listeners\DefaultDomain($this->runId, $this->eventDispatcher), 10);
$this->eventDispatcher->simpleNotify('LiveTest.Runner.InitCore', array ('arguments' => $arguments));
}

/**
* Initializes the unique run id
*/
private function initRunId()
{
$this->runId = (string)time();
}

/**
* This function parses the config array and returns a config object. This config
* object can be handled by the event dispatcher.
Expand All @@ -124,7 +124,7 @@ private function initRunId()
private function parseConfig($configArray)
{
$config = new ConfigConfig();

$parser = new Parser('\\LiveTest\Config\\Tags\\Config\\');
try
{
Expand All @@ -134,10 +134,10 @@ private function parseConfig($configArray)
{
throw new ConfigurationException('Unknown tag ("' . $e->getTagName() . '") found in the configuration file.', null, $e);
}

return $config;
}

/**
* Initializes the global configuration. If the config argument is set, the default
* configuration and the given config file are merged. Otherwise the default config
Expand All @@ -146,7 +146,7 @@ private function parseConfig($configArray)
private function initConfig()
{
$config = new Yaml(__DIR__ . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'default' . DIRECTORY_SEPARATOR . 'config.yml', true);

if ($this->hasArgument('config'))
{
$currentConfig = new Yaml($this->getArgument('config'), true);
Expand All @@ -155,15 +155,15 @@ private function initConfig()
$this->config = $this->parseConfig($config->toArray());
$this->eventDispatcher->simpleNotify('LiveTest.Runner.ConfigInitialized', array ('config' => $this->config));
}

/**
* This function initializes and registrates all the listeners.
*/
private function initListeners()
{
$this->eventDispatcher->registerByConfig($this->config, $this->runId);
}

/**
* Returns true if the runner can be run. It will return false if a listener stops
* the run workflow.
Expand All @@ -172,17 +172,17 @@ public function isRunAllowed()
{
return $this->runAllowed;
}

/**
* Initializes the test run.
*/
private function initTestRun()
{
$this->eventDispatcher->simpleNotify('LiveTest.Runner.InitTestRun');

try
{
$properties = Properties::createByYamlFile($this->getArgument('testsuite'), $this->config->getDefaultDomain());
$properties = Properties::createByYamlFile($this->getArgument('testsuite'), $this->config->getDefaultDomain(), $this->eventDispatcher);
}
catch (\Zend\Config\Exception\InvalidArgumentException $e)
{
Expand All @@ -192,12 +192,12 @@ private function initTestRun()
{
throw new ConfigurationException('Error parsing testsuite configuration: ' . $e->getMessage(), null, $e);
}

$clients = $this->getClients($properties->getSessions());

$this->testRun = new Run($properties, $clients, $this->eventDispatcher);
}

private function getClients( $sessions )
{
$clients = array();
Expand All @@ -212,10 +212,10 @@ private function getClients( $sessions )
$this->eventDispatcher->simpleNotify('LiveTest.Runner.InitHttpClient', array ('client' => $client, 'sessionName' => $sessionName));
$clients[$sessionName] = $client;
}

return $clients;
}

/**
* Runs the runner. Before running you should check if run is allowed (isRunAllowed())
*
Expand Down
2 changes: 1 addition & 1 deletion src/LiveTest/Packages/Reporting/Format/templates/html.php
Expand Up @@ -26,7 +26,7 @@
</tr>
<tr>
<td></td>
<td>Duration: <b><?php echo \Base\Date\Duration::format($information->getDuration(), '%d day(s) ', '%d hour(s), ', '%d minute(s) ', '%d second(s)'); ?></b></td>
<td>Duration: <b><?php echo \Base\Date\Duration::format(floor($information->getDuration()/1000), '%d day(s) ', '%d hour(s), ', '%d minute(s) ', '%d second(s)'); ?></b></td>
</tr>
<tr>
<td></td>
Expand Down
2 changes: 1 addition & 1 deletion src/LiveTest/Packages/Runner/Listeners/StatusBar.php
Expand Up @@ -82,7 +82,7 @@ public function handleResult(Result $result, Response $response)
*/
public function postRun(Information $information)
{
$formattedDuration = Duration::format($information->getDuration(), '%d day(s) ', '%d hour(s) ', '%d minute(s) ', '%d second(s)' );
$formattedDuration = Duration::format(floor($information->getDuration()/1000), '%d day(s) ', '%d hour(s) ', '%d minute(s) ', '%d second(s)' );
echo " Tests: " . $this->testCount . ' (failed: '.$this->failureCount.', error: '.$this->errorCount.') - Duration: ' . $formattedDuration;
}
}
16 changes: 12 additions & 4 deletions src/LiveTest/TestRun/Result/Result.php
Expand Up @@ -10,7 +10,7 @@
namespace LiveTest\TestRun\Result;

use LiveTest\TestRun\Test;

use Base\Http\Response\Response;
use Base\Http\Request\Request;

/**
Expand Down Expand Up @@ -48,17 +48,25 @@ class Result
*/
private $request;

private $response;

private $sessionName;
public function __construct(Test $test, $status, $message, Request $request, $sessionName)

public function __construct(Test $test, $status, $message, Request $request, Response $response, $sessionName)
{
$this->test = $test;
$this->status = $status;
$this->message = $message;
$this->request = $request;
$this->response = $response;
$this->sessionName = $sessionName;
}

public function getResponse( )
{
return $this->response;
}

/**
* Returns the test information for this result.
*
Expand Down Expand Up @@ -94,7 +102,7 @@ public function getSessionName( )
{
return $this->sessionName;
}

/**
* Returns the uri of the page the test was run against.
*
Expand Down
43 changes: 24 additions & 19 deletions src/LiveTest/TestRun/Run.php
Expand Up @@ -25,19 +25,19 @@ class Run
* @var Properties
*/
private $properties;

/**
* The injected http client used to fire http request for the given pages.
* @var Client
*/
private $httpClient = null;

/**
* The injected event dispatcher. Used to notify the registered listeners.
* @var Dispatcher
*/
private $eventDispatcher;

/**
* @param Properties $properties
* @param Client $httpClient
Expand All @@ -49,7 +49,7 @@ public function __construct(Properties $properties, array $httpClients, Dispatch
$this->httpClients = $httpClients;
$this->properties = $properties;
}

/**
* This function creates and initializes the test case object using the init method.
*
Expand All @@ -59,7 +59,7 @@ public function __construct(Properties $properties, array $httpClients, Dispatch
private function getInitializedTestCase(Test $test)
{
$testCaseName = $test->getClassName();

if (class_exists($testCaseName))
{
$testCaseObject = new $testCaseName();
Expand All @@ -70,10 +70,10 @@ private function getInitializedTestCase(Test $test)
throw new \Exception('Class not found (' . $testCaseName . '). ');
}
\LiveTest\Functions::initializeObject($testCaseObject, $test->getParameter());

return $testCaseObject;
}

/**
* This function runs the given test set with the assigned response.
*
Expand All @@ -88,7 +88,7 @@ private function runTests(TestSet $testSet, Response $response, $sessionName)
{
$runStatus = Result::STATUS_SUCCESS;
$runMessage = '';

try
{
$testCase = $this->getInitializedTestCase($test);
Expand All @@ -104,11 +104,12 @@ private function runTests(TestSet $testSet, Response $response, $sessionName)
$runStatus = Result::STATUS_ERROR;
$runMessage = $e->getMessage();
}
$result = new Result($test, $runStatus, $runMessage, $testSet->getRequest(), $sessionName);
$result = new Result($test, $runStatus, $runMessage, $testSet->getRequest(), $response, $sessionName);
// @todo response is part of the result so it should not be handled separatly
$this->eventDispatcher->simpleNotify('LiveTest.Run.HandleResult', array ('result' => $result, 'response' => $response));
}
}

/**
* This function sends a http request and assigns the response to the test cases.
*
Expand All @@ -120,7 +121,7 @@ private function runTestSet(TestSet $testSet, $sessionName)
{
$connectionStatusValue = ConnectionStatus::SUCCESS;
$connectionStatusMessage = '';

try
{
$response = $this->httpClients[$sessionName]->request($testSet->getRequest());
Expand All @@ -130,17 +131,21 @@ private function runTestSet(TestSet $testSet, $sessionName)
$connectionStatusValue = ConnectionStatus::ERROR;
$connectionStatusMessage = $e->getMessage();
}

$connectionStatus = new ConnectionStatus($connectionStatusValue, $testSet->getRequest(), $connectionStatusMessage);

if( isset($response))
{
$connectionStatus->setResponse($response);
}

$this->eventDispatcher->simpleNotify('LiveTest.Run.HandleConnectionStatus', array ('connectionStatus' => $connectionStatus));

if ($connectionStatusValue === ConnectionStatus::SUCCESS)
{
$this->runTests($testSet, $response, $sessionName);
}
}

/**
* This function runs all test sets defined in the properties file.
*
Expand All @@ -150,20 +155,20 @@ private function runTestSet(TestSet $testSet, $sessionName)
public function run()
{
$this->eventDispatcher->simpleNotify('LiveTest.Run.PreRun', array ('properties' => $this->properties));

// @todo move timer to runner.php
$timer = new Timer();

foreach ($this->properties->getTestSets() as $sessionName => $testSets)
{
foreach ($testSets as $testSet)
{
$this->runTestSet($testSet, $sessionName);
}
}

$information = new Information($timer->stop(), $this->properties->getDefaultDomain());

$this->eventDispatcher->simpleNotify('LiveTest.Run.PostRun', array ('information' => $information));
}
}

0 comments on commit d1bfba9

Please sign in to comment.