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