Files
Xes 73154ae174
Behat tests 1.11.x 🐞 / PHP 7.4 Test on ubuntu-latest (push) Canceled after 0s
PHP-CS-Fixer / composer_install (7.4) (push) Canceled after 0s
Chamilo 1.11.40 (ZIP oficial v1.11.40)
Fuente: https://github.com/chamilo/chamilo-lms/releases/download/v1.11.40/chamilo-1.11.40.zip
sha256: 1cf4bf2cc7bae1ef1a1eff643235db1d552f78ddf4b6dd1e2d2dac9868679439
Snapshot independiente (rama huerfana); diffable vs 1.11.38. vendor incluido.
2026-08-06 17:59:45 +02:00

164 lines
5.8 KiB
PHP

<?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);
}
}