$t->diag('implements Serializable'); class NotSerializable implements Serializable { public function serialize() { throw new Exception('Not serializable'); } public function unserialize($serialized) { throw new Exception('Not serializable'); } } function will_crash($a) { return serialize(new sfValidatorErrorSchema(new sfValidatorString())); } $a = new NotSerializable(); try { $serialized = will_crash($a); $t->pass('"sfValidatorErrorSchema" implements Serializable'); } catch (Exception $e) { $t->fail('"sfValidatorErrorSchema" implements Serializable'); } $e = new sfValidatorErrorSchema($v1); $e1 = unserialize($serialized); $t->is($e1->getMessage(), $e->getMessage(), '"sfValidatorErrorSchema" implements Serializable'); $t->is($e1->getCode(), $e->getCode(), '"sfValidatorErrorSchema" implements Serializable'); $t->is(get_class($e1->getValidator()), get_class($e->getValidator()), '"sfValidatorErrorSchema" implements Serializable'); $t->is($e1->getArguments(), $e->getArguments(), '"sfValidatorErrorSchema" implements Serializable'); $t->is($e1->getNamedErrors(), $e->getNamedErrors(), '"sfValidatorErrorSchema" implements Serializable'); $t->is($e1->getGlobalErrors(), $e->getGlobalErrors(), '"sfValidatorErrorSchema" implements Serializable');
// ->getGlobalErrors() $t->diag('->getGlobalErrors()'); $e = new sfValidatorErrorSchema($v1); $e->addError($e1); $e->addError($e2, 'e2'); $e->addError($e1, '2'); $t->is($e->getGlobalErrors(), array($e1), '->getGlobalErrors() returns all globals/non named errors'); // ->getNamedErrors() $t->diag('->getNamedErrors()'); $t->is($e->getNamedErrors(), array('e2' => $e2, '2' => $e1), '->getNamedErrors() returns all named errors'); // ->getValue() $t->diag('->getValue()'); $t->is($e->getValue(), null, '->getValue() always returns null'); // ->getArguments() $t->diag('->getArguments()'); $t->is($e->getArguments(), array(), '->getArguments() always returns an empty array'); $t->is($e->getArguments(true), array(), '->getArguments() always returns an empty array'); // ->getMessageFormat() $t->diag('->getMessageFormat()'); $t->is($e->getMessageFormat(), '', '->getMessageFormat() always returns an empty string'); // ->getMessage() $t->diag('->getMessage()'); $t->is($e->getMessage(), '"foo" is too long (1 characters max). e2 ["bar" is too short (5 characters min).] 2 ["foo" is too long (1 characters max).]', '->getMessage() returns the error message string'); // ->getCode() $t->diag('->getCode()'); $t->is($e->getCode(), 'max_length e2 [min_length] 2 [max_length]', '->getCode() returns the error code'); // implements Countable $t->diag('implements Countable'); $e = new sfValidatorErrorSchema($v1, array('e1' => $e1, 'e2' => $e2)); $t->is(count($e), 2, '"sfValidatorError" implements Countable'); // implements Iterator