Skip to content

Commit 93e418f

Browse files
committed
Improve exception messages.
1 parent 1c5a213 commit 93e418f

File tree

7 files changed

+39
-5
lines changed

7 files changed

+39
-5
lines changed

src/Symfony/Component/DependencyInjection/Loader/YamlFileLoader.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ protected function loadFile($file)
290290
try {
291291
$configuration = $this->yamlParser->parse(file_get_contents($file));
292292
} catch (ParseException $e) {
293-
throw new \InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $file), 0, $e);
293+
throw new InvalidArgumentException(sprintf('The file "%s" does not contain valid YAML.', $file), 0, $e);
294294
}
295295

296296
return $this->validate($configuration, $file);
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
parameters:
2+
FOO: bar

src/Symfony/Component/DependencyInjection/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ public function provideInvalidFiles()
8787
array('bad_services'),
8888
array('bad_service'),
8989
array('bad_calls'),
90+
array('bad_format'),
9091
);
9192
}
9293

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
blog_show:
2+
path: /blog/{slug}
3+
defaults: { _controller: "MyBundle:Blog:show" }

src/Symfony/Component/Routing/Tests/Loader/YamlFileLoaderTest.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,15 @@ public function testLoadThrowsExceptionWithInvalidFile($filePath)
5151

5252
public function getPathsToInvalidFiles()
5353
{
54-
return array(array('nonvalid.yml'), array('nonvalid2.yml'), array('incomplete.yml'), array('nonvalidkeys.yml'), array('nonesense_resource_plus_path.yml'), array('nonesense_type_without_resource.yml'));
54+
return array(
55+
array('nonvalid.yml'),
56+
array('nonvalid2.yml'),
57+
array('incomplete.yml'),
58+
array('nonvalidkeys.yml'),
59+
array('nonesense_resource_plus_path.yml'),
60+
array('nonesense_type_without_resource.yml'),
61+
array('bad_format.yml'),
62+
);
5563
}
5664

5765
public function testLoadSpecialRouteName()

src/Symfony/Component/Validator/Tests/Mapping/Loader/YamlFileLoaderTest.php

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,26 @@ public function testLoadClassMetadataReturnsFalseIfEmpty()
3131
$this->assertFalse($loader->loadClassMetadata($metadata));
3232
}
3333

34-
public function testLoadClassMetadataThrowsExceptionIfNotAnArray()
34+
/**
35+
* @dataProvider provideInvalidYamlFiles
36+
* @expectedException \InvalidArgumentException
37+
*/
38+
public function testInvalidYamlFiles($path)
3539
{
36-
$loader = new YamlFileLoader(__DIR__.'/nonvalid-mapping.yml');
40+
$loader = new YamlFileLoader(__DIR__.'/'.$path);
3741
$metadata = new ClassMetadata('Symfony\Component\Validator\Tests\Fixtures\Entity');
3842

39-
$this->setExpectedException('\InvalidArgumentException');
4043
$loader->loadClassMetadata($metadata);
4144
}
4245

46+
public function provideInvalidYamlFiles()
47+
{
48+
return array(
49+
array('nonvalid-mapping.yml'),
50+
array('bad-format.yml'),
51+
);
52+
}
53+
4354
/**
4455
* @see https://github.com/symfony/symfony/pull/12158
4556
*/
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespaces:
2+
custom: Symfony\Component\Validator\Tests\Fixtures\
3+
4+
Symfony\Component\Validator\Tests\Fixtures\Entity:
5+
constraints:
6+
# Custom constraint
7+
- Symfony\Component\Validator\Tests\Fixtures\ConstraintA: ~
8+
# Custom constraint with namespaces prefix
9+
- "custom:ConstraintB": ~

0 commit comments

Comments
 (0)