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(); }); }
/** * @dataProvider provideDataConsideredAsEmpty */ public function testEmptyDataError($emptyData) { $notBlankConstraint = new \Symfony\Component\Validator\Constraints\NotBlank(); $validator = new Validator(); $validator->setConstraints(['name' => [$notBlankConstraint]]); $mockInput = $this->getMock('AIV\\InputInterface'); $mockInput->expects($this->once())->method('getData')->will($this->returnCallback(function () use($emptyData) { return $emptyData; })); $validator->setInput($mockInput); $this->assertTrue($validator->hasErrors()); }