Actualización

This commit is contained in:
Xes
2025-04-10 12:24:57 +02:00
parent 8969cc929d
commit 45420b6f0d
39760 changed files with 4303286 additions and 0 deletions

View File

@@ -0,0 +1,163 @@
<?php
namespace spec\SM\Callback;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use SM\Event\TransitionEvent;
use SM\StateMachine\StateMachineInterface;
class CallbackSpec extends ObjectBehavior
{
protected $specs = array();
protected $callable;
protected $sm;
function let(StateMachineInterface $sm)
{
$sm->getState()->willReturn('checkout');
$this->beConstructedWith($this->specs, $this->callable);
}
function it_is_initializable()
{
$this->shouldHaveType('SM\Callback\Callback');
}
function it_satisfies_simple_on(TransitionEvent $event)
{
$specs = array('on' => 'tested-transition');
$this->beConstructedWith($specs, $this->callable);
$event->getConfig()->willReturn($this->getConfig(array('dummy'), 'dummy'));
$event->getTransition()->willReturn('tested-transition');
$event->getState()->willReturn('dummy');
$this->isSatisfiedBy($event)->shouldReturn(true);
}
function it_doesnt_satisfies_simple_on(TransitionEvent $event)
{
$specs = array('on' => 'tested-transition');
$this->beConstructedWith($specs, $this->callable);
$event->getConfig()->willReturn($this->getConfig(array('dummy'), 'dummy'));
$event->getTransition()->willReturn('tested-transition-not-matching');
$this->isSatisfiedBy($event)->shouldReturn(false);
}
function it_satisfies_simple_from(TransitionEvent $event)
{
$specs = array('from' => 'tested-state');
$this->beConstructedWith($specs, $this->callable);
$event->getConfig()->willReturn($this->getConfig(array('tested-state'), 'dummy'));
$event->getTransition()->willReturn('dummy');
$event->getState()->willReturn('tested-state');
$this->isSatisfiedBy($event)->shouldReturn(true);
}
function it_doesnt_satisfies_simple_from(TransitionEvent $event)
{
$specs = array('from' => 'tested-state');
$this->beConstructedWith($specs, $this->callable);
$event->getConfig()->willReturn($this->getConfig(array('tested-state-not-matching'), 'dummy'));
$event->getTransition()->willReturn('dummy');
$event->getState()->willReturn('tested-state-not-matching');
$this->isSatisfiedBy($event)->shouldReturn(false);
}
function it_satisfies_simple_to(TransitionEvent $event)
{
$specs = array('to' => 'tested-state');
$this->beConstructedWith($specs, $this->callable);
$event->getConfig()->willReturn($this->getConfig(array('dummy'), 'tested-state'));
$event->getTransition()->willReturn('dummy');
$event->getState()->willReturn('dummy');
$this->isSatisfiedBy($event)->shouldReturn(true);
}
function it_doesnt_satisfies_simple_to(TransitionEvent $event)
{
$specs = array('from' => 'tested-state');
$this->beConstructedWith($specs, $this->callable);
$event->getConfig()->willReturn($this->getConfig(array('tested-state-not-matching'), 'dummy'));
$event->getTransition()->willReturn('dummy');
$event->getState()->willReturn('dummy');
$this->isSatisfiedBy($event)->shouldReturn(false);
}
function it_satisfies_complex_specs(TransitionEvent $event)
{
$specs = array('to' => 'tested-state-to', 'from' => 'tested-state-from', 'on' => 'tested-transition');
$this->beConstructedWith($specs, $this->callable);
$event->getConfig()->willReturn($this->getConfig(array('tested-state-from'), 'tested-state-to'));
$event->getTransition()->willReturn('tested-transition');
$event->getState()->willReturn('tested-state-from');
$this->isSatisfiedBy($event)->shouldReturn(true);
}
function it_doesnt_satisfies_wrong_from(TransitionEvent $event)
{
$specs = array('to' => 'tested-state-to', 'from' => 'tested-wrong', 'on' => 'tested-transition');
$this->beConstructedWith($specs, $this->callable);
$event->getConfig()->willReturn($this->getConfig(array('dummy'), 'tested-state-to'));
$event->getTransition()->willReturn('tested-transition');
$event->getState()->willReturn('dummy');
$this->isSatisfiedBy($event)->shouldReturn(false);
}
function it_doesnt_satisfies_wrong_to(TransitionEvent $event)
{
$specs = array('to' => 'tested-wrong', 'from' => 'tested-state-from', 'on' => 'tested-transition');
$this->beConstructedWith($specs, $this->callable);
$event->getConfig()->willReturn($this->getConfig(array('tested-state-from'), 'dummy'));
$event->getTransition()->willReturn('tested-transition');
$event->getState()->willReturn('tested-state-from');
$this->isSatisfiedBy($event)->shouldReturn(false);
}
function it_doesnt_satisfies_wrong_on(TransitionEvent $event)
{
$specs = array('to' => 'tested-state-to', 'from' => 'tested-state-from', 'on' => 'tested-wrong');
$this->beConstructedWith($specs, $this->callable);
$event->getConfig()->willReturn($this->getConfig(array('tested-state-from'), 'tested-state-to'));
$event->getTransition()->willReturn('dummy');
$event->getState()->willReturn('tested-state-from');
$this->isSatisfiedBy($event)->shouldReturn(false);
}
function it_doesnt_satisfies_excluded_from(TransitionEvent $event)
{
$specs = array('to' => 'tested-state-to', 'excluded_from' => 'tested-state-from');
$this->beConstructedWith($specs, $this->callable);
$event->getConfig()->willReturn($this->getConfig(array('tested-state-from'), 'tested-state-to'));
$event->getTransition()->willReturn('dummy');
$event->getState()->willReturn('tested-state-from');
$this->isSatisfiedBy($event)->shouldReturn(false);
}
protected function getConfig($from = array(), $to)
{
return array('from' => $from, 'to' => $to);
}
}

