You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This PR was submitted for the master branch but it was merged into the 2.2 branch instead (closes#7433).
Commits
-------
9f84528 change wrapped exception message to be more usefull
Discussion
----------
change wrapped exception message to be more usefull
| Q | A
| ------------- | ---
| Bug fix? | yes
| New feature? | no
| BC breaks? | no
| Deprecations? | no
| Tests pass? | yes
| License | MIT
When you try to parse a yml file with the XMLLoader you get the following Exception
```
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
[ERROR 4] Start tag expected, '<' not found (in n/a - line 1, column 1)
[InvalidArgumentException]
[ERROR 4] Start tag expected, '<' not found (in n/a - line 1, column 1)
```
after the patch
```
[Symfony\Component\DependencyInjection\Exception\InvalidArgumentException]
Unable to parse file "/home/.../src/Application/FOS/UserBundle/DependencyInjection/../Resources/config/services.yml".
[InvalidArgumentException]
[ERROR 4] Start tag expected, '<' not found (in n/a - line 1, column 1)
```
Copy file name to clipboardExpand all lines: src/Symfony/Component/DependencyInjection/Tests/Loader/XmlFileLoaderTest.php
+37-13Lines changed: 37 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -50,7 +50,7 @@ public function testLoad()
50
50
$loader->load('foo.xml');
51
51
$this->fail('->load() throws an InvalidArgumentException if the loaded file does not exist');
52
52
} catch (\Exception$e) {
53
-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not exist');
53
+
$this->assertInstanceOf('InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the loaded file does not exist');
54
54
$this->assertStringStartsWith('The file "foo.xml" does not exist (in:', $e->getMessage(), '->load() throws an InvalidArgumentException if the loaded file does not exist');
55
55
}
56
56
}
@@ -66,7 +66,11 @@ public function testParseFile()
$this->fail('->parseFile() throws an InvalidArgumentException if the loaded file is not a valid XML file');
68
68
} catch (\Exception$e) {
69
-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->parseFile() throws an InvalidArgumentException if the loaded file is not a valid XML file');
69
+
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->parseFile() throws an InvalidArgumentException if the loaded file is not a valid XML file');
70
+
$this->assertRegExp(sprintf('#^Unable to parse file ".+%s".$#', 'parameters.ini'), $e->getMessage(), '->parseFile() throws an InvalidArgumentException if the loaded file is not a valid XML file');
71
+
72
+
$e = $e->getPrevious();
73
+
$this->assertInstanceOf('InvalidArgumentException', $e, '->parseFile() throws an InvalidArgumentException if the loaded file is not a valid XML file');
70
74
$this->assertStringStartsWith('[ERROR 4] Start tag expected, \'<\' not found (in', $e->getMessage(), '->parseFile() throws an InvalidArgumentException if the loaded file is not a valid XML file');
71
75
}
72
76
@@ -76,7 +80,11 @@ public function testParseFile()
$this->fail('->parseFile() throws an InvalidArgumentException if the loaded file does not validate the XSD');
78
82
} catch (\Exception$e) {
79
-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->parseFile() throws an InvalidArgumentException if the loaded file does not validate the XSD');
83
+
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->parseFile() throws an InvalidArgumentException if the loaded file does not validate the XSD');
84
+
$this->assertRegExp(sprintf('#^Unable to parse file ".+%s".$#', 'nonvalid.xml'), $e->getMessage(), '->parseFile() throws an InvalidArgumentException if the loaded file is not a valid XML file');
85
+
86
+
$e = $e->getPrevious();
87
+
$this->assertInstanceOf('InvalidArgumentException', $e, '->parseFile() throws an InvalidArgumentException if the loaded file does not validate the XSD');
80
88
$this->assertStringStartsWith('[ERROR 1845] Element \'nonvalid\': No matching global declaration available for the validation root. (in', $e->getMessage(), '->parseFile() throws an InvalidArgumentException if the loaded file does not validate the XSD');
81
89
}
82
90
@@ -262,8 +270,12 @@ public function testExtensions()
262
270
$loader->load('extensions/services3.xml');
263
271
$this->fail('->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
264
272
} catch (\Exception$e) {
265
-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
266
-
$this->assertRegexp('/The attribute \'bar\' is not allowed/', $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
273
+
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
274
+
$this->assertRegExp(sprintf('#^Unable to parse file ".+%s".$#', 'services3.xml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
275
+
276
+
$e = $e->getPrevious();
277
+
$this->assertInstanceOf('InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
278
+
$this->assertContains('The attribute \'bar\' is not allowed', $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
267
279
}
268
280
269
281
// non-registered extension
@@ -295,8 +307,12 @@ public function testExtensionInPhar()
295
307
$loader->load('extensions/services7.xml');
296
308
$this->fail('->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
297
309
} catch (\Exception$e) {
298
-
$this->assertInstanceOf('\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
299
-
$this->assertRegexp('/The attribute \'bar\' is not allowed/', $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
310
+
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
311
+
$this->assertRegExp(sprintf('#^Unable to parse file ".+%s".$#', 'services7.xml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
312
+
313
+
$e = $e->getPrevious();
314
+
$this->assertInstanceOf('InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
315
+
$this->assertContains('The attribute \'bar\' is not allowed', $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration does not validate the XSD');
300
316
}
301
317
}
302
318
@@ -333,15 +349,23 @@ public function testNoNamingConflictsForAnonymousServices()
333
349
$this->assertEquals('BarClass2', $inner2->getClass(), '->load() uses the same configuration as for the anonymous ones');
334
350
}
335
351
336
-
/**
337
-
* @expectedException \InvalidArgumentException
338
-
* @expectedExceptionMessage Document types are not allowed.
$this->fail('->load() throws an InvalidArgumentException if the configuration contains a document type');
362
+
} catch (\Exception$e) {
363
+
$this->assertInstanceOf('Symfony\\Component\\DependencyInjection\\Exception\\InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration contains a document type');
364
+
$this->assertRegExp(sprintf('#^Unable to parse file ".+%s".$#', 'withdoctype.xml'), $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration contains a document type');
365
+
366
+
$e = $e->getPrevious();
367
+
$this->assertInstanceOf('InvalidArgumentException', $e, '->load() throws an InvalidArgumentException if the configuration contains a document type');
368
+
$this->assertSame('Document types are not allowed.', $e->getMessage(), '->load() throws an InvalidArgumentException if the configuration contains a document type');
0 commit comments