| Conditions | 1 |
| Paths | 1 |
| Total Lines | 56 |
| Code Lines | 39 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 47 | public function testSingleMaxAdding2Processes() |
||
| 48 | { |
||
| 49 | $pool = new PriorityPool(); |
||
| 50 | $this->assertSame($pool, $pool->setMaxSimultaneous(1)); |
||
| 51 | |||
| 52 | $this->assertEquals(1, $pool->getMaxSimultaneous()); |
||
| 53 | |||
| 54 | $process1 = Mockery::mock(Process::class); |
||
| 55 | $process1->shouldReceive('stop'); |
||
| 56 | $process1->shouldReceive('isStarted')->andReturn(false, false, false, true); //add, add2, start, check |
||
| 57 | $process1->shouldReceive('isRunning')->andReturn(false); //add, add2, check |
||
| 58 | |||
| 59 | $pool->add($process1); |
||
|
|
|||
| 60 | |||
| 61 | $process2 = Mockery::mock(Process::class); |
||
| 62 | $process2->shouldReceive('stop'); |
||
| 63 | $process2->shouldReceive('isStarted')->andReturn(false, false, false, true); //add, add2, start, check |
||
| 64 | $process2->shouldReceive('isRunning')->andReturn(false); //add, add2, check |
||
| 65 | |||
| 66 | $pool->add($process2); |
||
| 67 | |||
| 68 | $process1->shouldReceive('start')->once(); |
||
| 69 | $pool->start(); |
||
| 70 | |||
| 71 | $this->assertCount(1, $pool->getRunning()); |
||
| 72 | $this->assertCount(1, $pool->getWaiting()); |
||
| 73 | |||
| 74 | $running = $pool->getRunning(); |
||
| 75 | $run = reset($running); |
||
| 76 | $this->assertInstanceOf(ProcessRun::class, $run); |
||
| 77 | $this->assertSame($process1, $run->getProcess(), 'first process added should be run first'); |
||
| 78 | |||
| 79 | $waiting = $pool->getWaiting(); |
||
| 80 | $run = reset($waiting); |
||
| 81 | $this->assertInstanceOf(ProcessRun::class, $run); |
||
| 82 | $this->assertSame($process2, $run->getProcess(), 'second process added should be waiting'); |
||
| 83 | |||
| 84 | $process1->shouldReceive('isSuccessful')->andReturn(true); |
||
| 85 | $process2->shouldReceive('start'); |
||
| 86 | |||
| 87 | $this->assertTrue($pool->poll()); // check running state |
||
| 88 | |||
| 89 | $this->assertCount(1, $pool->getRunning()); |
||
| 90 | $this->assertCount(0, $pool->getWaiting()); |
||
| 91 | |||
| 92 | $running = $pool->getRunning(); |
||
| 93 | $run = reset($running); |
||
| 94 | $this->assertInstanceOf(ProcessRun::class, $run); |
||
| 95 | $this->assertSame($process2, $run->getProcess(), 'second process added should now be running'); |
||
| 96 | |||
| 97 | $process2->shouldReceive('isSuccessful')->andReturn(true); |
||
| 98 | $process2->shouldReceive('isSuccessful')->andReturn(true); |
||
| 99 | $this->assertFalse($pool->poll()); |
||
| 100 | |||
| 101 | $this->assertCount(0, $pool->getRunning()); |
||
| 102 | $this->assertCount(0, $pool->getWaiting()); |
||
| 103 | } |
||
| 130 |