Complex classes like EuroTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use EuroTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 16 | class EuroTest extends TestCase { |
||
| 17 | |||
| 18 | /** |
||
| 19 | * @dataProvider unsignedIntegerProvider |
||
| 20 | */ |
||
| 21 | public function testGetCentsReturnsConstructorArgument( int $unsignedInteger ) { |
||
| 25 | |||
| 26 | public function unsignedIntegerProvider() { |
||
| 32 | |||
| 33 | public function testGivenZero_getEuroFloatReturnsZeroFloat() { |
||
| 38 | |||
| 39 | private function assertExactFloat( float $expected, $actual ) { |
||
| 43 | |||
| 44 | public function testGivenOneEuro_getEuroFloatReturnsOne() { |
||
| 48 | |||
| 49 | public function testGivenOneCent_getEuroFloatReturnsPointZeroOne() { |
||
| 53 | |||
| 54 | public function testGiven33cents_getEuroFloatReturnsPointThreeThree() { |
||
| 58 | |||
| 59 | public function testGivenNegativeAmount_constructorThrowsException() { |
||
| 63 | |||
| 64 | public function testGivenZero_getEuroStringReturnsZeroString() { |
||
| 68 | |||
| 69 | public function testGivenOneEuro_getEuroStringReturnsOnePointZeroZero() { |
||
| 73 | |||
| 74 | public function testGivenTwoEuros_getEuroStringReturnsTwoPointZeroZero() { |
||
| 78 | |||
| 79 | public function testGivenOneCent_getEuroStringReturnsZeroPointZeroOne() { |
||
| 83 | |||
| 84 | public function testGivenTenCents_getEuroStringReturnsZeroPointOneZero() { |
||
| 88 | |||
| 89 | public function testGiven1234Cents_getEuroStringReturns12euro34() { |
||
| 93 | |||
| 94 | public function testGiven1234Cents_stringCastingReturns12euro34() { |
||
| 98 | |||
| 99 | public function testOneEuroString_getsTurnedInto100cents() { |
||
| 102 | |||
| 103 | public function testOneCentString_getsTurnedInto1cents() { |
||
| 106 | |||
| 107 | public function testTenCentString_getsTurnedInto10cents() { |
||
| 110 | |||
| 111 | public function testShortTenCentString_getsTurnedInto10cents() { |
||
| 114 | |||
| 115 | public function testShortOneEuroString_getsTurnedInto100cents() { |
||
| 118 | |||
| 119 | public function testOneDecimalOneEuroString_getsTurnedInto100cents() { |
||
| 122 | |||
| 123 | public function testMultiDecimalOneEuroString_getsTurnedInto100cents() { |
||
| 126 | |||
| 127 | public function testHandlingOfLargeEuroString() { |
||
| 130 | |||
| 131 | public function testEuroStringThatCausedRoundingError_doesNotCauseRoundingError() { |
||
| 136 | |||
| 137 | public function testEuroStringWithRoundingError_getsRoundedAppropriately() { |
||
| 153 | |||
| 154 | public function testGivenNegativeAmountString_exceptionIsThrown() { |
||
| 158 | |||
| 159 | public function testGivenStringWithComma_exceptionIsThrown() { |
||
| 163 | |||
| 164 | public function testGivenStringWithMultipleDots_ExceptionIsThrown() { |
||
| 168 | |||
| 169 | public function testGivenNonNumber_exceptionIsThrown() { |
||
| 173 | |||
| 174 | public function testGivenNegativeFloatAmount_exceptionIsThrown() { |
||
| 178 | |||
| 179 | public function testOneEuroFloat_getsTurnedInto100cents() { |
||
| 182 | |||
| 183 | public function testOneCentFloat_getsTurnedInto1cent() { |
||
| 186 | |||
| 187 | public function testTenCentFloat_getsTurnedInto10cents() { |
||
| 190 | |||
| 191 | public function testHandlingOfLargeEuroFloat() { |
||
| 194 | |||
| 195 | public function testFloatWithRoundingError_getsRoundedAppropriately() { |
||
| 206 | |||
| 207 | public function testZeroEuroIntegers_isZeroCents() { |
||
| 210 | |||
| 211 | public function testOneEuroIntegers_is100cents() { |
||
| 214 | |||
| 215 | public function test1337EuroIntegers_is133700cents() { |
||
| 218 | |||
| 219 | public function testGivenNegativeIntegerAmount_exceptionIsThrown() { |
||
| 223 | |||
| 224 | /** |
||
| 225 | * @dataProvider euroProvider |
||
| 226 | * @param Euro $euro |
||
| 227 | */ |
||
| 228 | public function testEuroEqualsItself( Euro $euro ) { |
||
| 231 | |||
| 232 | public function euroProvider() { |
||
| 241 | |||
| 242 | public function testOneCentDoesNotEqualOneEuro() { |
||
| 245 | |||
| 246 | public function testOneCentDoesNotEqualTwoCents() { |
||
| 249 | |||
| 250 | public function testOneCentDoesNotEqualOneEuroAndOneCent() { |
||
| 253 | |||
| 254 | public function test9001centsDoesNotEqual9000cents() { |
||
| 257 | |||
| 258 | } |
||
| 259 |