azine /
email-bundle
| 1 | <?php |
||||
| 2 | |||||
| 3 | namespace Azine\EmailBundle\Tests\Command; |
||||
| 4 | |||||
| 5 | use Azine\EmailBundle\Command\SendNewsLetterCommand; |
||||
| 6 | use Symfony\Component\Console\Application; |
||||
| 7 | use Symfony\Component\Console\Tester\CommandTester; |
||||
| 8 | use Symfony\Component\Process\Process; |
||||
| 9 | |||||
| 10 | /** |
||||
| 11 | * @author dominik |
||||
| 12 | */ |
||||
| 13 | class SendNewsLetterCommandTest extends \PHPUnit\Framework\TestCase |
||||
| 14 | { |
||||
| 15 | public function testHelpInfo() |
||||
| 16 | { |
||||
| 17 | $command = $this->getCommand(); |
||||
| 18 | $display = $command->getHelp(); |
||||
| 19 | $this->assertContains('Depending on you Swiftmailer-Configuration the email will be send directly or will be written to the spool.', $display); |
||||
| 20 | } |
||||
| 21 | |||||
| 22 | public function testSend() |
||||
| 23 | { |
||||
| 24 | $command = $this->getCommand(); |
||||
| 25 | $tester = new CommandTester($command); |
||||
| 26 | $tester->execute(array('')); |
||||
| 27 | $display = $tester->getDisplay(); |
||||
| 28 | $this->assertContains(AzineNotifierServiceMock::EMAIL_COUNT.' newsletter emails have been sent.', $display); |
||||
| 29 | } |
||||
| 30 | |||||
| 31 | public function testSendFail() |
||||
| 32 | { |
||||
| 33 | $command = $this->getCommand(true); |
||||
| 34 | $tester = new CommandTester($command); |
||||
| 35 | $tester->execute(array('')); |
||||
| 36 | $display = $tester->getDisplay(); |
||||
| 37 | $this->assertContains((AzineNotifierServiceMock::EMAIL_COUNT - 1).' newsletter emails have been sent.', $display); |
||||
| 38 | $this->assertContains(AzineNotifierServiceMock::FAILED_ADDRESS, $display); |
||||
| 39 | } |
||||
| 40 | |||||
| 41 | /** |
||||
| 42 | * @return SendNewsLetterCommand |
||||
| 43 | */ |
||||
| 44 | private function getCommand($fail = false) |
||||
| 45 | { |
||||
| 46 | $application = new Application(); |
||||
| 47 | $application->add(new SendNewsLetterCommand()); |
||||
| 48 | $command = $application->find('emails:sendNewsletter'); |
||||
| 49 | $command->setContainer($this->getMockSetup($fail)); |
||||
|
0 ignored issues
–
show
Bug
introduced
by
Loading history...
|
|||||
| 50 | |||||
| 51 | return $command; |
||||
| 52 | } |
||||
| 53 | |||||
| 54 | private function getMockSetup($fail = false) |
||||
| 55 | { |
||||
| 56 | $containerMock = $this->getMockBuilder("Symfony\Component\DependencyInjection\ContainerInterface")->disableOriginalConstructor()->getMock(); |
||||
| 57 | $notifierServiceMock = new AzineNotifierServiceMock($fail); |
||||
| 58 | $containerMock->expects($this->any())->method('get')->with('azine_email_notifier_service')->will($this->returnValue($notifierServiceMock)); |
||||
| 59 | |||||
| 60 | return $containerMock; |
||||
| 61 | } |
||||
| 62 | |||||
| 63 | public function testLockingFunctionality() |
||||
| 64 | { |
||||
| 65 | if (!class_exists('AppKernel')) { |
||||
| 66 | $this->markTestSkipped('This test does only works if a full application is installed (including AppKernel class'); |
||||
| 67 | } |
||||
| 68 | $commandName = $this->getCommand()->getName(); |
||||
| 69 | $reflector = new \ReflectionClass(\AppKernel::class); |
||||
|
0 ignored issues
–
show
The type
AppKernel was not found. Maybe you did not declare it correctly or list all dependencies?
The issue could also be caused by a filter entry in the build configuration.
If the path has been excluded in your configuration, e.g. filter:
dependency_paths: ["lib/*"]
For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths Loading history...
|
|||||
| 70 | $appDirectory = dirname($reflector->getFileName()); |
||||
| 71 | |||||
| 72 | // start commands in a separate processes |
||||
| 73 | $process1 = new Process("php $appDirectory/../bin/console $commandName --env=test"); |
||||
|
0 ignored issues
–
show
'php '.$appDirectory.'/....mmandName.' --env=test' of type string is incompatible with the type array expected by parameter $command of Symfony\Component\Process\Process::__construct().
(
Ignorable by Annotation
)
If this is a false-positive, you can also ignore this issue in your code via the
Loading history...
|
|||||
| 74 | $process2 = new Process("php $appDirectory/../bin/console $commandName --env=test"); |
||||
| 75 | $process1->start(); |
||||
| 76 | $process2->start(); |
||||
| 77 | |||||
| 78 | // wait until both processes have terminated |
||||
| 79 | while (!$process1->isTerminated() || !$process2->isTerminated()) { |
||||
| 80 | usleep(10); |
||||
| 81 | } |
||||
| 82 | |||||
| 83 | $this->assertContains('The command is already running in another process.', $process2->getOutput().$process1->getOutput()); |
||||
| 84 | } |
||||
| 85 | } |
||||
| 86 |