PageRenderTime 44ms CodeModel.GetById 24ms RepoModel.GetById 1ms app.codeStats 0ms

/site/application/third_party/php-activerecord/test/ConfigTest.php

https://bitbucket.org/thiscode/thiscode-shop
PHP | 96 lines | 78 code | 15 blank | 3 comment | 0 complexity | f719acb5f976fc07df69f89369e44e76 MD5 | raw file
  1. <?php
  2. include 'helpers/config.php';
  3. use ActiveRecord\Config;
  4. use ActiveRecord\ConfigException;
  5. class TestLogger
  6. {
  7. private function log() {}
  8. }
  9. class ConfigTest extends SnakeCase_PHPUnit_Framework_TestCase
  10. {
  11. public function set_up()
  12. {
  13. $this->config = new Config();
  14. $this->connections = array('development' => 'mysql://blah/development', 'test' => 'mysql://blah/test');
  15. $this->config->set_connections($this->connections);
  16. }
  17. /**
  18. * @expectedException ActiveRecord\ConfigException
  19. */
  20. public function test_set_connections_must_be_array()
  21. {
  22. $this->config->set_connections(null);
  23. }
  24. public function test_get_connections()
  25. {
  26. $this->assert_equals($this->connections,$this->config->get_connections());
  27. }
  28. public function test_get_connection()
  29. {
  30. $this->assert_equals($this->connections['development'],$this->config->get_connection('development'));
  31. }
  32. public function test_get_invalid_connection()
  33. {
  34. $this->assert_null($this->config->get_connection('whiskey tango foxtrot'));
  35. }
  36. public function test_get_default_connection_and_connection()
  37. {
  38. $this->config->set_default_connection('development');
  39. $this->assert_equals('development',$this->config->get_default_connection());
  40. $this->assert_equals($this->connections['development'],$this->config->get_default_connection_string());
  41. }
  42. public function test_get_default_connection_and_connection_string_defaults_to_development()
  43. {
  44. $this->assert_equals('development',$this->config->get_default_connection());
  45. $this->assert_equals($this->connections['development'],$this->config->get_default_connection_string());
  46. }
  47. public function test_get_default_connection_string_when_connection_name_is_not_valid()
  48. {
  49. $this->config->set_default_connection('little mac');
  50. $this->assert_null($this->config->get_default_connection_string());
  51. }
  52. public function test_default_connection_is_set_when_only_one_connection_is_present()
  53. {
  54. $this->config->set_connections(array('development' => $this->connections['development']));
  55. $this->assert_equals('development',$this->config->get_default_connection());
  56. }
  57. public function test_set_connections_with_default()
  58. {
  59. $this->config->set_connections($this->connections,'test');
  60. $this->assert_equals('test',$this->config->get_default_connection());
  61. }
  62. public function test_initialize_closure()
  63. {
  64. $test = $this;
  65. Config::initialize(function($cfg) use ($test)
  66. {
  67. $test->assert_not_null($cfg);
  68. $test->assert_equals('ActiveRecord\Config',get_class($cfg));
  69. });
  70. }
  71. public function test_logger_object_must_implement_log_method()
  72. {
  73. try {
  74. $this->config->set_logger(new TestLogger);
  75. $this->fail();
  76. } catch (ConfigException $e) {
  77. $this->assert_equals($e->getMessage(), "Logger object must implement a public log method");
  78. }
  79. }
  80. }
  81. ?>