class YamlFileLoaderTest in Zircon Profile 8
Same name in this branch
- 8 vendor/symfony/routing/Tests/Loader/YamlFileLoaderTest.php \Symfony\Component\Routing\Tests\Loader\YamlFileLoaderTest
- 8 vendor/symfony/translation/Tests/Loader/YamlFileLoaderTest.php \Symfony\Component\Translation\Tests\Loader\YamlFileLoaderTest
- 8 vendor/symfony/dependency-injection/Tests/Loader/YamlFileLoaderTest.php \Symfony\Component\DependencyInjection\Tests\Loader\YamlFileLoaderTest
- 8 vendor/symfony/validator/Tests/Mapping/Loader/YamlFileLoaderTest.php \Symfony\Component\Validator\Tests\Mapping\Loader\YamlFileLoaderTest
- 8 vendor/symfony/serializer/Tests/Mapping/Loader/YamlFileLoaderTest.php \Symfony\Component\Serializer\Tests\Mapping\Loader\YamlFileLoaderTest
Same name and namespace in other branches
- 8.0 vendor/symfony/validator/Tests/Mapping/Loader/YamlFileLoaderTest.php \Symfony\Component\Validator\Tests\Mapping\Loader\YamlFileLoaderTest
Hierarchy
- class \Symfony\Component\Validator\Tests\Mapping\Loader\YamlFileLoaderTest extends \Symfony\Component\Validator\Tests\Mapping\Loader\PHPUnit_Framework_TestCase
Expanded class hierarchy of YamlFileLoaderTest
File
- vendor/
symfony/ validator/ Tests/ Mapping/ Loader/ YamlFileLoaderTest.php, line 26
Namespace
Symfony\Component\Validator\Tests\Mapping\LoaderView source
class YamlFileLoaderTest extends \PHPUnit_Framework_TestCase {
public function testLoadClassMetadataReturnsFalseIfEmpty() {
$loader = new YamlFileLoader(__DIR__ . '/empty-mapping.yml');
$metadata = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\Entity');
$this
->assertFalse($loader
->loadClassMetadata($metadata));
}
/**
* @dataProvider provideInvalidYamlFiles
* @expectedException \InvalidArgumentException
*/
public function testInvalidYamlFiles($path) {
$loader = new YamlFileLoader(__DIR__ . '/' . $path);
$metadata = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\Entity');
$loader
->loadClassMetadata($metadata);
}
public function provideInvalidYamlFiles() {
return array(
array(
'nonvalid-mapping.yml',
),
array(
'bad-format.yml',
),
);
}
/**
* @see https://github.com/symfony/symfony/pull/12158
*/
public function testDoNotModifyStateIfExceptionIsThrown() {
$loader = new YamlFileLoader(__DIR__ . '/nonvalid-mapping.yml');
$metadata = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\Entity');
try {
$loader
->loadClassMetadata($metadata);
} catch (\InvalidArgumentException $e) {
// Call again. Again an exception should be thrown
$this
->setExpectedException('\\InvalidArgumentException');
$loader
->loadClassMetadata($metadata);
}
}
public function testLoadClassMetadataReturnsTrueIfSuccessful() {
$loader = new YamlFileLoader(__DIR__ . '/constraint-mapping.yml');
$metadata = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\Entity');
$this
->assertTrue($loader
->loadClassMetadata($metadata));
}
public function testLoadClassMetadataReturnsFalseIfNotSuccessful() {
$loader = new YamlFileLoader(__DIR__ . '/constraint-mapping.yml');
$metadata = new ClassMetadata('\\stdClass');
$this
->assertFalse($loader
->loadClassMetadata($metadata));
}
public function testLoadClassMetadata() {
$loader = new YamlFileLoader(__DIR__ . '/constraint-mapping.yml');
$metadata = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\Entity');
$loader
->loadClassMetadata($metadata);
$expected = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\Entity');
$expected
->setGroupSequence(array(
'Foo',
'Entity',
));
$expected
->addConstraint(new ConstraintA());
$expected
->addConstraint(new ConstraintB());
$expected
->addConstraint(new Callback('validateMe'));
$expected
->addConstraint(new Callback('validateMeStatic'));
$expected
->addConstraint(new Callback(array(
'Symfony\\Component\\Validator\\Tests\\Fixtures\\CallbackClass',
'callback',
)));
$expected
->addPropertyConstraint('firstName', new NotNull());
$expected
->addPropertyConstraint('firstName', new Range(array(
'min' => 3,
)));
$expected
->addPropertyConstraint('firstName', new Choice(array(
'A',
'B',
)));
$expected
->addPropertyConstraint('firstName', new All(array(
new NotNull(),
new Range(array(
'min' => 3,
)),
)));
$expected
->addPropertyConstraint('firstName', new All(array(
'constraints' => array(
new NotNull(),
new Range(array(
'min' => 3,
)),
),
)));
$expected
->addPropertyConstraint('firstName', new Collection(array(
'fields' => array(
'foo' => array(
new NotNull(),
new Range(array(
'min' => 3,
)),
),
'bar' => array(
new Range(array(
'min' => 5,
)),
),
),
)));
$expected
->addPropertyConstraint('firstName', new Choice(array(
'message' => 'Must be one of %choices%',
'choices' => array(
'A',
'B',
),
)));
$expected
->addGetterConstraint('lastName', new NotNull());
$expected
->addGetterConstraint('valid', new IsTrue());
$expected
->addGetterConstraint('permissions', new IsTrue());
$this
->assertEquals($expected, $metadata);
}
public function testLoadGroupSequenceProvider() {
$loader = new YamlFileLoader(__DIR__ . '/constraint-mapping.yml');
$metadata = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\GroupSequenceProviderEntity');
$loader
->loadClassMetadata($metadata);
$expected = new ClassMetadata('Symfony\\Component\\Validator\\Tests\\Fixtures\\GroupSequenceProviderEntity');
$expected
->setGroupSequenceProvider(true);
$this
->assertEquals($expected, $metadata);
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
YamlFileLoaderTest:: |
public | function | ||
YamlFileLoaderTest:: |
public | function | ||
YamlFileLoaderTest:: |
public | function | @dataProvider provideInvalidYamlFiles @expectedException \InvalidArgumentException | |
YamlFileLoaderTest:: |
public | function | ||
YamlFileLoaderTest:: |
public | function | ||
YamlFileLoaderTest:: |
public | function | ||
YamlFileLoaderTest:: |
public | function | ||
YamlFileLoaderTest:: |
public | function |