public function testSanitizers() { $field = new \Ongoo\Component\Form\Field('field1'); $this->array($field->getSanitizers())->isEmpty(); $this->if($field->addSanitizer(function ($value) { return "xx{$value}"; }))->then->array($field->getSanitizers())->hasSize(1)->then->if($field->addSanitizer(function ($value) { return "{$value}xx"; }))->then->array($field->getSanitizers())->hasSize(2); $this->if($sanitized = $field->sanitize('foo'))->then->string($sanitized)->isEqualTo('xxfooxx'); $this->if($field->setSanitizers(array()))->then->array($field->getSanitizers())->isEmpty(); $this->if($field->addSanitizer(function ($value) { return "xx{$value}"; }))->and($field->addSanitizer(new \Ongoo\Component\Form\Sanitizers\TrimSanitizer()))->and($field->addSanitizer(function ($value) { return "{$value}yy"; }))->then->array($field->getSanitizers())->hasSize(3)->string($field->sanitize('foo'))->isEqualTo('xxfooyy')->string($field->sanitize(' foo '))->isEqualTo('xx fooyy'); $this->if($field->setSanitizers(array()))->then->array($field->getSanitizers())->isEmpty(); $this->if($field->addSanitizer(new \Ongoo\Component\Form\Sanitizers\TrimSanitizer()))->and($field->addSanitizer(function ($value) { return "xx{$value}"; }))->and($field->addSanitizer(function ($value) { return "{$value}yy"; }))->then->array($field->getSanitizers())->hasSize(3)->string($field->sanitize('foo'))->isEqualTo('xxfooyy')->string($field->sanitize(' foo '))->isEqualTo('xxfooyy'); }