| Total Complexity | 44 |
| Total Lines | 344 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like TestOfDecorator 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.
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 TestOfDecorator, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 14 | class TestOfDecorator extends UnitTestCase |
||
| 15 | { |
||
| 16 | public $mockengine; |
||
| 17 | public $mockcal; |
||
| 18 | public $decorator; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * TestOfDecorator constructor. |
||
| 22 | */ |
||
| 23 | public function __construct() |
||
| 24 | { |
||
| 25 | parent::__construct('Test of Calendar_Decorator'); |
||
| 26 | } |
||
| 27 | |||
| 28 | protected function setUp() |
||
| 29 | { |
||
| 30 | $this->mockengine = new Mock_Calendar_Engine($this); |
||
| 31 | $this->mockcal = new Mock_Calendar_Second($this); |
||
| 32 | $this->mockcal->setReturnValue('prevYear', 2002); |
||
| 33 | $this->mockcal->setReturnValue('thisYear', 2003); |
||
| 34 | $this->mockcal->setReturnValue('nextYear', 2004); |
||
| 35 | $this->mockcal->setReturnValue('prevMonth', 9); |
||
| 36 | $this->mockcal->setReturnValue('thisMonth', 10); |
||
| 37 | $this->mockcal->setReturnValue('nextMonth', 11); |
||
| 38 | $this->mockcal->setReturnValue('prevDay', 14); |
||
| 39 | $this->mockcal->setReturnValue('thisDay', 15); |
||
| 40 | $this->mockcal->setReturnValue('nextDay', 16); |
||
| 41 | $this->mockcal->setReturnValue('prevHour', 12); |
||
| 42 | $this->mockcal->setReturnValue('thisHour', 13); |
||
| 43 | $this->mockcal->setReturnValue('nextHour', 14); |
||
| 44 | $this->mockcal->setReturnValue('prevMinute', 29); |
||
| 45 | $this->mockcal->setReturnValue('thisMinute', 30); |
||
| 46 | $this->mockcal->setReturnValue('nextMinute', 31); |
||
| 47 | $this->mockcal->setReturnValue('prevSecond', 44); |
||
| 48 | $this->mockcal->setReturnValue('thisSecond', 45); |
||
| 49 | $this->mockcal->setReturnValue('nextSecond', 46); |
||
| 50 | $this->mockcal->setReturnValue('getEngine', $this->mockengine); |
||
| 51 | $this->mockcal->setReturnValue('getTimestamp', 12345); |
||
| 52 | } |
||
| 53 | |||
| 54 | protected function tearDown() |
||
| 55 | { |
||
| 56 | unset($this->engine, $this->mockcal); |
||
| 57 | } |
||
| 58 | |||
| 59 | public function testPrevYear() |
||
| 60 | { |
||
| 61 | $this->mockcal->expectOnce('prevYear', ['int']); |
||
| 62 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 63 | $this->assertEqual(2002, $Decorator->prevYear()); |
||
| 64 | } |
||
| 65 | |||
| 66 | public function testThisYear() |
||
| 67 | { |
||
| 68 | $this->mockcal->expectOnce('thisYear', ['int']); |
||
| 69 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 70 | $this->assertEqual(2003, $Decorator->thisYear()); |
||
| 71 | } |
||
| 72 | |||
| 73 | public function testNextYear() |
||
| 74 | { |
||
| 75 | $this->mockcal->expectOnce('nextYear', ['int']); |
||
| 76 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 77 | $this->assertEqual(2004, $Decorator->nextYear()); |
||
| 78 | } |
||
| 79 | |||
| 80 | public function testPrevMonth() |
||
| 81 | { |
||
| 82 | $this->mockcal->expectOnce('prevMonth', ['int']); |
||
| 83 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 84 | $this->assertEqual(9, $Decorator->prevMonth()); |
||
| 85 | } |
||
| 86 | |||
| 87 | public function testThisMonth() |
||
| 88 | { |
||
| 89 | $this->mockcal->expectOnce('thisMonth', ['int']); |
||
| 90 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 91 | $this->assertEqual(10, $Decorator->thisMonth()); |
||
| 92 | } |
||
| 93 | |||
| 94 | public function testNextMonth() |
||
| 95 | { |
||
| 96 | $this->mockcal->expectOnce('nextMonth', ['int']); |
||
| 97 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 98 | $this->assertEqual(11, $Decorator->nextMonth()); |
||
| 99 | } |
||
| 100 | |||
| 101 | public function testPrevWeek() |
||
| 102 | { |
||
| 103 | $mockweek = new Mock_Calendar_Week($this); |
||
| 104 | $mockweek->setReturnValue('prevWeek', 1); |
||
| 105 | $mockweek->expectOnce('prevWeek', ['n_in_month']); |
||
| 106 | $Decorator = new Calendar_Decorator($mockweek); |
||
| 107 | $this->assertEqual(1, $Decorator->prevWeek()); |
||
| 108 | } |
||
| 109 | |||
| 110 | public function testThisWeek() |
||
| 111 | { |
||
| 112 | $mockweek = new Mock_Calendar_Week($this); |
||
| 113 | $mockweek->setReturnValue('thisWeek', 2); |
||
| 114 | $mockweek->expectOnce('thisWeek', ['n_in_month']); |
||
| 115 | $Decorator = new Calendar_Decorator($mockweek); |
||
| 116 | $this->assertEqual(2, $Decorator->thisWeek()); |
||
| 117 | } |
||
| 118 | |||
| 119 | public function testNextWeek() |
||
| 120 | { |
||
| 121 | $mockweek = new Mock_Calendar_Week($this); |
||
| 122 | $mockweek->setReturnValue('nextWeek', 3); |
||
| 123 | $mockweek->expectOnce('nextWeek', ['n_in_month']); |
||
| 124 | $Decorator = new Calendar_Decorator($mockweek); |
||
| 125 | $this->assertEqual(3, $Decorator->nextWeek()); |
||
| 126 | } |
||
| 127 | |||
| 128 | public function testPrevDay() |
||
| 129 | { |
||
| 130 | $this->mockcal->expectOnce('prevDay', ['int']); |
||
| 131 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 132 | $this->assertEqual(14, $Decorator->prevDay()); |
||
| 133 | } |
||
| 134 | |||
| 135 | public function testThisDay() |
||
| 136 | { |
||
| 137 | $this->mockcal->expectOnce('thisDay', ['int']); |
||
| 138 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 139 | $this->assertEqual(15, $Decorator->thisDay()); |
||
| 140 | } |
||
| 141 | |||
| 142 | public function testNextDay() |
||
| 143 | { |
||
| 144 | $this->mockcal->expectOnce('nextDay', ['int']); |
||
| 145 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 146 | $this->assertEqual(16, $Decorator->nextDay()); |
||
| 147 | } |
||
| 148 | |||
| 149 | public function testPrevHour() |
||
| 150 | { |
||
| 151 | $this->mockcal->expectOnce('prevHour', ['int']); |
||
| 152 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 153 | $this->assertEqual(12, $Decorator->prevHour()); |
||
| 154 | } |
||
| 155 | |||
| 156 | public function testThisHour() |
||
| 157 | { |
||
| 158 | $this->mockcal->expectOnce('thisHour', ['int']); |
||
| 159 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 160 | $this->assertEqual(13, $Decorator->thisHour()); |
||
| 161 | } |
||
| 162 | |||
| 163 | public function testNextHour() |
||
| 164 | { |
||
| 165 | $this->mockcal->expectOnce('nextHour', ['int']); |
||
| 166 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 167 | $this->assertEqual(14, $Decorator->nextHour()); |
||
| 168 | } |
||
| 169 | |||
| 170 | public function testPrevMinute() |
||
| 171 | { |
||
| 172 | $this->mockcal->expectOnce('prevMinute', ['int']); |
||
| 173 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 174 | $this->assertEqual(29, $Decorator->prevMinute()); |
||
| 175 | } |
||
| 176 | |||
| 177 | public function testThisMinute() |
||
| 178 | { |
||
| 179 | $this->mockcal->expectOnce('thisMinute', ['int']); |
||
| 180 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 181 | $this->assertEqual(30, $Decorator->thisMinute()); |
||
| 182 | } |
||
| 183 | |||
| 184 | public function testNextMinute() |
||
| 185 | { |
||
| 186 | $this->mockcal->expectOnce('nextMinute', ['int']); |
||
| 187 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 188 | $this->assertEqual(31, $Decorator->nextMinute()); |
||
| 189 | } |
||
| 190 | |||
| 191 | public function testPrevSecond() |
||
| 192 | { |
||
| 193 | $this->mockcal->expectOnce('prevSecond', ['int']); |
||
| 194 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 195 | $this->assertEqual(44, $Decorator->prevSecond()); |
||
| 196 | } |
||
| 197 | |||
| 198 | public function testThisSecond() |
||
| 199 | { |
||
| 200 | $this->mockcal->expectOnce('thisSecond', ['int']); |
||
| 201 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 202 | $this->assertEqual(45, $Decorator->thisSecond()); |
||
| 203 | } |
||
| 204 | |||
| 205 | public function testNextSecond() |
||
| 206 | { |
||
| 207 | $this->mockcal->expectOnce('nextSecond', ['int']); |
||
| 208 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 209 | $this->assertEqual(46, $Decorator->nextSecond()); |
||
| 210 | } |
||
| 211 | |||
| 212 | public function testGetEngine() |
||
| 213 | { |
||
| 214 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 215 | $this->assertIsA($Decorator->getEngine(), 'Mock_Calendar_Engine'); |
||
| 216 | } |
||
| 217 | |||
| 218 | public function testSetTimestamp() |
||
| 219 | { |
||
| 220 | $this->mockcal->expectOnce('setTimestamp', ['12345']); |
||
| 221 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 222 | $Decorator->setTimestamp('12345'); |
||
| 223 | } |
||
| 224 | |||
| 225 | public function testGetTimestamp() |
||
| 226 | { |
||
| 227 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 228 | $this->assertEqual(12345, $Decorator->getTimestamp()); |
||
| 229 | } |
||
| 230 | |||
| 231 | public function testSetSelected() |
||
| 232 | { |
||
| 233 | $this->mockcal->expectOnce('setSelected', [true]); |
||
| 234 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 235 | $Decorator->setSelected(); |
||
| 236 | } |
||
| 237 | |||
| 238 | public function testIsSelected() |
||
| 239 | { |
||
| 240 | $this->mockcal->setReturnValue('isSelected', true); |
||
| 241 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 242 | $this->assertTrue($Decorator->isSelected()); |
||
| 243 | } |
||
| 244 | |||
| 245 | public function testAdjust() |
||
| 246 | { |
||
| 247 | $this->mockcal->expectOnce('adjust', []); |
||
| 248 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 249 | $Decorator->adjust(); |
||
| 250 | } |
||
| 251 | |||
| 252 | public function testToArray() |
||
| 253 | { |
||
| 254 | $this->mockcal->expectOnce('toArray', [12345]); |
||
| 255 | $testArray = ['foo' => 'bar']; |
||
| 256 | $this->mockcal->setReturnValue('toArray', $testArray); |
||
| 257 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 258 | $this->assertEqual($testArray, $Decorator->toArray(12345)); |
||
| 259 | } |
||
| 260 | |||
| 261 | public function testReturnValue() |
||
| 262 | { |
||
| 263 | $this->mockcal->expectOnce('returnValue', ['a', 'b', 'c', 'd']); |
||
| 264 | $this->mockcal->setReturnValue('returnValue', 'foo'); |
||
| 265 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 266 | $this->assertEqual('foo', $Decorator->returnValue('a', 'b', 'c', 'd')); |
||
| 267 | } |
||
| 268 | |||
| 269 | public function testSetFirst() |
||
| 270 | { |
||
| 271 | $mockday = new Mock_Calendar_Day($this); |
||
| 272 | $mockday->expectOnce('setFirst', [true]); |
||
| 273 | $Decorator = new Calendar_Decorator($mockday); |
||
| 274 | $Decorator->setFirst(); |
||
| 275 | } |
||
| 276 | |||
| 277 | public function testSetLast() |
||
| 278 | { |
||
| 279 | $mockday = new Mock_Calendar_Day($this); |
||
| 280 | $mockday->expectOnce('setLast', [true]); |
||
| 281 | $Decorator = new Calendar_Decorator($mockday); |
||
| 282 | $Decorator->setLast(); |
||
| 283 | } |
||
| 284 | |||
| 285 | public function testIsFirst() |
||
| 286 | { |
||
| 287 | $mockday = new Mock_Calendar_Day($this); |
||
| 288 | $mockday->setReturnValue('isFirst', true); |
||
| 289 | $Decorator = new Calendar_Decorator($mockday); |
||
| 290 | $this->assertTrue($Decorator->isFirst()); |
||
| 291 | } |
||
| 292 | |||
| 293 | public function testIsLast() |
||
| 294 | { |
||
| 295 | $mockday = new Mock_Calendar_Day($this); |
||
| 296 | $mockday->setReturnValue('isLast', true); |
||
| 297 | $Decorator = new Calendar_Decorator($mockday); |
||
| 298 | $this->assertTrue($Decorator->isLast()); |
||
| 299 | } |
||
| 300 | |||
| 301 | public function testSetEmpty() |
||
| 302 | { |
||
| 303 | $mockday = new Mock_Calendar_Day($this); |
||
| 304 | $mockday->expectOnce('setEmpty', [true]); |
||
| 305 | $Decorator = new Calendar_Decorator($mockday); |
||
| 306 | $Decorator->setEmpty(); |
||
| 307 | } |
||
| 308 | |||
| 309 | public function testIsEmpty() |
||
| 310 | { |
||
| 311 | $mockday = new Mock_Calendar_Day($this); |
||
| 312 | $mockday->setReturnValue('isEmpty', true); |
||
| 313 | $Decorator = new Calendar_Decorator($mockday); |
||
| 314 | $this->assertTrue($Decorator->isEmpty()); |
||
| 315 | } |
||
| 316 | |||
| 317 | public function testBuild() |
||
| 318 | { |
||
| 319 | $testArray = ['foo' => 'bar']; |
||
| 320 | $this->mockcal->expectOnce('build', [$testArray]); |
||
| 321 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 322 | $Decorator->build($testArray); |
||
| 323 | } |
||
| 324 | |||
| 325 | public function testFetch() |
||
| 326 | { |
||
| 327 | $this->mockcal->expectOnce('fetch', []); |
||
| 328 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 329 | $Decorator->fetch(); |
||
| 330 | } |
||
| 331 | |||
| 332 | public function testFetchAll() |
||
| 333 | { |
||
| 334 | $this->mockcal->expectOnce('fetchAll', []); |
||
| 335 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 336 | $Decorator->fetchAll(); |
||
| 337 | } |
||
| 338 | |||
| 339 | public function testSize() |
||
| 344 | } |
||
| 345 | |||
| 346 | public function testIsValid() |
||
| 347 | { |
||
| 348 | $this->mockcal->expectOnce('isValid', []); |
||
| 349 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 350 | $Decorator->isValid(); |
||
| 351 | } |
||
| 352 | |||
| 353 | public function testGetValidator() |
||
| 354 | { |
||
| 355 | $this->mockcal->expectOnce('getValidator', []); |
||
| 356 | $Decorator = new Calendar_Decorator($this->mockcal); |
||
| 357 | $Decorator->getValidator(); |
||
| 358 | } |
||
| 359 | } |
||
| 360 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths