config.test.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. <?php
  2. class ConfigTest extends PHPUnit_Framework_TestCase {
  3. /**
  4. * Tear down the testing environment.
  5. */
  6. public function tearDown()
  7. {
  8. Config::$items = array();
  9. Config::$cache = array();
  10. }
  11. /**
  12. * Test the Config::get method.
  13. *
  14. * @group laravel
  15. */
  16. public function testItemsCanBeRetrievedFromConfigFiles()
  17. {
  18. $this->assertEquals('UTF-8', Config::get('application.encoding'));
  19. $this->assertEquals('mysql', Config::get('database.connections.mysql.driver'));
  20. $this->assertEquals('dashboard', Config::get('dashboard::meta.bundle'));
  21. }
  22. /**
  23. * Test the Config::has method.
  24. *
  25. * @group laravel
  26. */
  27. public function testHasMethodIndicatesIfConfigItemExists()
  28. {
  29. $this->assertFalse(Config::has('application.foo'));
  30. $this->assertTrue(Config::has('application.encoding'));
  31. }
  32. /**
  33. * Test the Config::set method.
  34. *
  35. * @group laravel
  36. */
  37. public function testConfigItemsCanBeSet()
  38. {
  39. Config::set('application.encoding', 'foo');
  40. Config::set('dashboard::meta.bundle', 'bar');
  41. $this->assertEquals('foo', Config::get('application.encoding'));
  42. $this->assertEquals('bar', Config::get('dashboard::meta.bundle'));
  43. }
  44. /**
  45. * Test that environment configurations are loaded correctly.
  46. *
  47. * @group laravel
  48. */
  49. public function testEnvironmentConfigsOverrideNormalConfigurations()
  50. {
  51. $_SERVER['LARAVEL_ENV'] = 'local';
  52. $this->assertEquals('sqlite', Config::get('database.default'));
  53. unset($_SERVER['LARAVEL_ENV']);
  54. }
  55. /**
  56. * Test that items can be set after the entire file has already been loaded.
  57. *
  58. * @group laravel
  59. */
  60. public function testItemsCanBeSetAfterEntireFileIsLoaded()
  61. {
  62. Config::get('application');
  63. Config::set('application.key', 'taylor');
  64. $application = Config::get('application');
  65. $this->assertEquals('taylor', $application['key']);
  66. }
  67. }