Skip to content

Commit

Permalink
Merge pull request #59 from OndraM/fix/fix-process-status-publishing
Browse files Browse the repository at this point in the history
Fix publishing of process status and result to xml file
  • Loading branch information
OndraM committed Apr 25, 2016
2 parents 9f939f7 + 6998f00 commit 6891c8f
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 18 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
<!-- There is always Unreleased section on the top. Subsections (Added, Changed, Fixed, Removed) should be added as needed. -->

## Unreleased
- Nothing yet - everything is released.
### Fixed
- Process status and result was not properly published to results.xml file.

## 1.4.0 - 2016-04-07
### Added
Expand Down
19 changes: 14 additions & 5 deletions src-tests/Process/ProcessWrapperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -156,13 +156,13 @@ public function testShouldFailIfWrongProcessStatusGiven()
$wrapper->setStatus('WrongStatus');
}

public function testShouldPublishProcessStatusWhenStatusWasSet()
public function testShouldPublishProcessStatusWhenInitializedAndWhenStatusWasSet()
{
$publisherMock = $this->getMockBuilder(XmlPublisher::class)
->disableOriginalConstructor()
->getMock();

$publisherMock->expects($this->once())
$publisherMock->expects($this->at(0))
->method('publishResults')
->with(
'FooClassName',
Expand All @@ -172,10 +172,19 @@ public function testShouldPublishProcessStatusWhenStatusWasSet()
$this->identicalTo(null)
);

$wrapper = new ProcessWrapper(new Process(''), 'FooClassName');
$wrapper->setPublisher($publisherMock);
$publisherMock->expects($this->at(1))
->method('publishResults')
->with(
'FooClassName',
ProcessWrapper::PROCESS_STATUS_DONE,
$this->identicalTo(ProcessWrapper::PROCESS_RESULT_FAILED),
$this->identicalTo(null),
$this->identicalTo(null)
);

$wrapper->setStatus(ProcessWrapper::PROCESS_STATUS_QUEUED);
$wrapper = new ProcessWrapper(new Process(''), 'FooClassName', $publisherMock);

$wrapper->setStatus(ProcessWrapper::PROCESS_STATUS_DONE);
}

public function testShouldReturnErrorMessageIfProcessTimeoutIsDetected()
Expand Down
6 changes: 5 additions & 1 deletion src/Process/ProcessSetCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,11 @@ public function createFromFiles(
}

$className = key($classes);
$processWrapper = new ProcessWrapper($this->buildProcess($fileName, $phpunitArgs), $className);
$processWrapper = new ProcessWrapper(
$this->buildProcess($fileName, $phpunitArgs),
$className,
$this->publisher
);

if (!$ignoreDelays) {
$delayAfter = !empty($annotations['delayAfter']) ? current($annotations['delayAfter']) : '';
Expand Down
15 changes: 4 additions & 11 deletions src/Process/ProcessWrapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,20 +59,14 @@ class ProcessWrapper
/**
* @param Process $process Instance of PHPUnit process
* @param string $className Tested class fully qualified name
* @param AbstractPublisher $publisher
*/
public function __construct(Process $process, $className)
public function __construct(Process $process, $className, AbstractPublisher $publisher = null)
{
$this->process = $process;
$this->className = $className;
$this->setStatus(self::PROCESS_STATUS_QUEUED);
}

/**
* @param AbstractPublisher $publisher
*/
public function setPublisher(AbstractPublisher $publisher)
{
$this->publisher = $publisher;
$this->setStatus(self::PROCESS_STATUS_QUEUED);
}

/**
Expand Down Expand Up @@ -158,14 +152,13 @@ public function setStatus($status)

$this->status = $status;

$result = null;
if ($status == self::PROCESS_STATUS_DONE) {
$this->result = $this->resolveResult();
$this->finishedTime = time();
}

if ($this->publisher) {
$this->publisher->publishResults($this->getClassName(), $status, $result);
$this->publisher->publishResults($this->getClassName(), $status, $this->result);
}
}

Expand Down

0 comments on commit 6891c8f

Please sign in to comment.