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 |
||
12 | View Code Duplication | class SendNotificationsCommandTest extends \PHPUnit_Framework_TestCase |
|
13 | { |
||
14 | public function testHelpInfo() |
||
15 | { |
||
16 | $command = $this->getCommand(); |
||
17 | $display = $command->getHelp(); |
||
18 | $this->assertContains("Depending on you Swiftmailer-Configuration the email will be send directly or will be written to the spool.", $display); |
||
19 | } |
||
20 | |||
21 | public function testSend() |
||
22 | { |
||
23 | $command = $this->getCommand(); |
||
24 | $tester = new CommandTester($command); |
||
25 | $tester->execute(array('')); |
||
26 | $display = $tester->getDisplay(); |
||
27 | $this->assertContains(AzineNotifierServiceMock::EMAIL_COUNT." emails have been processed.", $display); |
||
28 | } |
||
29 | |||
30 | public function testSendFail() |
||
31 | { |
||
32 | $command = $this->getCommand(true); |
||
33 | $tester = new CommandTester($command); |
||
34 | $tester->execute(array('')); |
||
35 | $display = $tester->getDisplay(); |
||
36 | $this->assertContains((AzineNotifierServiceMock::EMAIL_COUNT-1)." emails have been processed.", $display); |
||
37 | $this->assertContains(AzineNotifierServiceMock::FAILED_ADDRESS, $display); |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * @return SendNotificationsCommand |
||
42 | */ |
||
43 | private function getCommand($fail = false){ |
||
44 | $application = new Application(); |
||
45 | $application->add(new SendNotificationsCommand()); |
||
46 | $command = $application->find('emails:sendNotifications'); |
||
47 | $command->setContainer($this->getMockSetup($fail)); |
||
48 | return $command; |
||
49 | } |
||
50 | |||
51 | private function getMockSetup($fail = false) |
||
58 | |||
59 | public function testLockingFunctionality() |
||
60 | { |
||
61 | if(!class_exists('AppKernel')){ |
||
62 | $this->markTestSkipped("This test does only work if a full application is installed (including AppKernel class"); |
||
81 | } |
||
82 |