Code Duplication    Length = 67-67 lines in 2 locations

Tests/Command/SendNewsLetterCommandTest.php 1 location

@@ 12-78 (lines=67) @@
9
/**
10
 * @author dominik
11
 */
12
class SendNewsLetterCommandTest 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." newsletter emails have been sent.", $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)." newsletter emails have been sent.", $display);
37
        $this->assertContains(AzineNotifierServiceMock::FAILED_ADDRESS, $display);
38
    }
39
40
    /**
41
     * @return SendNewsLetterCommand
42
     */
43
    private function getCommand($fail = false){
44
        $application = new Application();
45
        $application->add(new SendNewsLetterCommand());
46
        $command = $application->find('emails:sendNewsletter');
47
        $command->setContainer($this->getMockSetup($fail));
48
        return $command;
49
    }
50
51
    private function getMockSetup($fail = false)
52
    {
53
        $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock();
54
        $notifierServiceMock = new AzineNotifierServiceMock($fail);
55
        $containerMock->expects($this->any())->method('get')->with('azine_email_notifier_service')->will($this->returnValue($notifierServiceMock));
56
        return $containerMock;
57
    }
58
59
    public function testLockingFunctionality()
60
    {
61
        $commandName = $this->getCommand()->getName();
62
        $reflector = new \ReflectionClass(\AppKernel::class);
63
        $appDirectory = dirname($reflector->getFileName());
64
65
        // start commands in a separate processes
66
        $process1 = new Process("php $appDirectory/console $commandName --env=test");
67
        $process2 = new Process("php $appDirectory/console $commandName --env=test");
68
        $process1->start();
69
        $process2->start();
70
71
        // wait until both processes have terminated
72
        while(!$process1->isTerminated() || !$process2->isTerminated()){
73
            usleep(10);
74
        }
75
76
        $this->assertContains('The command is already running in another process.', $process2->getOutput().$process1->getOutput());
77
    }
78
}
79

Tests/Command/SendNotificationsCommandTest.php 1 location

@@ 12-78 (lines=67) @@
9
/**
10
 * @author dominik
11
 */
12
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)
52
    {
53
        $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock();
54
        $notifierServiceMock = new AzineNotifierServiceMock($fail);
55
        $containerMock->expects($this->any())->method('get')->with('azine_email_notifier_service')->will($this->returnValue($notifierServiceMock));
56
        return $containerMock;
57
    }
58
59
    public function testLockingFunctionality()
60
    {
61
        $commandName = $this->getCommand()->getName();
62
        $reflector = new \ReflectionClass(\AppKernel::class);
63
        $appDirectory = dirname($reflector->getFileName());
64
65
        // start commands in a separate processes
66
        $process1 = new Process("php $appDirectory/console $commandName --env=test");
67
        $process2 = new Process("php $appDirectory/console $commandName --env=test");
68
        $process1->start();
69
        $process2->start();
70
71
        // wait until both processes have terminated
72
        while(!$process1->isTerminated() || !$process2->isTerminated()){
73
            usleep(10);
74
        }
75
76
        $this->assertContains('The command is already running in another process.', $process2->getOutput().$process1->getOutput());
77
    }
78
}
79