public function testStringNormalization() { $collection = new Collection(); $collection->restrictTo(String::class, false)->addNormalizer(function (&$value) { // we add here a more restrictive normalizer than the default one if (is_string($value)) { $value = new String($value); } }); $collection[] = 'scalar string'; $collection[] = new String('another string'); $this->assertInstanceOf(String::class, $collection[0]); $this->assertEquals('scalar string', (string) $collection[0]); $this->assertEquals('another string', (string) $collection[1]); $this->expectsException(function () use($collection) { $collection[2] = 0x1; }, Exception::class, null, Exception::COLLECTION_FORBIDDEN_VALUE); }
/** * @param MessageStack $errors */ public static function setErrors(Collection $errors) { // check errors content $errors->restrictTo(MessageStack::class); self::$errors = $errors; }