ReaderTest.php 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. <?php
  2. /**
  3. * Tests the Config file reader that's shipped with kohana
  4. *
  5. * @group kohana
  6. * @group kohana.config
  7. *
  8. * @package Unittest
  9. * @author Kohana Team
  10. * @author Jeremy Bush <contractfrombelow@gmail.com>
  11. * @author Matt Button <matthew@sigswitch.com>
  12. * @copyright (c) Kohana Team
  13. * @license https://koseven.ga/LICENSE.md
  14. */
  15. class Kohana_Config_File_ReaderTest extends Kohana_Unittest_TestCase {
  16. /**
  17. * If we don't pass a directory to the reader then it should assume
  18. * that we want to search the dir 'config' by default
  19. *
  20. * @test
  21. * @covers Kohana_Config_File_Reader
  22. */
  23. public function test_default_search_dir_is_config()
  24. {
  25. $reader = new Kohana_Config_File_Reader;
  26. $this->assertAttributeSame('config', '_directory', $reader);
  27. }
  28. /**
  29. * If we pass a directory to the constructor of the file reader it
  30. * should change the search directory
  31. *
  32. * @test
  33. * @covers Kohana_Config_File_Reader
  34. */
  35. public function test_constructor_sets_search_dir_from_param()
  36. {
  37. $reader = new Kohana_Config_File_Reader('gafloog');
  38. $this->assertAttributeSame('gafloog', '_directory', $reader);
  39. }
  40. /**
  41. * If the config dir does not exist then the function should just
  42. * return an empty array
  43. *
  44. * @test
  45. * @covers Kohana_Config_File_Reader::load
  46. */
  47. public function test_load_returns_empty_array_if_conf_dir_dnx()
  48. {
  49. $config = new Kohana_Config_File_Reader('gafloogle');
  50. $this->assertSame([], $config->load('values'));
  51. }
  52. /**
  53. * If the requested config group does not exist then the reader
  54. * should return an empty array
  55. *
  56. * @test
  57. * @covers Kohana_Config_File_Reader::load
  58. */
  59. public function test_load_returns_empty_array_if_conf_dnx()
  60. {
  61. $config = new Kohana_Config_File_Reader;
  62. $this->assertSame([], $config->load('gafloogle'));
  63. }
  64. /**
  65. * Test that the load() function is actually loading the
  66. * configuration from the files.
  67. *
  68. * @test
  69. * @covers Kohana_Config_File_Reader::load
  70. */
  71. public function test_loads_config_from_files()
  72. {
  73. $config = new Kohana_Config_File_Reader;
  74. $values = $config->load('inflector');
  75. // Due to the way the cascading filesystem works there could be
  76. // any number of modifications to the system config in the
  77. // actual output. Therefore to increase compatability we just
  78. // check that we've got an array and that it's not empty
  79. $this->assertNotSame([], $values);
  80. $this->assertInternalType('array', $values);
  81. }
  82. }