Conditions | 1 |
Paths | 1 |
Total Lines | 53 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
26 | public function testExecute() |
||
27 | { |
||
28 | $singleTask = $this->createTask('Test workload 1'); |
||
29 | $laterTask = $this->createTask('Test workload 2'); |
||
30 | $intervalTask = $this->createTask('Test workload 3', CronExpression::factory('@daily')); |
||
31 | |||
32 | /** @var TaskExecutionInterface[] $executions */ |
||
33 | $executions = [ |
||
34 | $this->createTaskExecution($singleTask, new \DateTime('-1 hour')), |
||
35 | $this->createTaskExecution($laterTask, new \DateTime('+1 hour')), |
||
36 | $this->createTaskExecution($intervalTask, new \DateTime('-2 hour')), |
||
37 | ]; |
||
38 | |||
39 | $this->commandTester->execute( |
||
40 | [ |
||
41 | 'command' => $this->command->getName(), |
||
42 | ] |
||
43 | ); |
||
44 | |||
45 | $execution = $this->taskExecutionRepository->findByUuid($executions[0]->getUuid()); |
||
46 | $this->assertEquals(TaskStatus::COMPLETED, $execution->getStatus()); |
||
47 | $this->assertEquals(strrev('Test workload 1'), $execution->getResult()); |
||
48 | $this->assertGreaterThan(0, $execution->getDuration()); |
||
49 | $this->assertGreaterThanOrEqual($execution->getStartTime(), $execution->getEndTime()); |
||
50 | |||
51 | $execution = $this->taskExecutionRepository->findByUuid($executions[1]->getUuid()); |
||
52 | $this->assertEquals(TaskStatus::PLANNED, $execution->getStatus()); |
||
53 | $this->assertNull($execution->getResult()); |
||
54 | $this->assertNull($execution->getDuration()); |
||
55 | $this->assertNull($execution->getStartTime()); |
||
56 | $this->assertNull($execution->getEndTime()); |
||
57 | |||
58 | $execution = $this->taskExecutionRepository->findByUuid($executions[2]->getUuid()); |
||
59 | $this->assertEquals(TaskStatus::COMPLETED, $execution->getStatus()); |
||
60 | $this->assertEquals(strrev('Test workload 3'), $execution->getResult()); |
||
61 | $this->assertGreaterThan(0, $execution->getDuration()); |
||
62 | $this->assertGreaterThanOrEqual($execution->getStartTime(), $execution->getEndTime()); |
||
63 | |||
64 | $result = $this->taskExecutionRepository->findAll(2, 3); |
||
65 | $this->assertCount(1, $result); |
||
66 | |||
67 | $task = $result[0]->getTask(); |
||
68 | $this->assertEquals($intervalTask->getUuid(), $task->getUuid()); |
||
69 | $this->assertEquals($intervalTask->getHandlerClass(), $task->getHandlerClass()); |
||
70 | $this->assertEquals($intervalTask->getWorkload(), $task->getWorkload()); |
||
71 | $this->assertLessThanOrEqual($intervalTask->getFirstExecution(), $task->getFirstExecution()); |
||
72 | $this->assertLessThanOrEqual($intervalTask->getLastExecution(), $task->getLastExecution()); |
||
73 | $this->assertEquals($intervalTask->getInterval(), $task->getInterval()); |
||
74 | |||
75 | $this->assertEquals(TaskStatus::PLANNED, $result[0]->getStatus()); |
||
76 | $this->assertEquals(TestHandler::class, $result[0]->getHandlerClass()); |
||
77 | $this->assertEquals('Test workload 3', $result[0]->getWorkload()); |
||
78 | } |
||
79 | |||
142 |