Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
| 1 | <?php |
||
| 16 | class CountCommandTest extends TestCase |
||
| 17 | { |
||
| 18 | use CommandTrait; |
||
| 19 | |||
| 20 | public function testCountCommand() |
||
| 21 | { |
||
| 22 | $container = new Container(); |
||
| 23 | $jobTimingManager = new JobTimingManager(JobTiming::class, false); |
||
| 24 | $runManager = new RunManager($jobTimingManager, Run::class); |
||
| 25 | $container->set('dtc_queue.manager.job', new StubJobManager($runManager, $jobTimingManager, Job::class)); |
||
| 26 | $this->runCommandException(CountCommand::class, $container, []); |
||
| 27 | } |
||
| 28 | |||
| 29 | public function testCountBeanstalkdCommand() |
||
| 30 | { |
||
| 31 | JobManagerTest::setUpBeforeClass(); |
||
| 32 | $jobManager = JobManagerTest::$jobManager; |
||
| 33 | $container = new Container(); |
||
| 34 | $container->set('dtc_queue.manager.job', $jobManager); |
||
| 35 | $this->runCommand(CountCommand::class, $container, []); |
||
| 36 | } |
||
| 37 | |||
| 38 | public function testCountMongodbCommand() |
||
| 39 | { |
||
| 40 | \Dtc\QueueBundle\Tests\ODM\JobManagerTest::setUpBeforeClass(); |
||
| 41 | $jobManager = \Dtc\QueueBundle\Tests\ODM\JobManagerTest::$jobManager; |
||
| 42 | $container = new Container(); |
||
| 43 | $container->set('dtc_queue.manager.job', $jobManager); |
||
| 44 | $this->runCommand(CountCommand::class, $container, []); |
||
| 45 | } |
||
| 46 | |||
| 47 | public function testCountORMCommand() |
||
| 48 | { |
||
| 49 | \Dtc\QueueBundle\Tests\ORM\JobManagerTest::setUpBeforeClass(); |
||
| 50 | $jobManager = \Dtc\QueueBundle\Tests\ORM\JobManagerTest::$jobManager; |
||
| 51 | $container = new Container(); |
||
| 52 | $container->set('dtc_queue.manager.job', $jobManager); |
||
| 53 | $this->runCommand(CountCommand::class, $container, []); |
||
| 54 | } |
||
| 55 | } |
||
| 56 |