public function testSeqErr() { $vfs = [function ($in) { throw new ValidationException('a'); }, function ($in) { throw new ValidationException('b'); }]; $_ = seq($vfs); try { $_('dummy'); } catch (ValidationException $e) { $this->assertEquals('a, b', $e->getMessage()); } $_ = seq_($vfs); try { $_('dummy'); } catch (ValidationException $e) { $this->assertEquals('a', $e->getMessage()); } }
/** * Combine a map of validation functions into a map validator * * Fields with no rules count as validation errors. * Throw exception immediately at the first problem. */ function map_S($callables) { return seq_([function ($data) use($callables) { $diff = array_diff(array_keys($data), array_keys($callables)); if (count($diff) > 0) { throw new IncompleteValidationException("the following fields lack validation rules: " . implode(',', $diff)); } return $data; }, map_($callables)]); }