| 1 | <?php |
||
| 2 | |||
| 3 | namespace Azine\MailgunWebhooksBundle\Tests\Services; |
||
| 4 | |||
| 5 | use Azine\MailgunWebhooksBundle\Services\AzineMailgunMailerService; |
||
| 6 | use Symfony\Bridge\Doctrine\ManagerRegistry; |
||
|
0 ignored issues
–
show
|
|||
| 7 | use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; |
||
| 8 | use Symfony\Component\DependencyInjection\ContainerInterface; |
||
| 9 | use Symfony\Component\Translation\Translator; |
||
| 10 | |||
| 11 | class AzineMailgunMailerServiceTest extends WebTestCase |
||
| 12 | { |
||
| 13 | public function testSendSpamComplaintNotification() |
||
| 14 | { |
||
| 15 | $this->checkApplication(); |
||
| 16 | |||
| 17 | // Create a new client to browse the application |
||
| 18 | $client = static::createClient(); |
||
| 19 | $client->request('GET', '/'); |
||
| 20 | $client->followRedirects(); |
||
| 21 | |||
| 22 | /** @var \Swift_Mailer $mailer */ |
||
| 23 | $mailer = $this->getContainer()->get('mailer'); |
||
| 24 | /** @var \Twig_Environment $twig */ |
||
| 25 | $twig = $this->getContainer()->get('twig'); |
||
| 26 | /** @var Translator $translator */ |
||
| 27 | $translator = $this->getContainer()->get('translator'); |
||
| 28 | $fromEmail = '[email protected]'; |
||
| 29 | $ticketId = '123'; |
||
| 30 | $ticketSubject = 'test'; |
||
| 31 | $ticketMessage = 'testMessage'; |
||
| 32 | $spamAlertsRecipientEmail = '[email protected]'; |
||
| 33 | /** @var ManagerRegistry $managerRegistry */ |
||
| 34 | $managerRegistry = $this->getContainer()->get('doctrine'); |
||
| 35 | $sendIntervalSeconds = 1; |
||
| 36 | |||
| 37 | $mailgunMailerService = new AzineMailgunMailerService($mailer, $twig, $translator,$fromEmail, $ticketId, |
||
| 38 | $ticketSubject, $ticketMessage, $spamAlertsRecipientEmail, $managerRegistry, $sendIntervalSeconds); |
||
| 39 | |||
| 40 | $messageSent = $mailgunMailerService->sendSpamComplaintNotification(123); |
||
| 41 | |||
| 42 | // Check that email was sent |
||
| 43 | $this->assertSame(1, $messageSent); |
||
| 44 | |||
| 45 | $messageSent = $mailgunMailerService->sendSpamComplaintNotification(123); |
||
| 46 | |||
| 47 | // Check that an email was not sent because the last email was sent less then azine_mailgun_webhooks_send_spam_alerts_interval |
||
| 48 | $this->assertSame(0, $messageSent); |
||
| 49 | |||
| 50 | $timeToWait = ($sendIntervalSeconds + 1); |
||
| 51 | sleep($timeToWait); |
||
| 52 | $messageSent = $mailgunMailerService->sendSpamComplaintNotification(123); |
||
| 53 | |||
| 54 | // Check that email was sent after azine_mailgun_webhooks_send_spam_alerts_interval have passed |
||
| 55 | $this->assertSame(1, $messageSent); |
||
| 56 | } |
||
| 57 | |||
| 58 | /** |
||
| 59 | * @var ContainerInterface |
||
| 60 | */ |
||
| 61 | private $appContainer; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Get the current container. |
||
| 65 | * |
||
| 66 | * @return \Symfony\Component\DependencyInjection\ContainerInterface |
||
| 67 | */ |
||
| 68 | private function getContainer() |
||
| 69 | { |
||
| 70 | if (null == $this->appContainer) { |
||
| 71 | $this->appContainer = static::$kernel->getContainer(); |
||
| 72 | } |
||
| 73 | |||
| 74 | return $this->appContainer; |
||
| 75 | } |
||
| 76 | |||
| 77 | /** |
||
| 78 | * Check if the current setup is a full application. |
||
| 79 | * If not, mark the test as skipped else continue. |
||
| 80 | */ |
||
| 81 | private function checkApplication() |
||
| 82 | { |
||
| 83 | try { |
||
| 84 | static::$kernel = static::createKernel(array()); |
||
| 85 | static::$kernel->boot(); |
||
| 86 | } catch (\RuntimeException $ex) { |
||
| 87 | $this->markTestSkipped('There does not seem to be a full application available (e.g. running tests on travis.org). So this test is skipped.'); |
||
| 88 | |||
| 89 | return; |
||
| 90 | } |
||
| 91 | } |
||
| 92 | } |
||
| 93 |
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.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths