/** * @param Field $field */ public function setField(Field $field) { $this->fields[$field->getName()] = $field; }
public function testContextModelsCallback() { $context = new Context(); $field = new Field('body'); $field->setCallback(function (FilterTestFieldWeirdGetter $model) { return $model->getWeirdBody(); }); $context->setField($field); $filter = new Parser(new Scanner("body contains midget"), $context); // Models with public attributes $this->assertTrue($filter->validate(new FilterTestFieldWeirdGetter("This object contains a midget in the body."))); $this->assertFalse($filter->validate(new FilterTestFieldWeirdGetter("This object contains a giant in the body."))); $filter = new Parser(new Scanner("body contains body"), $context); // Models with public attributes $this->assertTrue($filter->validate(new FilterTestFieldWeirdGetter("Cuz theze are my united states of whatever"))); }