ResultTest.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. namespace Ddeboer\DataImport\Tests;
  3. use Ddeboer\DataImport\Result;
  4. /**
  5. * Tests For Workflow Result
  6. *
  7. * @author Aydin Hassan <aydin@hotmail.co.uk>
  8. */
  9. class ResultTest extends \PHPUnit_Framework_TestCase
  10. {
  11. public function testResultName()
  12. {
  13. $result = new Result('export', new \DateTime, new \DateTime, 10, new \SplObjectStorage());
  14. $this->assertSame('export', $result->getName());
  15. }
  16. public function testResultCounts()
  17. {
  18. $result = new Result('export', new \DateTime, new \DateTime, 10, new \SplObjectStorage());
  19. $this->assertSame(10, $result->getTotalProcessedCount());
  20. $this->assertSame(10, $result->getSuccessCount());
  21. $this->assertSame(0, $result->getErrorCount());
  22. $exceptions = new \SplObjectStorage();
  23. $exceptions->attach(new \Exception());
  24. $exceptions->attach(new \Exception());
  25. $result = new Result('export', new \DateTime, new \DateTime, 10, $exceptions);
  26. $this->assertSame(10, $result->getTotalProcessedCount());
  27. $this->assertSame(8, $result->getSuccessCount());
  28. $this->assertSame(2, $result->getErrorCount());
  29. }
  30. public function testDates()
  31. {
  32. $startDate = new \DateTime("22-07-2014 22:00");
  33. $endDate = new \DateTime("22-07-2014 23:30");
  34. $result = new Result('export', $startDate, $endDate, 10, new \SplObjectStorage());
  35. $this->assertSame($startDate, $result->getStartTime());
  36. $this->assertSame($endDate, $result->getEndTime());
  37. $this->assertInstanceOf('DateInterval', $result->getElapsed());
  38. }
  39. public function testHasErrorsReturnsTrueIfAnyExceptions()
  40. {
  41. $exceptions = new \SplObjectStorage();
  42. $exceptions->attach(new \Exception());
  43. $exceptions->attach(new \Exception());
  44. $result = new Result('export', new \DateTime, new \DateTime, 10, $exceptions);
  45. $this->assertTrue($result->hasErrors());
  46. }
  47. public function testHasErrorsReturnsFalseIfNoExceptions()
  48. {
  49. $result = new Result('export', new \DateTime, new \DateTime, 10, new \SplObjectStorage());
  50. $this->assertFalse($result->hasErrors());
  51. }
  52. public function testGetExceptions()
  53. {
  54. $exceptions = new \SplObjectStorage();
  55. $exceptions->attach(new \Exception());
  56. $exceptions->attach(new \Exception());
  57. $result = new Result('export', new \DateTime, new \DateTime, 10, $exceptions);
  58. $this->assertSame($exceptions, $result->getExceptions());
  59. }
  60. }