/** * {@inheritdoc} */ public function analyse(OccurrencesInterface $occurences) { $storage = new \SplObjectStorage(); /** @var OccurrenceInterface $occurence */ foreach ($occurences->getFirstOccurrences() as $occurence) { $rule = $occurence->getRule(); $expectedCount = count($rule->getConditions()); $counter = 1; $current = $occurence; $previous = null; $this->dynamicCapabilitiesProcessor->process($current); while ($next = $occurences->getNext($current)) { $previous = $current; $current = $next; if ($this->incrementation->oughtToBeIncrement($current, $previous)) { $counter++; $this->dynamicCapabilitiesProcessor->process($current); } } if ($counter === $expectedCount && !$storage->contains($rule)) { $storage->attach($rule); } } return $storage; }
function it_return_negative_analyse_occurrences(IncrementationInterface $incrementation, DynamicCapabilitiesProcessorInterface $dynamicCapabilitiesProcessor, OccurrencesInterface $occurences, OccurrenceInterface $occurence1, OccurrenceInterface $occurence2, RuleInterface $rule) { $this->beConstructedWith($incrementation, $dynamicCapabilitiesProcessor); $rule->getConditions()->shouldBeCalled()->willReturn(array(1, 2, 3)); $occurence1->getRule()->shouldBeCalled()->willReturn($rule); $occurence2->getRule()->shouldBeCalled()->willReturn($rule); $dynamicCapabilitiesProcessor->process(Argument::exact($occurence1->getWrappedObject()))->shouldBeCalled(); $dynamicCapabilitiesProcessor->process(Argument::exact($occurence2->getWrappedObject()))->shouldBeCalled(); $occurencesIterator = array($occurence1, $occurence2); $occurences->getFirstOccurrences()->shouldBeCalled()->willReturn($occurencesIterator); $occurences->getNext(Argument::exact($occurence1->getWrappedObject()))->shouldBeCalled()->willReturn($occurence2); $occurences->getNext(Argument::exact($occurence2->getWrappedObject()))->shouldBeCalled()->willReturn(false); $incrementation->oughtToBeIncrement($occurence2->getWrappedObject(), $occurence1->getWrappedObject())->shouldBeCalled()->willReturn(true); $results = $this->analyse($occurences); $results->shouldBeAnInstanceOf('\\Iterator'); $results->shouldHaveCount(0); }