/** * {@inheritdoc} */ public function isEnabled(TransitionInterface $transition, MarkingInterface $marking) { $inputArcs = $transition->getInputArcs(); $outputArcs = $transition->getOutputArcs(); if (empty($inputArcs)) { return false; } foreach ($inputArcs as $inputArc) { $place = $inputArc->getPlace(); $placeMarking = $marking->getPlaceMarking($place); if (null === $placeMarking) { return false; } if (count($placeMarking->getTokens()) < $inputArc->getWeight()) { return false; } } foreach ($outputArcs as $outputArc) { $flag = true; if ($outputArc->assert() == false) { $flag &= false; } if ($flag) { return true; } } return $flag; }
function it_throws_an_exception_when_firing_a_disabled_transition(FactoryInterface $factory, MarkingInterface $marking, PlaceMarkingInterface $placeMarking, TransitionInterface $transition, PlaceInterface $place, InputArcInterface $arc) { $place->getOutputArcs()->willReturn(array($arc)); $transition->getInputArcs()->willReturn(array($arc)); $arc->getPlace()->willReturn($place); $arc->getTransition()->willReturn($transition); $arc->getWeight()->willReturn(1); $placeMarking->getTokens()->willReturn(array()); $marking->getPlaceMarking($place)->willReturn($placeMarking); $this->beConstructedWith($factory); $this->shouldThrow(new TransitionNotEnabledException('Cannot fire a disabled transition.'))->duringFire($transition, $marking); }