Skip to content

Commit

Permalink
[Continuation] Removed the FlowExecution::activated() method. (Issue p…
Browse files Browse the repository at this point in the history
…iece#4)

* [Continuation] Removed the ContinuationServer::getView() method.
* [PageFlow] Added the IPageFlow::getView() method.
* Removed unnecessary test methods.
  • Loading branch information
iteman committed Sep 18, 2012
1 parent 9cb0f82 commit 0675c29
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 91 deletions.
22 changes: 0 additions & 22 deletions src/Piece/Flow/Continuation/ContinuationServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,6 @@ public function invoke($payload)
return $this->activeFlowExecutionTicket;
}

/**
* Gets an appropriate view string which corresponding to the current
* state.
*
* @return string
* @throws \Piece\Flow\Core\MethodInvocationException
*/
public function getView()
{
if (!$this->flowExecution->activated()) {
throw new MethodInvocationException(__FUNCTION__ . ' method must be called after starting/continuing flows.');
}

$flow = $this->flowExecution->getActiveFlow();
return $flow->getView();
}

/**
* Sets a callback for getting an event name.
*
Expand Down Expand Up @@ -244,15 +227,10 @@ public function getActiveFlowID()

/**
* @return \Piece\Flow\Continuation\PageFlowInstance
* @throws \Piece\Flow\Core\MethodInvocationException
* @since Method available since Release 2.0.0
*/
public function getActivePageFlowInstance()
{
if (!$this->flowExecution->activated()) {
throw new MethodInvocationException(__FUNCTION__ . ' method must be called after starting/continuing flows.');
}

return $this->flowExecution->findByID($this->activeFlowExecutionTicket);
}

Expand Down
10 changes: 0 additions & 10 deletions src/Piece/Flow/Continuation/FlowExecution.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,6 @@ public function activateFlowExecution($flowExecutionTicket, $flowID)
$this->activated = true;
}

/**
* Returns whether the flow execution has activated or not.
*
* @return boolean
*/
public function activated()
{
return $this->activated;
}

/**
* Returns whether or not a flow execution exists in the flow executions.
*
Expand Down
5 changes: 5 additions & 0 deletions src/Piece/Flow/Continuation/NullPageFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ public function getCurrentStateName()
{
return null;
}

public function getView()
{
return null;
}
}

/*
Expand Down
5 changes: 5 additions & 0 deletions src/Piece/Flow/Continuation/PageFlowInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ public function getCurrentStateName()
{
return $this->pageFlow->getCurrentStateName();
}

public function getView()
{
return $this->pageFlow->getView();
}
}

/*
Expand Down
9 changes: 9 additions & 0 deletions src/Piece/Flow/PageFlow/IPageFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,15 @@ public function checkLastEvent();
* @throws \Piece\Flow\Core\MethodInvocationException
*/
public function getCurrentStateName();

/**
* Gets the appropriate view string corresponding to the current state.
*
* @return string
* @throws \Piece\Flow\Core\MethodInvocationException
* @throws \Piece\Flow\PageFlow\InvalidTransitionException
*/
public function getView();
}

/*
Expand Down
8 changes: 0 additions & 8 deletions src/Piece/Flow/PageFlow/PageFlow.php
Original file line number Diff line number Diff line change
Expand Up @@ -149,14 +149,6 @@ public function setActionInvoker(ActionInvoker $actionInvoker)
$this->actionInvoker = $actionInvoker;
}

/**
* Gets an appropriate view string which corresponding to the current
* state.
*
* @return string
* @throws \Piece\Flow\Core\MethodInvocationException
* @throws \Piece\Flow\PageFlow\InvalidTransitionException
*/
public function getView()
{
if (!$this->started()) {
Expand Down
57 changes: 6 additions & 51 deletions test/Piece/Flow/Continuation/ContinuationServerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ public function testInvocationInMultipleFlowModeAndFlowInNonExclusiveMode()
$flowExecutionTicket2 = $server->invoke(new \stdClass());

$this->assertRegexp('/[0-9a-f]{40}/', $flowExecutionTicket1);
$this->assertEquals('Counter', $server->getView());
$this->assertEquals('Counter', $server->getActivePageFlowInstance()->getView());
$this->assertEquals(1, $server->getActivePageFlowInstance()->getAttribute('counter'));
$this->assertEquals($flowExecutionTicket1, $flowExecutionTicket2);
}
Expand Down Expand Up @@ -151,7 +151,7 @@ public function testMultipleInvocationInMultipleFlowModeAndFlowInNonExclusiveMod
$this->assertEquals(0, $server->getActivePageFlowInstance()->getAttribute('counter'));
$this->assertRegexp('/[0-9a-f]{40}/', $flowExecutionTicket1);
$this->assertRegexp('/[0-9a-f]{40}/', $flowExecutionTicket2);
$this->assertEquals('SecondCounter', $server->getView());
$this->assertEquals('SecondCounter', $server->getActivePageFlowInstance()->getView());
$this->assertTrue($flowExecutionTicket1 != $flowExecutionTicket2);

$server->shutdown();
Expand All @@ -166,7 +166,7 @@ public function testMultipleInvocationInMultipleFlowModeAndFlowInNonExclusiveMod

$this->assertEquals(1, $server->getActivePageFlowInstance()->getAttribute('counter'));

$this->assertEquals('Counter', $server->getView());
$this->assertEquals('Counter', $server->getActivePageFlowInstance()->getView());
$this->assertEquals($flowExecutionTicket1, $flowExecutionTicket3);

$server->shutdown();
Expand All @@ -179,7 +179,7 @@ public function testMultipleInvocationInMultipleFlowModeAndFlowInNonExclusiveMod
$this->flowExecutionTicket = $flowExecutionTicket2;
$flowExecutionTicket4 = $server->invoke(new \stdClass());

$this->assertEquals('SecondCounter', $server->getView());
$this->assertEquals('SecondCounter', $server->getActivePageFlowInstance()->getView());
$this->assertEquals(1, $server->getActivePageFlowInstance()->getAttribute('counter'));
$this->assertEquals($flowExecutionTicket2, $flowExecutionTicket4);

Expand All @@ -193,7 +193,7 @@ public function testMultipleInvocationInMultipleFlowModeAndFlowInNonExclusiveMod
$this->flowExecutionTicket = null;
$flowExecutionTicket5 = $server->invoke(new \stdClass());

$this->assertEquals('SecondCounter', $server->getView());
$this->assertEquals('SecondCounter', $server->getActivePageFlowInstance()->getView());
$this->assertEquals(0, $server->getActivePageFlowInstance()->getAttribute('counter'));
$this->assertTrue($flowExecutionTicket2 != $flowExecutionTicket5);
}
Expand Down Expand Up @@ -277,7 +277,7 @@ public function testInvocationInMultipleFlowModeAndFlowInExclusiveMode()

$this->assertRegexp('/[0-9a-f]{40}/', $flowExecutionTicket1);
$this->assertRegexp('/[0-9a-f]{40}/', $flowExecutionTicket3);
$this->assertEquals('Counter', $server->getView());
$this->assertEquals('Counter', $server->getActivePageFlowInstance()->getView());
$this->assertEquals($flowExecutionTicket1, $flowExecutionTicket2);
$this->assertTrue($flowExecutionTicket1 != $flowExecutionTicket3);
}
Expand Down Expand Up @@ -330,32 +330,6 @@ public function testSettingAttribute()
$this->assertEquals('bar', $baz2->foo);
}

/**
* @expectedException \Piece\Flow\Core\MethodInvocationException
*/
public function testFailureToSetAttributeBeforeStartingContinuation()
{
$server = new ContinuationServer(new PageFlowRepository(new PageFlowRegistry($this->cacheDirectory, '.yaml'), $this->cacheDirectory, true));
$server->addFlow('Counter');
$server->setEventNameCallback(array($this, 'getEventName'));
$server->setFlowExecutionTicketCallback(array($this, 'getFlowExecutionTicket'));
$server->setFlowIDCallback(array($this, 'getFlowID'));
$server->getActivePageFlowInstance()->setAttribute('foo', 'bar');
}

/**
* @expectedException \Piece\Flow\Core\MethodInvocationException
*/
public function testFailureToGetAttributeBeforeStartingContinuation()
{
$server = new ContinuationServer(new PageFlowRepository(new PageFlowRegistry($this->cacheDirectory, '.yaml'), $this->cacheDirectory, true));
$server->addFlow('Counter');
$server->setEventNameCallback(array($this, 'getEventName'));
$server->setFlowExecutionTicketCallback(array($this, 'getFlowExecutionTicket'));
$server->setFlowIDCallback(array($this, 'getFlowID'));
$server->getActivePageFlowInstance()->getAttribute('foo');
}

public function testStartingNewFlowExecutionAfterShuttingDownContinuationInNonExclusiveMode()
{
$shutdownCount = 0;
Expand Down Expand Up @@ -759,25 +733,6 @@ public function testCurrentStateNameShouldBeAbleToGetIfContinuationHasActivated(
$this->assertEquals('DisplayEditFinish', $server->getActivePageFlowInstance()->getCurrentStateName());
}

/**
* @expectedException \Piece\Flow\Core\MethodInvocationException
* @since Method available since Release 1.14.0
*/
public function testGetCurrentStateNameShouldRaiseExceptionIfContinuationHasNotActivated()
{
$flowName = 'CheckLastEvent';
$server = new ContinuationServer(new PageFlowRepository(new PageFlowRegistry($this->cacheDirectory, '.yaml'), $this->cacheDirectory, true));
$server->addFlow($flowName);
$server->setEventNameCallback(array($this, 'getEventName'));
$server->setFlowExecutionTicketCallback(array($this, 'getFlowExecutionTicket'));
$server->setFlowIDCallback(array($this, 'getFlowID'));

$this->flowID = $flowName;
$this->eventName = null;
$this->flowExecutionTicket = null;
$server->getActivePageFlowInstance()->getCurrentStateName();
}

/**
* @since Method available since Release 1.15.1
*/
Expand Down

0 comments on commit 0675c29

Please sign in to comment.