LoaderLoadExceptionTest.php 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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\LoaderLoadException;
  13. class LoaderLoadExceptionTest extends TestCase
  14. {
  15. public function testMessageCannotLoadResource()
  16. {
  17. $exception = new LoaderLoadException('resource', null);
  18. $this->assertEquals('Cannot load resource "resource".', $exception->getMessage());
  19. }
  20. public function testMessageCannotLoadResourceWithType()
  21. {
  22. $exception = new LoaderLoadException('resource', null, null, null, 'foobar');
  23. $this->assertEquals('Cannot load resource "resource". Make sure there is a loader supporting the "foobar" type.', $exception->getMessage());
  24. }
  25. public function testMessageCannotLoadResourceWithAnnotationType()
  26. {
  27. $exception = new LoaderLoadException('resource', null, null, null, 'annotation');
  28. $this->assertEquals('Cannot load resource "resource". Make sure annotations are installed and enabled.', $exception->getMessage());
  29. }
  30. public function testMessageCannotImportResourceFromSource()
  31. {
  32. $exception = new LoaderLoadException('resource', 'sourceResource');
  33. $this->assertEquals('Cannot import resource "resource" from "sourceResource".', $exception->getMessage());
  34. }
  35. public function testMessageCannotImportBundleResource()
  36. {
  37. $exception = new LoaderLoadException('@resource', 'sourceResource');
  38. $this->assertEquals(
  39. 'Cannot import resource "@resource" from "sourceResource". '.
  40. 'Make sure the "resource" bundle is correctly registered and loaded in the application kernel class. '.
  41. 'If the bundle is registered, make sure the bundle path "@resource" is not empty.',
  42. $exception->getMessage()
  43. );
  44. }
  45. public function testMessageHasPreviousErrorWithDotAndUnableToLoad()
  46. {
  47. $exception = new LoaderLoadException(
  48. 'resource',
  49. null,
  50. null,
  51. new \Exception('There was a previous error with an ending dot.')
  52. );
  53. $this->assertEquals(
  54. 'There was a previous error with an ending dot in resource (which is loaded in resource "resource").',
  55. $exception->getMessage()
  56. );
  57. }
  58. public function testMessageHasPreviousErrorWithoutDotAndUnableToLoad()
  59. {
  60. $exception = new LoaderLoadException(
  61. 'resource',
  62. null,
  63. null,
  64. new \Exception('There was a previous error with no ending dot')
  65. );
  66. $this->assertEquals(
  67. 'There was a previous error with no ending dot in resource (which is loaded in resource "resource").',
  68. $exception->getMessage()
  69. );
  70. }
  71. public function testMessageHasPreviousErrorAndUnableToLoadBundle()
  72. {
  73. $exception = new LoaderLoadException(
  74. '@resource',
  75. null,
  76. null,
  77. new \Exception('There was a previous error with an ending dot.')
  78. );
  79. $this->assertEquals(
  80. 'There was a previous error with an ending dot in @resource '.
  81. '(which is loaded in resource "@resource"). '.
  82. 'Make sure the "resource" bundle is correctly registered and loaded in the application kernel class. '.
  83. 'If the bundle is registered, make sure the bundle path "@resource" is not empty.',
  84. $exception->getMessage()
  85. );
  86. }
  87. }