forked from jpfuentes2/php-activerecord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfigTest.php
141 lines (119 loc) · 3.81 KB
/
ConfigTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php
use ActiveRecord\Config;
use ActiveRecord\ConfigException;
class TestLogger
{
private function log() {}
}
class TestDateTimeWithoutCreateFromFormat
{
public function format($format=null) {}
}
class TestDateTime
{
public function format($format=null) {}
public static function createFromFormat($format, $time) {}
}
class ConfigTest extends SnakeCase_PHPUnit_Framework_TestCase
{
public function set_up()
{
$this->config = new Config();
$this->connections = array('development' => 'mysql://blah/development', 'test' => 'mysql://blah/test');
$this->config->set_connections($this->connections);
}
/**
* @expectedException ActiveRecord\ConfigException
*/
public function test_set_connections_must_be_array()
{
$this->config->set_connections(null);
}
public function test_get_connections()
{
$this->assert_equals($this->connections,$this->config->get_connections());
}
public function test_get_connection()
{
$this->assert_equals($this->connections['development'],$this->config->get_connection('development'));
}
public function test_get_invalid_connection()
{
$this->assert_null($this->config->get_connection('whiskey tango foxtrot'));
}
public function test_get_default_connection_and_connection()
{
$this->config->set_default_connection('development');
$this->assert_equals('development',$this->config->get_default_connection());
$this->assert_equals($this->connections['development'],$this->config->get_default_connection_string());
}
public function test_get_default_connection_and_connection_string_defaults_to_development()
{
$this->assert_equals('development',$this->config->get_default_connection());
$this->assert_equals($this->connections['development'],$this->config->get_default_connection_string());
}
public function test_get_default_connection_string_when_connection_name_is_not_valid()
{
$this->config->set_default_connection('little mac');
$this->assert_null($this->config->get_default_connection_string());
}
public function test_default_connection_is_set_when_only_one_connection_is_present()
{
$this->config->set_connections(array('development' => $this->connections['development']));
$this->assert_equals('development',$this->config->get_default_connection());
}
public function test_set_connections_with_default()
{
$this->config->set_connections($this->connections,'test');
$this->assert_equals('test',$this->config->get_default_connection());
}
public function test_get_date_class_with_default()
{
$this->assert_equals('ActiveRecord\\DateTime', $this->config->get_date_class());
}
/**
* @expectedException ActiveRecord\ConfigException
*/
public function test_set_date_class_when_class_doesnt_exist()
{
$this->config->set_date_class('doesntexist');
}
/**
* @expectedException ActiveRecord\ConfigException
*/
public function test_set_date_class_when_class_doesnt_have_format_or_createfromformat()
{
$this->config->set_date_class('TestLogger');
}
/**
* @expectedException ActiveRecord\ConfigException
*/
public function test_set_date_class_when_class_doesnt_have_createfromformat()
{
$this->config->set_date_class('TestDateTimeWithoutCreateFromFormat');
}
public function test_set_date_class_with_valid_class()
{
$this->config->set_date_class('TestDateTime');
$this->assert_equals('TestDateTime', $this->config->get_date_class());
}
public function test_initialize_closure()
{
$test = $this;
Config::initialize(function($cfg) use ($test)
{
$test->assert_not_null($cfg);
$test->assert_equals('ActiveRecord\Config',get_class($cfg));
});
}
public function test_logger_object_must_implement_log_method()
{
try {
$this->config->set_logger(new TestLogger);
$this->fail();
} catch (ConfigException $e) {
$this->assert_equals($e->getMessage(), "Logger object must implement a public log method");
}
}
}
?>