/** * {@inheritdoc} */ public function process(OccurrenceInterface $occurrence) { $condition = $occurrence->getCondition(); $node = $occurrence->getNode(); $rule = $occurrence->getRule(); $dynamicCapabilities = $condition->getDynamicCapabilities(); $matchesCapabilities = array(); foreach ($dynamicCapabilities as $capability) { $matchesCapabilities[$capability] = $node->getValue(); } $rule->setCapabilities(array_merge($rule->getCapabilities(), $matchesCapabilities)); }
function it_process_dynamic_capabilities(OccurrenceInterface $occurrence, ConditionInterface $condition, NodeInterface $node, RuleInterface $rule) { $occurrence->getCondition()->shouldBeCalled()->willReturn($condition); $occurrence->getNode()->shouldBeCalled()->willReturn($node); $occurrence->getRule()->shouldBeCalled()->willReturn($rule); $node->getValue()->shouldBeCalled()->willReturn('12.09b'); $dynamicCapabilities = array('browser_version'); $condition->getDynamicCapabilities()->shouldBeCalled()->willReturn($dynamicCapabilities); $capabilities = array('browser' => 'Chrome'); $rule->getCapabilities()->shouldBeCalled()->willReturn($capabilities); $rule->setCapabilities(Argument::exact(array('browser' => 'Chrome', 'browser_version' => '12.09b')))->shouldBeCalled()->willReturn($rule); $this->process($occurrence); }
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); }
function it_add_and_clear_occurrences(OccurrenceInterface $occurence, RuleInterface $rule) { $occurence->getRule()->shouldBeCalled()->willReturn($rule); $this->add($occurence)->shouldReturn($this); $this->clear()->shouldReturn($this); }