Add test and small code fix
This commit is contained in:
parent
8ac5275751
commit
de43182e0d
@ -28,14 +28,14 @@ class FileLoaderLoadException extends \Exception
|
||||
{
|
||||
$message = '';
|
||||
if ($previous) {
|
||||
// include the previous exception, to help the user see what might be the underlying cause
|
||||
// Include the previous exception, to help the user see what might be the underlying cause
|
||||
|
||||
//Trim the trailing period of the previous message. We only want 1 period remove so no rtrim...
|
||||
// Trim the trailing period of the previous message. We only want 1 period remove so no rtrim...
|
||||
if ('.' === substr($previous->getMessage(), -1)) {
|
||||
$trimmedMessage = substr($previous->getMessage(), 0, -1);
|
||||
$message .= ' ' . sprintf('%s', $trimmedMessage) . ' in ';
|
||||
$message .= sprintf('%s', $trimmedMessage) . ' in ';
|
||||
} else {
|
||||
$message .= ' ' . sprintf('%s', $previous->getMessage()) . ' in ';
|
||||
$message .= sprintf('%s', $previous->getMessage()) . ' in ';
|
||||
}
|
||||
$message .= $resource . ' ';
|
||||
|
||||
|
@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Symfony\Component\Config\Tests\Exception;
|
||||
|
||||
use Symfony\Component\Config\Exception\FileLoaderLoadException;
|
||||
|
||||
class FileLoaderLoadExceptionTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public function testMessageCannotLoadResource()
|
||||
{
|
||||
$exception = new FileLoaderLoadException('resource', null);
|
||||
$this->assertEquals('Cannot load resource "resource".', $exception->getMessage());
|
||||
}
|
||||
|
||||
public function testMessageCannotImportResourceFromSource()
|
||||
{
|
||||
$exception = new FileLoaderLoadException('resource', 'sourceResource');
|
||||
$this->assertEquals('Cannot import resource "resource" from "sourceResource".', $exception->getMessage());
|
||||
}
|
||||
|
||||
public function testMessageCannotImportBundleResource()
|
||||
{
|
||||
$exception = new FileLoaderLoadException('@resource', 'sourceResource');
|
||||
$this->assertEquals(
|
||||
'Cannot import resource "@resource" from "sourceResource". ' .
|
||||
'Make sure the "resource" bundle is correctly registered and loaded in the application kernel class.',
|
||||
$exception->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
public function testMessageHasPreviousErrorWithDotAndUnableToLoad()
|
||||
{
|
||||
$exception = new FileLoaderLoadException(
|
||||
'resource',
|
||||
null,
|
||||
null,
|
||||
new \Exception('There was a previous error with an ending dot.')
|
||||
);
|
||||
$this->assertEquals(
|
||||
'There was a previous error with an ending dot in resource (which is loaded in resource "resource").',
|
||||
$exception->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
public function testMessageHasPreviousErrorWithoutDotAndUnableToLoad()
|
||||
{
|
||||
$exception = new FileLoaderLoadException(
|
||||
'resource',
|
||||
null,
|
||||
null,
|
||||
new \Exception('There was a previous error with no ending dot')
|
||||
);
|
||||
$this->assertEquals(
|
||||
'There was a previous error with no ending dot in resource (which is loaded in resource "resource").',
|
||||
$exception->getMessage()
|
||||
);
|
||||
}
|
||||
|
||||
public function testMessageHasPreviousErrorAndUnableToLoadBundle()
|
||||
{
|
||||
$exception = new FileLoaderLoadException(
|
||||
'@resource',
|
||||
null,
|
||||
null,
|
||||
new \Exception('There was a previous error with an ending dot.')
|
||||
);
|
||||
$this->assertEquals(
|
||||
'There was a previous error with an ending dot in @resource ' .
|
||||
'(which is loaded in resource "@resource"). ' .
|
||||
'Make sure the "resource" bundle is correctly registered and loaded in the application kernel class.',
|
||||
$exception->getMessage()
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user