-
Notifications
You must be signed in to change notification settings - Fork 123
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #93 from AydinHassan/workflow-result
WIP: Return Result Object
- Loading branch information
Showing
5 changed files
with
348 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,150 @@ | ||
<?php | ||
|
||
namespace Ddeboer\DataImport; | ||
|
||
use DateTime; | ||
use DateInterval; | ||
use Ddeboer\DataImport\Exception\ExceptionInterface; | ||
|
||
/** | ||
* Simple Container for Workflow | ||
* Results | ||
* | ||
* @author Aydin Hassan <[email protected]> | ||
*/ | ||
class Result | ||
{ | ||
|
||
/** | ||
* Identifier given to the import/export | ||
* | ||
* @var string | ||
*/ | ||
protected $name; | ||
|
||
/** | ||
* @var DateTime | ||
*/ | ||
protected $startTime; | ||
|
||
/** | ||
* @var DateTime | ||
*/ | ||
protected $endTime; | ||
|
||
/** | ||
* @var DateInterval | ||
*/ | ||
protected $elapsed; | ||
|
||
/** | ||
* @var int Number Of Errors | ||
*/ | ||
protected $errorCount = 0; | ||
|
||
/** | ||
* @var int Number of Successes | ||
*/ | ||
protected $successCount = 0; | ||
|
||
/** | ||
* @var int Total Rows Processed | ||
*/ | ||
protected $totalProcessedCount = 0; | ||
|
||
/** | ||
* @var ExceptionInterface[] | ||
*/ | ||
protected $exceptions; | ||
|
||
/** | ||
* @param $name | ||
* @param DateTime $startTime | ||
* @param DateTime $endTime | ||
* @param $totalCount | ||
* @param ExceptionInterface[] $exceptions | ||
*/ | ||
public function __construct($name, DateTime $startTime, DateTime $endTime, $totalCount, array $exceptions = array()) | ||
{ | ||
$this->name = $name; | ||
$this->startTime = $startTime; | ||
$this->endTime = $endTime; | ||
$this->elapsed = $startTime->diff($endTime); | ||
$this->totalProcessedCount = $totalCount; | ||
$this->errorCount = count($exceptions); | ||
$this->successCount = $totalCount - $this->errorCount; | ||
$this->exceptions = $exceptions; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getName() | ||
{ | ||
return $this->name; | ||
} | ||
|
||
/** | ||
* @return DateTime | ||
*/ | ||
public function getStartTime() | ||
{ | ||
return $this->startTime; | ||
} | ||
|
||
/** | ||
* @return DateTime | ||
*/ | ||
public function getEndTime() | ||
{ | ||
return $this->endTime; | ||
} | ||
|
||
/** | ||
* @return DateInterval | ||
*/ | ||
public function getElapsed() | ||
{ | ||
return $this->elapsed; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getErrorCount() | ||
{ | ||
return $this->errorCount; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getSuccessCount() | ||
{ | ||
return $this->successCount; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getTotalProcessedCount() | ||
{ | ||
return $this->totalProcessedCount; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function hasErrors() | ||
{ | ||
return count($this->exceptions) > 0; | ||
} | ||
|
||
/** | ||
* @return ExceptionInterface[] | ||
*/ | ||
public function getExceptions() | ||
{ | ||
return $this->exceptions; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?php | ||
|
||
namespace Ddeboer\DataImport\Tests; | ||
|
||
use Ddeboer\DataImport\Result; | ||
|
||
/** | ||
* Tests For Workflow Result | ||
* | ||
* @author Aydin Hassan <[email protected]> | ||
*/ | ||
class ResultTest extends \PHPUnit_Framework_TestCase | ||
{ | ||
public function testResultName() | ||
{ | ||
$result = new Result('export', new \DateTime, new \DateTime, 10); | ||
$this->assertSame('export', $result->getName()); | ||
} | ||
|
||
public function testResultCounts() | ||
{ | ||
$result = new Result('export', new \DateTime, new \DateTime, 10); | ||
$this->assertSame(10, $result->getTotalProcessedCount()); | ||
$this->assertSame(10, $result->getSuccessCount()); | ||
$this->assertSame(0, $result->getErrorCount()); | ||
$result = new Result('export', new \DateTime, new \DateTime, 10, array(new \Exception, new \Exception)); | ||
$this->assertSame(10, $result->getTotalProcessedCount()); | ||
$this->assertSame(8, $result->getSuccessCount()); | ||
$this->assertSame(2, $result->getErrorCount()); | ||
|
||
} | ||
|
||
public function testDates() | ||
{ | ||
$startDate = new \DateTime("22-07-2014 22:00"); | ||
$endDate = new \DateTime("22-07-2014 23:30"); | ||
|
||
$result = new Result('export', $startDate, $endDate, 10); | ||
|
||
$this->assertSame($startDate, $result->getStartTime()); | ||
$this->assertSame($endDate, $result->getEndTime()); | ||
$this->assertInstanceOf('DateInterval', $result->getElapsed()); | ||
} | ||
|
||
public function testHasErrorsReturnsTrueIfAnyExceptions() | ||
{ | ||
$result = new Result('export', new \DateTime, new \DateTime, 10, array(new \Exception, new \Exception)); | ||
$this->assertTrue($result->hasErrors()); | ||
} | ||
|
||
public function testHasErrorsReturnsFalseIfNoExceptions() | ||
{ | ||
$result = new Result('export', new \DateTime, new \DateTime, 10); | ||
$this->assertFalse($result->hasErrors()); | ||
} | ||
|
||
public function testGetExceptions() | ||
{ | ||
$exceptions = array(new \Exception, new \Exception); | ||
$result = new Result('export', new \DateTime, new \DateTime, 10, $exceptions); | ||
$this->assertSame($exceptions, $result->getExceptions()); | ||
} | ||
} |
Oops, something went wrong.