FileLoaderLoadExceptionTest.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. <?php
  2. /*
  3. * This file is part of the Symfony package.
  4. *
  5. * (c) Fabien Potencier <fabien@symfony.com>
  6. *
  7. * For the full copyright and license information, please view the LICENSE
  8. * file that was distributed with this source code.
  9. */
  10. namespace Symfony\Component\Config\Tests\Exception;
  11. use PHPUnit\Framework\TestCase;
  12. use Symfony\Component\Config\Exception\FileLoaderLoadException;
  13. class FileLoaderLoadExceptionTest extends TestCase
  14. {
  15. public function testMessageCannotLoadResource()
  16. {
  17. $exception = new FileLoaderLoadException('resource', null);
  18. $this->assertEquals('Cannot load resource "resource".', $exception->getMessage());
  19. }
  20. public function testMessageCannotImportResourceFromSource()
  21. {
  22. $exception = new FileLoaderLoadException('resource', 'sourceResource');
  23. $this->assertEquals('Cannot import resource "resource" from "sourceResource".', $exception->getMessage());
  24. }
  25. public function testMessageCannotImportBundleResource()
  26. {
  27. $exception = new FileLoaderLoadException('@resource', 'sourceResource');
  28. $this->assertEquals(
  29. 'Cannot import resource "@resource" from "sourceResource". '.
  30. 'Make sure the "resource" bundle is correctly registered and loaded in the application kernel class. '.
  31. 'If the bundle is registered, make sure the bundle path "@resource" is not empty.',
  32. $exception->getMessage()
  33. );
  34. }
  35. public function testMessageHasPreviousErrorWithDotAndUnableToLoad()
  36. {
  37. $exception = new FileLoaderLoadException(
  38. 'resource',
  39. null,
  40. null,
  41. new \Exception('There was a previous error with an ending dot.')
  42. );
  43. $this->assertEquals(
  44. 'There was a previous error with an ending dot in resource (which is loaded in resource "resource").',
  45. $exception->getMessage()
  46. );
  47. }
  48. public function testMessageHasPreviousErrorWithoutDotAndUnableToLoad()
  49. {
  50. $exception = new FileLoaderLoadException(
  51. 'resource',
  52. null,
  53. null,
  54. new \Exception('There was a previous error with no ending dot')
  55. );
  56. $this->assertEquals(
  57. 'There was a previous error with no ending dot in resource (which is loaded in resource "resource").',
  58. $exception->getMessage()
  59. );
  60. }
  61. public function testMessageHasPreviousErrorAndUnableToLoadBundle()
  62. {
  63. $exception = new FileLoaderLoadException(
  64. '@resource',
  65. null,
  66. null,
  67. new \Exception('There was a previous error with an ending dot.')
  68. );
  69. $this->assertEquals(
  70. 'There was a previous error with an ending dot in @resource '.
  71. '(which is loaded in resource "@resource"). '.
  72. 'Make sure the "resource" bundle is correctly registered and loaded in the application kernel class. '.
  73. 'If the bundle is registered, make sure the bundle path "@resource" is not empty.',
  74. $exception->getMessage()
  75. );
  76. }
  77. }