public function register(Application $app) { $this->app = $app; $app['aiv.namespaced'] = false; $app['validator'] = function () use($app) { return $app['aiv']; }; $app['aiv'] = $app->share(function (Application $app) { $manager = new Manager(); if ($app['aiv.namespaced']) { $manager->enableNamespace(); } $validators = $app['aiv.validators']; foreach ($validators as $name => $validatorConstraints) { $validator = new Validator(); $validator->setOptions(isset($validatorConstraints['options']) ? $validatorConstraints['options'] : []); $validator->setConstraintResolver($this); $validator->setConstraints($validatorConstraints['params']); $manager->addValidator($name, $validator); } $manager->setInput($app['aiv.input']); return $manager; }); $app['aiv.input'] = $app->share(function () { return new FormInput(); }); }
public function testAllowMissingParamsOption() { $notBlankConstraint = new \Symfony\Component\Validator\Constraints\NotBlank(); $expectedData = ['name' => 'John Smith']; $mockInput = $this->getMock('AIV\\InputInterface'); $mockInput->expects($this->any())->method('getData')->will($this->returnCallback(function () use($expectedData) { return $expectedData; })); $validator = new Validator(); $validator->setOptions(['allow.missing.params' => true]); $validator->setConstraints(['name' => [$notBlankConstraint], 'email' => [$notBlankConstraint]]); $validator->setInput($mockInput); $this->assertEquals($expectedData, $validator->getData()); }