function it_connects_a_transition_to_a_place(FactoryInterface $factory, OutputArcInterface $arc, TransitionInterface $transition, PlaceInterface $place) { $factory->createPlace()->willReturn($place); $factory->createTransition()->willReturn($transition); $factory->createOutputArc()->willReturn($arc); $arc->setTransition($transition)->shouldBeCalled(); $arc->setPlace($place)->shouldBeCalled(); $arc->setWeight(1)->shouldBeCalled(); $transition->addOutputArc($arc)->shouldBeCalled(); $place->addInputArc($arc)->shouldBeCalled(); $this->beConstructedWith($factory); $this->connect($transition, $place)->shouldReturn($this); }
/** * Connects a place to a transition or vice-versa by an arc of the specified weight. * * @param NodeInterface $source * @param NodeInterface $target * @param integer $weight * * @return $this * * @throws \InvalidArgumentException */ public function connect(NodeInterface $source, NodeInterface $target, $weight = 1) { if ($source instanceof PlaceInterface && $target instanceof TransitionInterface) { $arc = $this->factory->createInputArc(); $arc->setPlace($source); $arc->setTransition($target); } elseif ($source instanceof TransitionInterface && $target instanceof PlaceInterface) { $arc = $this->factory->createOutputArc(); $arc->setPlace($target); $arc->setTransition($source); } else { throw new \InvalidArgumentException('An arc must connect a place to a transition or vice-versa.'); } $arc->setWeight($weight); $source->addOutputArc($arc); $target->addInputArc($arc); return $this; }