public function previous()
 {
     $stateString = $this->getState();
     if (is_null($stateString)) {
         throw new \common_exception_Error('Called previous on a non existing test execution');
     }
     $execution = TestExecutionState::fromString($stateString);
     if ($execution->hasPrevious()) {
         $execution->previous();
         $this->setState($execution->toString());
         $api = $this->buildItemScript($execution);
     } else {
         $api = null;
     }
     $this->returnJson(array('api' => $api, 'next' => $execution->hasNext(), 'previous' => $execution->hasPrevious()));
 }
 public function testToString()
 {
     $testExecutionId = 'myTestId';
     $compilationId = 'myCompilationId';
     $this->testRunnerService->expects($this->once())->method('getItemData')->with($compilationId)->willReturn(array('myFirstKey'));
     $execution = TestExecutionState::initNew($testExecutionId, $compilationId);
     $string = json_encode(array('testExecutionId' => $testExecutionId, 'compilationId' => $compilationId, 'current' => 0, 'itemExecutions' => array(array('itemIndex' => 0, 'callId' => $testExecutionId . '_0'))));
     $this->assertEquals($string, $execution->toString());
 }