View File

@@ -0,0 +1,72 @@
<?php
namespace spec\SM\Callback;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use SM\Event\TransitionEvent;
use SM\Factory\FactoryInterface;
use SM\StateMachine\StateMachineInterface;
use spec\SM\DummyObject;
class CascadeTransitionCallbackSpec extends ObjectBehavior
{
function let(FactoryInterface $factory)
{
$this->beConstructedWith($factory);
}
function it_is_initializable()
{
$this->shouldHaveType('SM\Callback\CascadeTransitionCallback');
}
function it_applies($factory, TransitionEvent $event, DummyObject $object, StateMachineInterface $sm)
{
$factory->get($object, 'graph')->willReturn($sm);
$sm->can('transition')->willReturn(true);
$sm->apply('transition', true)->shouldBeCalled();
$this->apply($object, $event, 'transition', 'graph');
}
function it_applies_with_default_graph(
$factory,
TransitionEvent $event,
DummyObject $object,
StateMachineInterface $sm1,
StateMachineInterface $sm2
) {
$event->getStateMachine()->willReturn($sm2);
$sm2->getGraph()->willReturn('graph');
$factory->get($object, 'graph')->willReturn($sm1);
$sm1->can('transition')->willReturn(true);
$sm1->apply('transition', true)->shouldBeCalled();
$this->apply($object, $event, 'transition');
}
function it_applies_with_default_graph_and_default_transition(
$factory,
TransitionEvent $event,
DummyObject $object,
StateMachineInterface $sm1,
StateMachineInterface $sm2
) {
$event->getStateMachine()->willReturn($sm2);
$event->getTransition()->willReturn('transition');
$sm2->getGraph()->willReturn('graph');
$factory->get($object, 'graph')->willReturn($sm1);
$sm1->can('transition')->willReturn(true);
$sm1->apply('transition', true)->shouldBeCalled();
$this->apply($object, $event);
}
}