[Validator] Change default of ValidatorFactory::buildDefault to exclude annotations

This commit is contained in:
Igor Wiedler 2012-05-02 20:47:18 +02:00
parent c7a8678992
commit 4b0cdde2b1
2 changed files with 6 additions and 17 deletions

View File

@ -80,21 +80,6 @@ class ValidatorFactoryTest extends \PHPUnit_Framework_TestCase
$this->assertEquals(new Validator($metadataFactory, $validatorFactory), $validator);
}
public function testBuildDefaultFromAnnotations()
{
if (!class_exists('Doctrine\Common\Annotations\AnnotationReader')) {
$this->markTestSkipped('Annotations is required for this test');
}
$factory = ValidatorFactory::buildDefault();
$context = new ValidatorContext();
$context
->setClassMetadataFactory(new ClassMetadataFactory(new AnnotationLoader(new AnnotationReader())))
->setConstraintValidatorFactory(new ConstraintValidatorFactory());
$this->assertEquals(new ValidatorFactory($context), $factory);
}
public function testBuildDefaultFromAnnotationsWithCustomNamespaces()
{
if (!class_exists('Doctrine\Common\Annotations\AnnotationReader')) {
@ -178,7 +163,7 @@ class ValidatorFactoryTest extends \PHPUnit_Framework_TestCase
*/
public function testBuildDefaultThrowsExceptionIfNoLoaderIsFound()
{
ValidatorFactory::buildDefault(array(), false);
ValidatorFactory::buildDefault();
}
/**

View File

@ -98,7 +98,7 @@ class ValidatorFactory implements ValidatorContextInterface
* has neither the extension ".xml" nor
* ".yml" nor ".yaml"
*/
static public function buildDefault(array $mappingFiles = array(), $annotations = true, $staticMethod = null)
static public function buildDefault(array $mappingFiles = array(), $annotations = false, $staticMethod = null)
{
$xmlMappingFiles = array();
$yamlMappingFiles = array();
@ -126,6 +126,10 @@ class ValidatorFactory implements ValidatorContextInterface
}
if ($annotations) {
if (!class_exists('Doctrine\Common\Annotations\AnnotationReader')) {
throw new \RuntimeException('Requested a ValidatorFactory with an AnnotationLoader, but the AnnotationReader was not found. You should add Doctrine Common to your project.');
}
$loaders[] = new AnnotationLoader(new AnnotationReader());
}