Conditions | 1 |
Paths | 1 |
Total Lines | 154 |
Code Lines | 123 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
51 | public function testPrepValueForDB() |
||
52 | { |
||
53 | /* Float behaviour, asserting we have 0 */ |
||
54 | $float = DBFloat::create(); |
||
55 | $this->assertEquals(0, $float->prepValueForDB(0)); |
||
56 | $this->assertEquals(0, $float->prepValueForDB(null)); |
||
57 | $this->assertEquals(0, $float->prepValueForDB(false)); |
||
58 | $this->assertEquals(0, $float->prepValueForDB('')); |
||
59 | $this->assertEquals('0', $float->prepValueForDB('0')); |
||
60 | |||
61 | /* Double behaviour, asserting we have 0 */ |
||
62 | $double = DBDouble::create(); |
||
63 | $this->assertEquals(0, $double->prepValueForDB(0)); |
||
64 | $this->assertEquals(0, $double->prepValueForDB(null)); |
||
65 | $this->assertEquals(0, $double->prepValueForDB(false)); |
||
66 | $this->assertEquals(0, $double->prepValueForDB('')); |
||
67 | $this->assertEquals('0', $double->prepValueForDB('0')); |
||
68 | |||
69 | /* Integer behaviour, asserting we have 0 */ |
||
70 | $int = singleton('Int'); |
||
71 | $this->assertEquals(0, $int->prepValueForDB(0)); |
||
72 | $this->assertEquals(0, $int->prepValueForDB(null)); |
||
73 | $this->assertEquals(0, $int->prepValueForDB(false)); |
||
74 | $this->assertEquals(0, $int->prepValueForDB('')); |
||
75 | $this->assertEquals(0, $int->prepValueForDB('0')); |
||
76 | |||
77 | /* Integer behaviour, asserting we have 1 */ |
||
78 | $this->assertEquals(1, $int->prepValueForDB(true)); |
||
79 | $this->assertEquals(1, $int->prepValueForDB(1)); |
||
80 | $this->assertEquals(1, $int->prepValueForDB('1')); |
||
81 | |||
82 | /* Decimal behaviour, asserting we have 0 */ |
||
83 | $decimal = DBDecimal::create(); |
||
84 | $this->assertEquals(0, $decimal->prepValueForDB(0)); |
||
85 | $this->assertEquals(0.0, $decimal->prepValueForDB(0.0)); |
||
86 | $this->assertEquals(0, $decimal->prepValueForDB(null)); |
||
87 | $this->assertEquals(0, $decimal->prepValueForDB(false)); |
||
88 | $this->assertEquals(0, $decimal->prepValueForDB('')); |
||
89 | $this->assertEquals(0, $decimal->prepValueForDB('0')); |
||
90 | $this->assertEquals(0.0, $decimal->prepValueForDB('0.0')); |
||
91 | |||
92 | /* Decimal behaviour, asserting we have 1 */ |
||
93 | $this->assertEquals(1, $decimal->prepValueForDB(true)); |
||
94 | $this->assertEquals(1, $decimal->prepValueForDB(1)); |
||
95 | $this->assertEquals(1.1, $decimal->prepValueForDB(1.1)); |
||
96 | $this->assertEquals(1, $decimal->prepValueForDB('1')); |
||
97 | $this->assertEquals(1.1, $decimal->prepValueForDB('1.1')); |
||
98 | |||
99 | /* Boolean behaviour, asserting we have 0 */ |
||
100 | $boolean = DBBoolean::create(); |
||
101 | $this->assertEquals(false, $boolean->prepValueForDB(0)); |
||
102 | $this->assertEquals(false, $boolean->prepValueForDB(null)); |
||
103 | $this->assertEquals(false, $boolean->prepValueForDB(false)); |
||
104 | $this->assertEquals(false, $boolean->prepValueForDB('false')); |
||
105 | $this->assertEquals(false, $boolean->prepValueForDB('f')); |
||
106 | $this->assertEquals(false, $boolean->prepValueForDB('')); |
||
107 | $this->assertEquals(false, $boolean->prepValueForDB('0')); |
||
108 | |||
109 | /* Boolean behaviour, asserting we have 1 */ |
||
110 | $this->assertEquals(true, $boolean->prepValueForDB(true)); |
||
111 | $this->assertEquals(true, $boolean->prepValueForDB('true')); |
||
112 | $this->assertEquals(true, $boolean->prepValueForDB('t')); |
||
113 | $this->assertEquals(true, $boolean->prepValueForDB(1)); |
||
114 | $this->assertEquals(true, $boolean->prepValueForDB('1')); |
||
115 | |||
116 | // @todo - Revisit Varchar to evaluate correct behaviour of nullifyEmpty |
||
117 | |||
118 | /* Varchar behaviour: nullifyifEmpty defaults to true */ |
||
119 | $varchar = DBVarchar::create(); |
||
120 | $this->assertEquals(0, $varchar->prepValueForDB(0)); |
||
121 | $this->assertEquals(null, $varchar->prepValueForDB(null)); |
||
122 | $this->assertEquals(null, $varchar->prepValueForDB(false)); |
||
123 | $this->assertEquals(null, $varchar->prepValueForDB('')); |
||
124 | $this->assertEquals('0', $varchar->prepValueForDB('0')); |
||
125 | $this->assertEquals(1, $varchar->prepValueForDB(1)); |
||
126 | $this->assertEquals(true, $varchar->prepValueForDB(true)); |
||
127 | $this->assertEquals('1', $varchar->prepValueForDB('1')); |
||
128 | $this->assertEquals('00000', $varchar->prepValueForDB('00000')); |
||
129 | $this->assertEquals(0, $varchar->prepValueForDB(0000)); |
||
130 | $this->assertEquals('test', $varchar->prepValueForDB('test')); |
||
131 | $this->assertEquals(123, $varchar->prepValueForDB(123)); |
||
132 | |||
133 | /* AllowEmpty Varchar behaviour */ |
||
134 | $varcharField = DBVarchar::create("testfield", 50, array("nullifyEmpty"=>false)); |
||
135 | $this->assertSame('0', $varcharField->prepValueForDB(0)); |
||
136 | $this->assertSame(null, $varcharField->prepValueForDB(null)); |
||
137 | $this->assertSame('', $varcharField->prepValueForDB(false)); |
||
138 | $this->assertSame('', $varcharField->prepValueForDB('')); |
||
139 | $this->assertSame('0', $varcharField->prepValueForDB('0')); |
||
140 | $this->assertSame('1', $varcharField->prepValueForDB(1)); |
||
141 | $this->assertSame('1', $varcharField->prepValueForDB(true)); |
||
142 | $this->assertSame('1', $varcharField->prepValueForDB('1')); |
||
143 | $this->assertSame('00000', $varcharField->prepValueForDB('00000')); |
||
144 | $this->assertSame('0', $varcharField->prepValueForDB(0000)); |
||
145 | $this->assertSame('test', $varcharField->prepValueForDB('test')); |
||
146 | $this->assertSame('123', $varcharField->prepValueForDB(123)); |
||
147 | unset($varcharField); |
||
148 | |||
149 | /* Text behaviour */ |
||
150 | $text = DBText::create(); |
||
151 | $this->assertEquals('0', $text->prepValueForDB(0)); |
||
152 | $this->assertEquals(null, $text->prepValueForDB(null)); |
||
153 | $this->assertEquals(null, $text->prepValueForDB(false)); |
||
154 | $this->assertEquals(null, $text->prepValueForDB('')); |
||
155 | $this->assertEquals('0', $text->prepValueForDB('0')); |
||
156 | $this->assertEquals('1', $text->prepValueForDB(1)); |
||
157 | $this->assertEquals('1', $text->prepValueForDB(true)); |
||
158 | $this->assertEquals('1', $text->prepValueForDB('1')); |
||
159 | $this->assertEquals('00000', $text->prepValueForDB('00000')); |
||
160 | $this->assertEquals('0', $text->prepValueForDB(0000)); |
||
161 | $this->assertEquals('test', $text->prepValueForDB('test')); |
||
162 | $this->assertEquals('123', $text->prepValueForDB(123)); |
||
163 | |||
164 | /* AllowEmpty Text behaviour */ |
||
165 | $textField = DBText::create("testfield", array("nullifyEmpty"=>false)); |
||
166 | $this->assertSame('0', $textField->prepValueForDB(0)); |
||
167 | $this->assertSame(null, $textField->prepValueForDB(null)); |
||
168 | $this->assertSame('', $textField->prepValueForDB(false)); |
||
169 | $this->assertSame('', $textField->prepValueForDB('')); |
||
170 | $this->assertSame('0', $textField->prepValueForDB('0')); |
||
171 | $this->assertSame('1', $textField->prepValueForDB(1)); |
||
172 | $this->assertSame('1', $textField->prepValueForDB(true)); |
||
173 | $this->assertSame('1', $textField->prepValueForDB('1')); |
||
174 | $this->assertSame('00000', $textField->prepValueForDB('00000')); |
||
175 | $this->assertSame('0', $textField->prepValueForDB(0000)); |
||
176 | $this->assertSame('test', $textField->prepValueForDB('test')); |
||
177 | $this->assertSame('123', $textField->prepValueForDB(123)); |
||
178 | unset($textField); |
||
179 | |||
180 | /* Time behaviour */ |
||
181 | $time = DBTime::create(); |
||
182 | $time->setValue('12:01am'); |
||
183 | $this->assertEquals("00:01:00", $time->getValue()); |
||
184 | $time->setValue('12:59am'); |
||
185 | $this->assertEquals("00:59:00", $time->getValue()); |
||
186 | $time->setValue('11:59am'); |
||
187 | $this->assertEquals("11:59:00", $time->getValue()); |
||
188 | $time->setValue('12:00pm'); |
||
189 | $this->assertEquals("12:00:00", $time->getValue()); |
||
190 | $time->setValue('12:59am'); |
||
191 | $this->assertEquals("00:59:00", $time->getValue()); |
||
192 | $time->setValue('1:00pm'); |
||
193 | $this->assertEquals("13:00:00", $time->getValue()); |
||
194 | $time->setValue('11:59pm'); |
||
195 | $this->assertEquals("23:59:00", $time->getValue()); |
||
196 | $time->setValue('12:00am'); |
||
197 | $this->assertEquals("00:00:00", $time->getValue()); |
||
198 | $time->setValue('00:00:00'); |
||
199 | $this->assertEquals("00:00:00", $time->getValue()); |
||
200 | |||
201 | /* BigInt behaviour */ |
||
202 | $bigInt = DBBigInt::create(); |
||
203 | $bigInt->setValue(PHP_INT_MAX); |
||
204 | $this->assertEquals(PHP_INT_MAX, $bigInt->getValue()); |
||
205 | } |
||
326 |