Skip to content

Commit

Permalink
Merge f5ad50d into c76d0c6
Browse files Browse the repository at this point in the history
  • Loading branch information
filp committed Jun 25, 2013
2 parents c76d0c6 + f5ad50d commit b620f6a
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 10 deletions.
10 changes: 10 additions & 0 deletions src/Athletic/Athletic.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public function __construct()

public function run()
{
$this->setupErrorHandler();
$classesToBenchmark = $this->getClassesToBenchmark();
$this->benchmark($classesToBenchmark);
}
Expand Down Expand Up @@ -60,5 +61,14 @@ private function benchmark($classes)
$suite->publishResults();

}

private function setupErrorHandler()
{
/** @var Athletic\Common\ErrorHandlerInterace $handler */
$handler = $this['errorHandler'];

set_exception_handler(array($handler, 'handleException'));
set_error_handler(array($handler, 'handleError'));
}
}

43 changes: 43 additions & 0 deletions src/Athletic/Common/CmdLineErrorHandler.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

namespace Athletic\Common;
use Commando\Command;
use ErrorException;

/**
* CmdLineErrorHandler
* @package Athletic
*/
class CmdLineErrorHandler implements ErrorHandlerInterface
{
/** @var Command $command */
private $command;

/**
* @param Command $command
*/
public function __construct($command)
{
$this->command = $command;
}

/*
* {@inheritDoc}
*/
public function handleException(\Exception $exception)
{
$this->command->error($exception);
}

/*
* {@inheritDoc}
*/
public function handleError($errorLevel, $errorMessage, $errorFile, $errorLine, $errorContext = array())
{
// Translate the error to an ErrorException and delegate it to the
// exception handler:
$this->handleException(
new ErrorException($errorMessage, $errorLevel, null, $errorFile, $errorLine)
);
}
}
19 changes: 9 additions & 10 deletions src/Athletic/Common/DICBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ public function __construct($athletic)

public function buildDependencyGraph()
{

$this->setupDiscovery();
$this->setupParser();
$this->setupCmdLine();
Expand All @@ -43,7 +42,7 @@ public function buildDependencyGraph()
$this->setupClassRunner();
$this->setupMethodResults();
$this->setupClassResults();

$this->setupErrorHandler();
}


Expand Down Expand Up @@ -72,8 +71,6 @@ private function setupDiscovery()
$path = $cmdLine->getSuitePath();
return new $dic['discoveryClass']($dic['parserFactory'], $path);
};


}


Expand All @@ -90,8 +87,6 @@ private function setupParser()
return new $dic['parserClass']($path);
};
};


}


Expand Down Expand Up @@ -129,7 +124,6 @@ private function setupMethodResults()

private function setupCmdLine()
{

$this->athletic['cmdLine'] = function ($dic) {
return new CmdLine($dic['command']);
};
Expand All @@ -142,8 +136,6 @@ private function setupCmdLine()

private function setupFormatter()
{


$this->athletic['formatterClass'] = '\Athletic\Formatters\DefaultFormatter';
$this->athletic['formatter'] = function ($dic) {
return new $dic['formatterClass']();
Expand All @@ -162,11 +154,18 @@ private function setupPublisher()

private function setupSuiteRunner()
{

$this->athletic['suiteRunnerClass'] = '\Athletic\Runners\SuiteRunner';
$this->athletic['suiteRunner'] = function ($dic) {
return new $dic['suiteRunnerClass']($dic['publisher'], $dic['classResultsFactory'], $dic['classRunnerFactory']);
};

}

private function setupErrorHandler()
{
$this->athletic['errorHandlerClass'] = '\Athletic\Common\CmdLineErrorHandler';
$this->athletic['errorHandler'] = function($dic) {
return new $dic['errorHandlerClass']($dic['command']);
};
}
}
24 changes: 24 additions & 0 deletions src/Athletic/Common/ErrorHandlerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

namespace Athletic\Common;

/**
* ErrorHandlerInterface
* @package Athletic
*/
interface ErrorHandlerInterface
{
/**
* @param int $errorLevel
* @param string $errorMessage
* @param string $errorFile
* @param int $errorLine
* @param array $errorContext
*/
public function handleError($errorLevel, $errorMessage, $errorFile, $errorLine, $errorContext = array());

/**
* @param \Exception $exception
*/
public function handleException(\Exception $exception);
}

0 comments on commit b620f6a

Please sign in to comment.