/** * Tests that removing expressions by indices works. */ public function testDeletingExpressions() { // Create a rule with 2 conditions and 2 actions. $this->rule->addExpressionObject($this->trueConditionExpression->reveal()); $this->rule->addExpressionObject($this->falseConditionExpression->reveal()); $this->rule->addExpressionObject($this->testActionExpression->reveal()); $second_action = $this->prophesize(RulesAction::class); $second_action->getUuid()->willReturn('action_uuid2'); $this->rule->addExpressionObject($second_action->reveal()); // Delete the first action. $uuid = $this->testActionExpression->reveal()->getUuid(); $this->rule->deleteExpression($uuid); $this->assertEquals(2, count($this->rule->getConditions()->getIterator())); $this->assertEquals(1, count($this->rule->getActions()->getIterator())); // Delete the second condition. $uuid = $this->falseConditionExpression->reveal()->getUuid(); $this->rule->deleteExpression($uuid); $this->assertEquals(1, count($this->rule->getConditions()->getIterator())); $this->assertEquals(1, count($this->rule->getActions()->getIterator())); // Delete the remaining action. $uuid = $second_action->reveal()->getUuid(); $this->rule->deleteExpression($uuid); $this->assertEquals(1, count($this->rule->getConditions()->getIterator())); $this->assertEquals(0, count($this->rule->getActions()->getIterator())); // Delete the remaining condition, rule should be empty now. $uuid = $this->trueConditionExpression->reveal()->getUuid(); $this->rule->deleteExpression($uuid); $this->assertEquals(0, count($this->rule->getConditions()->getIterator())); $this->assertEquals(0, count($this->rule->getActions()->getIterator())); }