/**
  * {@inheritdoc}
  */
 public function fire(TransitionInterface $transition, MarkingInterface $marking)
 {
     if (!$this->isEnabled($transition, $marking)) {
         throw new TransitionNotEnabledException('Cannot fire a disabled transition.');
     }
     $inputArcs = $transition->getInputArcs();
     $outputArcs = $transition->getOutputArcs();
     // Remove tokens from the input places
     foreach ($inputArcs as $arc) {
         $arcWeight = $arc->getWeight();
         $place = $arc->getPlace();
         $placeMarking = $marking->getPlaceMarking($place);
         $tokens = $placeMarking->getTokens();
         for ($i = 0; $i < $arcWeight; $i++) {
             $placeMarking->removeToken($tokens[$i]);
         }
     }
     // Add tokens to the output places
     foreach ($outputArcs as $arc) {
         $arcWeight = $arc->getWeight();
         $place = $arc->getPlace();
         $placeMarking = $marking->getPlaceMarking($place);
         if (null === $placeMarking) {
             $placeMarking = $this->factory->createPlaceMarking();
             $placeMarking->setPlace($place);
             $marking->addPlaceMarking($placeMarking);
         }
         // Create the tokens
         $tokens = array();
         for ($i = 0; $i < $arcWeight; $i++) {
             $tokens[] = $this->factory->createToken();
         }
         $placeMarking->setTokens($tokens);
     }
 }
 function it_builds_a_petrinet(FactoryInterface $factory, PetrinetInterface $petrinet, PlaceInterface $placeOne, PlaceInterface $placeTwo, TransitionInterface $transitionOne, TransitionInterface $transitionTwo)
 {
     $factory->createPetrinet()->willReturn($petrinet);
     $factory->createPlace()->willReturn($placeOne, $placeTwo);
     $factory->createTransition()->willReturn($transitionOne, $transitionTwo);
     $petrinet->setTransitions(array($transitionOne, $transitionTwo))->shouldBeCalled();
     $petrinet->setPlaces(array($placeOne, $placeTwo))->shouldBeCalled();
     $this->beConstructedWith($factory);
     $this->place();
     $this->place();
     $this->transition();
     $this->transition();
     $this->getPetrinet()->shouldReturn($petrinet);
 }
 /**
  * Gets the created Petrinet.
  *
  * @return \Petrinet\Model\PetrinetInterface
  */
 public function getPetrinet()
 {
     $petrinet = $this->factory->createPetrinet();
     $petrinet->setPlaces($this->places);
     $petrinet->setTransitions($this->transitions);
     return $petrinet;
 }
 function it_builds_a_marking_with_three_place_markings(FactoryInterface $factory, MarkingInterface $marking, PlaceMarkingInterface $placeMarkingOne, PlaceMarkingInterface $placeMarkingTwo, PlaceMarkingInterface $placeMarkingThree, PlaceInterface $placeOne, PlaceInterface $placeTwo, PlaceInterface $placeThree, TokenInterface $token)
 {
     $factory->createMarking()->willReturn($marking);
     $factory->createPlaceMarking()->willReturn($placeMarkingOne, $placeMarkingTwo, $placeMarkingThree);
     $factory->createToken()->willReturn($token)->shouldBeCalledTimes(3);
     $marking->setPlaceMarkings(array($placeMarkingOne, $placeMarkingTwo, $placeMarkingThree))->shouldBeCalled();
     $placeMarkingOne->setPlace($placeOne)->shouldBeCalled();
     $placeMarkingOne->setTokens(array($token))->shouldBeCalled();
     $placeMarkingTwo->setPlace($placeTwo)->shouldBeCalled();
     $placeMarkingTwo->setTokens(array($token, $token))->shouldBeCalled();
     $placeMarkingThree->setPlace($placeThree)->shouldBeCalled();
     $placeMarkingThree->setTokens(array($token, $token, $token))->shouldBeCalled();
     $this->beConstructedWith($factory);
     $this->mark($placeOne, $token);
     $this->mark($placeTwo, array($token, $token));
     $this->mark($placeThree, 3);
     $this->getMarking()->shouldReturn($marking);
 }
 /**
  * Gets the created marking.
  *
  * @return \Petrinet\Model\MarkingInterface
  */
 public function getMarking()
 {
     $marking = $this->factory->createMarking();
     $marking->setPlaceMarkings($this->placeMarkings);
     return $marking;
 }
 function it_creates_the_output_places_marking_if_not_existing_when_firing_a_transition(FactoryInterface $factory, PlaceMarkingInterface $placeOneMarking, PlaceMarkingInterface $placeTwoMarking, MarkingInterface $marking, PlaceInterface $placeOne, PlaceInterface $placeTwo, TransitionInterface $transition, InputArcInterface $arcOne, OutputArcInterface $arcTwo, TokenInterface $token)
 {
     $placeOne->getOutputArcs()->willReturn(array($arcOne));
     $arcOne->getPlace()->willReturn($placeOne);
     $arcOne->getTransition()->willReturn($transition);
     $arcOne->getWeight()->willReturn(1);
     $transition->getInputArcs()->willReturn(array($arcOne));
     $transition->getOutputArcs()->willReturn(array($arcTwo));
     $arcTwo->getTransition()->willReturn($transition);
     $arcTwo->getPlace()->willReturn($placeTwo);
     $arcTwo->getWeight()->willReturn(1);
     $factory->createToken()->willReturn($token)->shouldBeCalled();
     $factory->createPlaceMarking()->willReturn($placeTwoMarking)->shouldBeCalled();
     $placeOneMarking->getTokens()->willReturn(array($token));
     $marking->getPlaceMarking($placeOne->getWrappedObject())->willReturn($placeOneMarking);
     $marking->getPlaceMarking($placeTwo->getWrappedObject())->willReturn(null);
     $placeOneMarking->removeToken($token)->shouldBeCalled();
     $placeTwoMarking->setPlace($placeTwo)->shouldBeCalled();
     $placeTwoMarking->setTokens(array($token))->shouldBeCalled();
     $marking->addPlaceMarking($placeTwoMarking)->shouldBeCalled();
     $this->beConstructedWith($factory);
     $this->fire($transition, $marking);
 }