| Conditions | 1 |
| Paths | 1 |
| Total Lines | 53 |
| Code Lines | 38 |
| 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 |
||
| 80 | public function testExecuteWithFail() |
||
| 81 | { |
||
| 82 | $singleTask = $this->createTask('Test workload 1', null, FailTestHandler::class); |
||
| 83 | $laterTask = $this->createTask('Test workload 2', null, FailTestHandler::class); |
||
| 84 | $intervalTask = $this->createTask('Test workload 3', CronExpression::factory('@daily'), FailTestHandler::class); |
||
| 85 | |||
| 86 | /** @var TaskExecutionInterface[] $executions */ |
||
| 87 | $executions = [ |
||
| 88 | $this->createTaskExecution($singleTask, new \DateTime('-1 hour')), |
||
| 89 | $this->createTaskExecution($laterTask, new \DateTime('+1 hour')), |
||
| 90 | $this->createTaskExecution($intervalTask, new \DateTime('-2 hour')), |
||
| 91 | ]; |
||
| 92 | |||
| 93 | $this->commandTester->execute( |
||
| 94 | [ |
||
| 95 | 'command' => $this->command->getName(), |
||
| 96 | ] |
||
| 97 | ); |
||
| 98 | |||
| 99 | $execution = $this->taskExecutionRepository->findByUuid($executions[0]->getUuid()); |
||
| 100 | $this->assertEquals(TaskStatus::FAILED, $execution->getStatus()); |
||
| 101 | $this->assertNull($execution->getResult()); |
||
| 102 | $this->assertGreaterThan(0, $execution->getDuration()); |
||
| 103 | $this->assertGreaterThanOrEqual($execution->getStartTime(), $execution->getEndTime()); |
||
| 104 | |||
| 105 | $execution = $this->taskExecutionRepository->findByUuid($executions[1]->getUuid()); |
||
| 106 | $this->assertEquals(TaskStatus::PLANNED, $execution->getStatus()); |
||
| 107 | $this->assertNull($execution->getResult()); |
||
| 108 | $this->assertNull($execution->getDuration()); |
||
| 109 | $this->assertNull($execution->getStartTime()); |
||
| 110 | $this->assertNull($execution->getEndTime()); |
||
| 111 | |||
| 112 | $execution = $this->taskExecutionRepository->findByUuid($executions[2]->getUuid()); |
||
| 113 | $this->assertEquals(TaskStatus::FAILED, $execution->getStatus()); |
||
| 114 | $this->assertNull($execution->getResult()); |
||
| 115 | $this->assertGreaterThan(0, $execution->getDuration()); |
||
| 116 | $this->assertGreaterThanOrEqual($execution->getStartTime(), $execution->getEndTime()); |
||
| 117 | |||
| 118 | $result = $this->taskExecutionRepository->findAll(2, 3); |
||
| 119 | $this->assertCount(1, $result); |
||
| 120 | |||
| 121 | $task = $result[0]->getTask(); |
||
| 122 | $this->assertEquals($intervalTask->getUuid(), $task->getUuid()); |
||
| 123 | $this->assertEquals($intervalTask->getHandlerClass(), $task->getHandlerClass()); |
||
| 124 | $this->assertEquals($intervalTask->getWorkload(), $task->getWorkload()); |
||
| 125 | $this->assertLessThanOrEqual($intervalTask->getFirstExecution(), $task->getFirstExecution()); |
||
| 126 | $this->assertLessThanOrEqual($intervalTask->getLastExecution(), $task->getLastExecution()); |
||
| 127 | $this->assertEquals($intervalTask->getInterval(), $task->getInterval()); |
||
| 128 | |||
| 129 | $this->assertEquals(TaskStatus::PLANNED, $result[0]->getStatus()); |
||
| 130 | $this->assertEquals(FailTestHandler::class, $result[0]->getHandlerClass()); |
||
| 131 | $this->assertEquals('Test workload 3', $result[0]->getWorkload()); |
||
| 132 | } |
||
| 133 | |||
| 142 |