Skip to content

Commit

Permalink
ArrayLoader should respect state machines state accessor
Browse files Browse the repository at this point in the history
added test for array loader with custom state accessor
  • Loading branch information
realshadow committed Apr 18, 2016
1 parent dc53d48 commit c7a5672
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/Finite/Loader/ArrayLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ public function load(StateMachineInterface $stateMachine)
$this->callbackBuilderFactory = new CallbackBuilderFactory();
}

$stateMachine->setStateAccessor(new PropertyPathStateAccessor($this->config['property_path']));
if (!$stateMachine->hasStateAccessor()) {

This comment has been minimized.

Copy link
@Gregoire-M

Gregoire-M Feb 23, 2018

This causes a BC break, see #138

$stateMachine->setStateAccessor(new PropertyPathStateAccessor($this->config['property_path']));
}

$stateMachine->setGraph($this->config['graph']);

$this->loadStates($stateMachine);
Expand Down
8 changes: 8 additions & 0 deletions src/Finite/StateMachine/StateMachine.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,14 @@ public function setStateAccessor(StateAccessorInterface $stateAccessor)
$this->stateAccessor = $stateAccessor;
}

/**
* {@inheritdoc}
*/
public function hasStateAccessor()
{
return null !== $this->stateAccessor;
}

/**
* {@inheritdoc}
*/
Expand Down
5 changes: 5 additions & 0 deletions src/Finite/StateMachine/StateMachineInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ public function getDispatcher();
*/
public function setStateAccessor(StateAccessorInterface $stateAccessor);

/**
* @return bool
*/
public function hasStateAccessor();

/**
* @param string $graph
*/
Expand Down
10 changes: 10 additions & 0 deletions tests/Finite/Test/Loader/ArrayLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,8 +179,18 @@ public function testLoadWithProperties()
);

$this->object->load($sm);
}

public function testLoadWithCustomStateAccessor()
{
$sa = $this->getMock('Finite\State\Accessor\PropertyPathStateAccessor', array(), array(), 'CustomAccessor');

$sm = new StateMachine;
$sm->setStateAccessor($sa);

$this->object->load($sm);

$this->assertAttributeInstanceOf('CustomAccessor', 'stateAccessor', $sm);
}

public function testSupports()
Expand Down

0 comments on commit c7a5672

Please sign in to comment.