| Conditions | 1 |
| Paths | 1 |
| Total Lines | 145 |
| 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 |
||
| 24 | public function testPrepValueForDB() { |
||
| 25 | $db = DB::get_conn(); |
||
| 26 | |||
| 27 | /* Float behaviour, asserting we have 0 */ |
||
| 28 | $this->assertEquals(0, singleton('Float')->prepValueForDB(0)); |
||
| 29 | $this->assertEquals(0, singleton('Float')->prepValueForDB(null)); |
||
| 30 | $this->assertEquals(0, singleton('Float')->prepValueForDB(false)); |
||
| 31 | $this->assertEquals(0, singleton('Float')->prepValueForDB('')); |
||
| 32 | $this->assertEquals('0', singleton('Float')->prepValueForDB('0')); |
||
| 33 | |||
| 34 | /* Double behaviour, asserting we have 0 */ |
||
| 35 | $this->assertEquals(0, singleton('Double')->prepValueForDB(0)); |
||
| 36 | $this->assertEquals(0, singleton('Double')->prepValueForDB(null)); |
||
| 37 | $this->assertEquals(0, singleton('Double')->prepValueForDB(false)); |
||
| 38 | $this->assertEquals(0, singleton('Double')->prepValueForDB('')); |
||
| 39 | $this->assertEquals('0', singleton('Double')->prepValueForDB('0')); |
||
| 40 | |||
| 41 | /* Integer behaviour, asserting we have 0 */ |
||
| 42 | $this->assertEquals(0, singleton('Int')->prepValueForDB(0)); |
||
| 43 | $this->assertEquals(0, singleton('Int')->prepValueForDB(null)); |
||
| 44 | $this->assertEquals(0, singleton('Int')->prepValueForDB(false)); |
||
| 45 | $this->assertEquals(0, singleton('Int')->prepValueForDB('')); |
||
| 46 | $this->assertEquals('0', singleton('Int')->prepValueForDB('0')); |
||
| 47 | |||
| 48 | /* Integer behaviour, asserting we have 1 */ |
||
| 49 | $this->assertEquals(1, singleton('Int')->prepValueForDB(true)); |
||
| 50 | $this->assertEquals(1, singleton('Int')->prepValueForDB(1)); |
||
| 51 | $this->assertEquals('1', singleton('Int')->prepValueForDB('1')); |
||
| 52 | |||
| 53 | /* Decimal behaviour, asserting we have 0 */ |
||
| 54 | $this->assertEquals(0, singleton('Decimal')->prepValueForDB(0)); |
||
| 55 | $this->assertEquals(0, singleton('Decimal')->prepValueForDB(null)); |
||
| 56 | $this->assertEquals(0, singleton('Decimal')->prepValueForDB(false)); |
||
| 57 | $this->assertEquals(0, singleton('Decimal')->prepValueForDB('')); |
||
| 58 | $this->assertEquals('0', singleton('Decimal')->prepValueForDB('0')); |
||
| 59 | |||
| 60 | /* Decimal behaviour, asserting we have 1 */ |
||
| 61 | $this->assertEquals(1, singleton('Decimal')->prepValueForDB(true)); |
||
| 62 | $this->assertEquals(1, singleton('Decimal')->prepValueForDB(1)); |
||
| 63 | $this->assertEquals('1', singleton('Decimal')->prepValueForDB('1')); |
||
| 64 | |||
| 65 | /* Boolean behaviour, asserting we have 0 */ |
||
| 66 | $this->assertEquals(false, singleton('Boolean')->prepValueForDB(0)); |
||
| 67 | $this->assertEquals(false, singleton('Boolean')->prepValueForDB(null)); |
||
| 68 | $this->assertEquals(false, singleton('Boolean')->prepValueForDB(false)); |
||
| 69 | $this->assertEquals(false, singleton('Boolean')->prepValueForDB('false')); |
||
| 70 | $this->assertEquals(false, singleton('Boolean')->prepValueForDB('f')); |
||
| 71 | $this->assertEquals(false, singleton('Boolean')->prepValueForDB('')); |
||
| 72 | $this->assertEquals(false, singleton('Boolean')->prepValueForDB('0')); |
||
| 73 | |||
| 74 | /* Boolean behaviour, asserting we have 1 */ |
||
| 75 | $this->assertEquals(true, singleton('Boolean')->prepValueForDB(true)); |
||
| 76 | $this->assertEquals(true, singleton('Boolean')->prepValueForDB('true')); |
||
| 77 | $this->assertEquals(true, singleton('Boolean')->prepValueForDB('t')); |
||
| 78 | $this->assertEquals(true, singleton('Boolean')->prepValueForDB(1)); |
||
| 79 | $this->assertEquals(true, singleton('Boolean')->prepValueForDB('1')); |
||
| 80 | |||
| 81 | // @todo - Revisit Varchar to evaluate correct behaviour of nullifyEmpty |
||
| 82 | |||
| 83 | /* Varchar behaviour */ |
||
| 84 | $this->assertEquals(0, singleton('Varchar')->prepValueForDB(0)); |
||
| 85 | $this->assertEquals(null, singleton('Varchar')->prepValueForDB(null)); |
||
| 86 | $this->assertEquals(null, singleton('Varchar')->prepValueForDB(false)); |
||
| 87 | $this->assertEquals(null, singleton('Varchar')->prepValueForDB('')); |
||
| 88 | $this->assertEquals('0', singleton('Varchar')->prepValueForDB('0')); |
||
| 89 | $this->assertEquals(1, singleton('Varchar')->prepValueForDB(1)); |
||
| 90 | $this->assertEquals(true, singleton('Varchar')->prepValueForDB(true)); |
||
| 91 | $this->assertEquals('1', singleton('Varchar')->prepValueForDB('1')); |
||
| 92 | $this->assertEquals('00000', singleton('Varchar')->prepValueForDB('00000')); |
||
| 93 | $this->assertEquals(0, singleton('Varchar')->prepValueForDB(0000)); |
||
| 94 | $this->assertEquals('test', singleton('Varchar')->prepValueForDB('test')); |
||
| 95 | $this->assertEquals(123, singleton('Varchar')->prepValueForDB(123)); |
||
| 96 | |||
| 97 | /* AllowEmpty Varchar behaviour */ |
||
| 98 | $varcharField = new Varchar("testfield", 50, array("nullifyEmpty"=>false)); |
||
| 99 | $this->assertSame(0, $varcharField->prepValueForDB(0)); |
||
| 100 | $this->assertSame(null, $varcharField->prepValueForDB(null)); |
||
| 101 | $this->assertSame(null, $varcharField->prepValueForDB(false)); |
||
| 102 | $this->assertSame('', $varcharField->prepValueForDB('')); |
||
| 103 | $this->assertSame('0', $varcharField->prepValueForDB('0')); |
||
| 104 | $this->assertSame(1, $varcharField->prepValueForDB(1)); |
||
| 105 | $this->assertSame(true, $varcharField->prepValueForDB(true)); |
||
| 106 | $this->assertSame('1', $varcharField->prepValueForDB('1')); |
||
| 107 | $this->assertSame('00000', $varcharField->prepValueForDB('00000')); |
||
| 108 | $this->assertSame(0, $varcharField->prepValueForDB(0000)); |
||
| 109 | $this->assertSame('test', $varcharField->prepValueForDB('test')); |
||
| 110 | $this->assertSame(123, $varcharField->prepValueForDB(123)); |
||
| 111 | unset($varcharField); |
||
| 112 | |||
| 113 | /* Text behaviour */ |
||
| 114 | $this->assertEquals(0, singleton('Text')->prepValueForDB(0)); |
||
| 115 | $this->assertEquals(null, singleton('Text')->prepValueForDB(null)); |
||
| 116 | $this->assertEquals(null, singleton('Text')->prepValueForDB(false)); |
||
| 117 | $this->assertEquals(null, singleton('Text')->prepValueForDB('')); |
||
| 118 | $this->assertEquals('0', singleton('Text')->prepValueForDB('0')); |
||
| 119 | $this->assertEquals(1, singleton('Text')->prepValueForDB(1)); |
||
| 120 | $this->assertEquals(true, singleton('Text')->prepValueForDB(true)); |
||
| 121 | $this->assertEquals('1', singleton('Text')->prepValueForDB('1')); |
||
| 122 | $this->assertEquals('00000', singleton('Text')->prepValueForDB('00000')); |
||
| 123 | $this->assertEquals(0, singleton('Text')->prepValueForDB(0000)); |
||
| 124 | $this->assertEquals('test', singleton('Text')->prepValueForDB('test')); |
||
| 125 | $this->assertEquals(123, singleton('Text')->prepValueForDB(123)); |
||
| 126 | |||
| 127 | /* AllowEmpty Text behaviour */ |
||
| 128 | $textField = new Text("testfield", array("nullifyEmpty"=>false)); |
||
| 129 | $this->assertSame(0, $textField->prepValueForDB(0)); |
||
| 130 | $this->assertSame(null, $textField->prepValueForDB(null)); |
||
| 131 | $this->assertSame(null, $textField->prepValueForDB(false)); |
||
| 132 | $this->assertSame('', $textField->prepValueForDB('')); |
||
| 133 | $this->assertSame('0', $textField->prepValueForDB('0')); |
||
| 134 | $this->assertSame(1, $textField->prepValueForDB(1)); |
||
| 135 | $this->assertSame(true, $textField->prepValueForDB(true)); |
||
| 136 | $this->assertSame('1', $textField->prepValueForDB('1')); |
||
| 137 | $this->assertSame('00000', $textField->prepValueForDB('00000')); |
||
| 138 | $this->assertSame(0, $textField->prepValueForDB(0000)); |
||
| 139 | $this->assertSame('test', $textField->prepValueForDB('test')); |
||
| 140 | $this->assertSame(123, $textField->prepValueForDB(123)); |
||
| 141 | unset($textField); |
||
| 142 | |||
| 143 | /* Time behaviour */ |
||
| 144 | $time = singleton('Time'); |
||
| 145 | $time->setValue('00:01am'); |
||
| 146 | $this->assertEquals("00:01:00", $time->getValue()); |
||
| 147 | $time->setValue('00:59am'); |
||
| 148 | $this->assertEquals("00:59:00", $time->getValue()); |
||
| 149 | $time->setValue('11:59am'); |
||
| 150 | $this->assertEquals("11:59:00", $time->getValue()); |
||
| 151 | $time->setValue('12:00pm'); |
||
| 152 | $this->assertEquals("12:00:00", $time->getValue()); |
||
| 153 | $time->setValue('12:59am'); |
||
| 154 | $this->assertEquals("12:59:00", $time->getValue()); |
||
| 155 | $time->setValue('1:00pm'); |
||
| 156 | $this->assertEquals("13:00:00", $time->getValue()); |
||
| 157 | $time->setValue('11:59pm'); |
||
| 158 | $this->assertEquals("23:59:00", $time->getValue()); |
||
| 159 | $time->setValue('00:00am'); |
||
| 160 | $this->assertEquals("00:00:00", $time->getValue()); |
||
| 161 | $time->setValue('00:00:00'); |
||
| 162 | $this->assertEquals("00:00:00", $time->getValue()); |
||
| 163 | |||
| 164 | /* BigInt behaviour */ |
||
| 165 | $bigInt = singleton('BigInt'); |
||
| 166 | $bigInt->setValue(PHP_INT_MAX); |
||
| 167 | $this->assertEquals(PHP_INT_MAX, $bigInt->getValue()); |
||
| 168 | } |
||
| 169 | |||
| 301 |