Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/phpunit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI

on:
push:
pull_request:

jobs:
test:
name: "PHPUnit (PHP ${{ matrix.php-version }}, deps: ${{ matrix.dependency-mode }})"
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
php-version: ['8.5']
dependency-mode: ['stable', 'lowest']

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extensions: mailparse
coverage: none

- name: Validate composer.json
run: composer validate --strict

- name: Cache Composer
uses: actions/cache@v4
with:
path: |
~/.composer/cache/files
~/.cache/composer/files
key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependency-mode }}-${{ hashFiles('composer.json') }}
restore-keys: |
${{ runner.os }}-php-${{ matrix.php-version }}-${{ matrix.dependency-mode }}-

- name: Install dependencies (stable)
if: matrix.dependency-mode == 'stable'
run: composer update --no-interaction --prefer-dist

- name: Install dependencies (lowest)
if: matrix.dependency-mode == 'lowest'
run: composer update --no-interaction --prefer-lowest --prefer-stable

- name: Run PHPUnit
run: vendor/bin/phpunit -c phpunit.xml.dist
44 changes: 7 additions & 37 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,50 +1,20 @@
# Legacy CI kept for backward compatibility.
# GitHub Actions (.github/workflows/phpunit.yml) is the primary CI pipeline.
language: php

php:
- 7.1
- 7.2
- 8.5

env:
- SYMFONY_VERSION=lts:^2
- SYMFONY_VERSION=lts:^3
- SYMFONY_VERSION=flex:^1
- SYMFONY_VERSION=lts:^4


matrix:
fast_finish: true
include:
- env:
- SYMFONY_VERSION=lts:^2
- dependencies=lowest

- env:
- SYMFONY_VERSION=lts:^3
- cs_fixer=cs_dry_run

allow_failures:
- env: SYMFONY_VERSION=lts:^4
- DEPENDENCIES=stable
- DEPENDENCIES=lowest

cache:
directories:
- $HOME/.composer/cache

before_install:
- mv /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini ~/xdebug.ini
- composer self-update

before_script:
- phpenv config-add travis.php.ini
- travis_wait composer require symfony/${SYMFONY_VERSION} --prefer-source --no-update -v
- mv ~/xdebug.ini /home/travis/.phpenv/versions/$(phpenv version-name)/etc/conf.d/xdebug.ini
- if [ "$dependencies" != "lowest" ]; then travis_wait composer update --prefer-source; fi;
- if [ "$dependencies" = "lowest" ]; then travis_wait composer update --prefer-lowest --prefer-stable -n; fi;
- if [ "$DEPENDENCIES" = "lowest" ]; then composer update --prefer-lowest --prefer-stable -n; else composer update --prefer-dist -n; fi

script:
- travis_wait vendor/phpunit/phpunit/phpunit --coverage-text --coverage-clover=coverage.clover Tests/
- wget https://scrutinizer-ci.com/ocular.phar
- php ocular.phar code-coverage:upload --format=php-clover coverage.clover
- if [ "$cs_fixer" = "cs_dry_run" ]; then php vendor/friendsofphp/php-cs-fixer/php-cs-fixer --diff --dry-run -v fix --config=.php_cs.dist ./; fi;

notifications:
email: travis@azine-it.ch
- vendor/bin/phpunit -c phpunit.xml.dist
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,32 @@ This bundle captures this data. You can search for, filter and display log-entri
delete them when you don't need them anymore (or when you need to save some disk-space).



## Requirements (current)
- PHP **8.5+**
- Symfony **7.4** components
- Twig **3.x**
- Doctrine ORM **3.3+**
- PHP extension: **mailparse**

## Local test execution
1. Install dependencies:
```bash
composer update
```
2. Run tests:
```bash
vendor/bin/phpunit -c phpunit.xml.dist
```
3. (Optional) Validate Composer metadata:
```bash
composer validate --strict
```

## CI
GitHub Actions is the primary CI and runs on every push and pull request via `.github/workflows/phpunit.yml`.
It tests stable and lowest dependency installs on PHP 8.5.

## Features
- capture all data that mailgun.com can post via the "webhooks" provided by mailgun.com => http://documentation.mailgun.com/user_manual.html#webhooks
- display lists of event entries with search and filter functionality
Expand Down
26 changes: 13 additions & 13 deletions Tests/Command/CheckIpAddressIsBlacklistedCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,18 +72,18 @@ public function setUp(): void
'api_blacklist_check_link' => 'https://api.example.com/v2/token/blacklist-check/ipv4/198.51.100.42/',
);

$this->entityRepository = $this->getMockBuilder('Doctrine\ORM\EntityRepository')->disableOriginalConstructor()->setMethods(array('getLastKnownSenderIpData', 'findBy'))->getMock();
$this->entityRepository = $this->getMockBuilder('Doctrine\ORM\EntityRepository')->disableOriginalConstructor()->onlyMethods(array('getLastKnownSenderIpData', 'findBy'))->getMock();
$this->entityRepository->expects($this->any())->method('getLastKnownSenderIpData')->will($this->returnValue(array('ip' => '198.51.100.42', 'timestamp' => '1552971782')));

$this->entityManager = $this->getMockBuilder(EntityRepository::class)->disableOriginalConstructor()->setMethods(array('getRepository'))->getMock();
$this->entityManager = $this->getMockBuilder(EntityRepository::class)->disableOriginalConstructor()->onlyMethods(array('getRepository'))->getMock();
$this->entityManager->expects($this->any())->method('getRepository')->will($this->returnValue($this->entityRepository));

$this->registry = $this->getMockBuilder("Doctrine\Common\Persistence\ManagerRegistry")->disableOriginalConstructor()->getMock();
$this->registry = $this->getMockBuilder("Doctrine\Persistence\ManagerRegistry")->disableOriginalConstructor()->getMock();
$this->registry->expects($this->any())->method('getManager')->will($this->returnValue($this->entityManager));

$this->hetrixtoolsService = $this->getMockBuilder("Azine\MailgunWebhooksBundle\Services\HetrixtoolsService\AzineMailgunHetrixtoolsService")->disableOriginalConstructor()->setMethods(array('checkIpAddressInBlacklist'))->getMock();
$this->hetrixtoolsService = $this->getMockBuilder("Azine\MailgunWebhooksBundle\Services\HetrixtoolsService\AzineMailgunHetrixtoolsService")->disableOriginalConstructor()->onlyMethods(array('checkIpAddressInBlacklist'))->getMock();

$this->azineMailgunService = $this->getMockBuilder("Azine\MailgunWebhooksBundle\Services\AzineMailgunMailerService")->disableOriginalConstructor()->setMethods(array('sendBlacklistNotification'))->getMock();
$this->azineMailgunService = $this->getMockBuilder("Azine\MailgunWebhooksBundle\Services\AzineMailgunMailerService")->disableOriginalConstructor()->onlyMethods(array('sendBlacklistNotification'))->getMock();
$this->azineMailgunService->expects($this->any())->method('sendBlacklistNotification')->will($this->returnvalue(1));

$this->blackListNotificationRepository = $this->getMockBuilder(HetrixToolsBlacklistResponseNotificationRepository::class)->disableOriginalConstructor()->getMock();
Expand All @@ -101,7 +101,7 @@ public function testSendingBlackListReportFirstTimeSent()
$tester->execute(array(''));

$display = $tester->getDisplay();
$this->assertContains(CheckIpAddressIsBlacklistedCommand::BLACKLIST_REPORT_WAS_SENT, $display);
$this->assertStringContainsString(CheckIpAddressIsBlacklistedCommand::BLACKLIST_REPORT_WAS_SENT, $display);
}

public function testSendingBlackListReportNotMutedSent()
Expand All @@ -114,7 +114,7 @@ public function testSendingBlackListReportNotMutedSent()
$tester->execute(array(''));

$display = $tester->getDisplay();
$this->assertContains(CheckIpAddressIsBlacklistedCommand::BLACKLIST_REPORT_WAS_SENT, $display);
$this->assertStringContainsString(CheckIpAddressIsBlacklistedCommand::BLACKLIST_REPORT_WAS_SENT, $display);
}

public function testSendingBlackListReportLastNotificationIsLongSinceAndListsAreTheSameSent()
Expand All @@ -132,7 +132,7 @@ public function testSendingBlackListReportLastNotificationIsLongSinceAndListsAre
$tester->execute(array(''));

$display = $tester->getDisplay();
$this->assertContains(CheckIpAddressIsBlacklistedCommand::BLACKLIST_REPORT_WAS_SENT, $display);
$this->assertStringContainsString(CheckIpAddressIsBlacklistedCommand::BLACKLIST_REPORT_WAS_SENT, $display);
}

public function testSendingBlackListReportLastNotificationIsRecentButListsAreNotTheSameSent()
Expand Down Expand Up @@ -168,7 +168,7 @@ public function testSendingBlackListReportLastNotificationIsRecentButListsAreNot
$tester->execute(array(''));

$display = $tester->getDisplay();
$this->assertContains(CheckIpAddressIsBlacklistedCommand::BLACKLIST_REPORT_WAS_SENT, $display);
$this->assertStringContainsString(CheckIpAddressIsBlacklistedCommand::BLACKLIST_REPORT_WAS_SENT, $display);
}

public function testSendingBlackListReportLastNotificationIsRecentButListsNotChangedMuted()
Expand All @@ -186,7 +186,7 @@ public function testSendingBlackListReportLastNotificationIsRecentButListsNotCha
$tester->execute(array(''));

$display = $tester->getDisplay();
$this->assertContains(CheckIpAddressIsBlacklistedCommand::BLACKLIST_REPORT_IS_SAME_AS_PREVIOUS, $display);
$this->assertStringContainsString(CheckIpAddressIsBlacklistedCommand::BLACKLIST_REPORT_IS_SAME_AS_PREVIOUS, $display);
}

public function testSendingBlackListReportNotListedNotSent()
Expand All @@ -202,7 +202,7 @@ public function testSendingBlackListReportNotListedNotSent()
$tester->execute(array(''));

$display = $tester->getDisplay();
$this->assertContains(CheckIpAddressIsBlacklistedCommand::IP_IS_NOT_BLACKLISTED, $display);
$this->assertStringContainsString(CheckIpAddressIsBlacklistedCommand::IP_IS_NOT_BLACKLISTED, $display);
}

public function testSendingBlackListReportNoResponseShowError()
Expand All @@ -213,7 +213,7 @@ public function testSendingBlackListReportNoResponseShowError()
$tester->execute(array(''));

$display = $tester->getDisplay();
$this->assertContains(CheckIpAddressIsBlacklistedCommand::NO_VALID_RESPONSE_FROM_HETRIX, $display);
$this->assertStringContainsString(CheckIpAddressIsBlacklistedCommand::NO_VALID_RESPONSE_FROM_HETRIX, $display);
}

/**
Expand All @@ -222,7 +222,7 @@ public function testSendingBlackListReportNoResponseShowError()
private function getTester($muteDays = 0)
{
$application = new Application();
$application->add(new CheckIpAddressIsBlacklistedCommand($this->registry, $this->hetrixtoolsService, $this->azineMailgunService, 'test', $muteDays));
$application->addCommand(new CheckIpAddressIsBlacklistedCommand($this->registry, $this->hetrixtoolsService, $this->azineMailgunService, 'test', $muteDays));
$command = $this->getCheckIpAddressIsBlacklistedCommand($application);
$tester = new CommandTester($command);

Expand Down
40 changes: 19 additions & 21 deletions Tests/Command/DeleteOldEntriesCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,32 +20,32 @@ public function setUp(): void
public function testHelpInfo()
{
$application = new Application();
$application->add(new DeleteOldEntriesCommand($this->mailgunServiceMock));
$application->addCommand(new DeleteOldEntriesCommand($this->mailgunServiceMock));
$command = $this->getDeleteOldEntriesCommand($application);

$display = $command->getHelp();
$this->assertContains('Mailgun accepted the request to send/forward the email and the message has been placed in queue.', $display);
$this->assertStringContainsString('Mailgun accepted the request to send/forward the email and the message has been placed in queue.', $display);
}

public function testDeleteOldEntriesWithoutParams()
{
$application = new Application();
$application->add(new DeleteOldEntriesCommand($this->mailgunServiceMock));
$application->addCommand(new DeleteOldEntriesCommand($this->mailgunServiceMock));
$command = $this->getDeleteOldEntriesCommand($application);

self::$days = 60;
self::$count = 14;
self::$type = null;
$this->mailgunServiceMock->expects($this->once())->method('removeEvents')->will($this->returnCallback(array($this, 'removeEventsCallback')));
$this->mailgunServiceMock->expects($this->once())->method('removeEvents')->willReturnCallback(array($this, 'removeEventsCallback'));

$tester = new CommandTester($command);

$tester->execute(array(''));
$display = $tester->getDisplay();
$this->assertContains('deleting entries of any type.', $display);
$this->assertContains("using default age-limit of '60 days ago'.", $display);
$this->assertContains('All MailgunEvents (& their CustomVariables & Attachments) older than', $display);
$this->assertContains('of any type have been deleted (14).', $display);
$this->assertStringContainsString('deleting entries of any type.', $display);
$this->assertStringContainsString("using default age-limit of '60 days ago'.", $display);
$this->assertStringContainsString('All MailgunEvents (& their CustomVariables & Attachments) older than', $display);
$this->assertStringContainsString('of any type have been deleted (14).', $display);
}

public static $days;
Expand Down Expand Up @@ -74,48 +74,46 @@ private function getDeleteOldEntriesCommand($application)
public function testDeleteOldEntriesWithDate()
{
$application = new Application();
$application->add(new DeleteOldEntriesCommand($this->mailgunServiceMock));
$application->addCommand(new DeleteOldEntriesCommand($this->mailgunServiceMock));
$command = $this->getDeleteOldEntriesCommand($application);

self::$days = 21;
self::$count = 11;
self::$type = null;
$this->mailgunServiceMock->expects($this->once())->method('removeEvents')->will($this->returnCallback(array($this, 'removeEventsCallback')));
$this->mailgunServiceMock->expects($this->once())->method('removeEvents')->willReturnCallback(array($this, 'removeEventsCallback'));

$tester = new CommandTester($command);

$tester->execute(array('date' => '21 days ago'));
$display = $tester->getDisplay();
$this->assertContains('deleting entries of any type.', $display);
$this->assertContains('All MailgunEvents (& their CustomVariables & Attachments) older than', $display);
$this->assertContains('of any type have been deleted (11).', $display);
$this->assertStringContainsString('deleting entries of any type.', $display);
$this->assertStringContainsString('All MailgunEvents (& their CustomVariables & Attachments) older than', $display);
$this->assertStringContainsString('of any type have been deleted (11).', $display);
}

public function testDeleteOldEntriesWithDateAndType()
{
$application = new Application();
$application->add(new DeleteOldEntriesCommand($this->mailgunServiceMock));
$application->addCommand(new DeleteOldEntriesCommand($this->mailgunServiceMock));
$command = $this->getDeleteOldEntriesCommand($application);

self::$days = 33;
self::$count = 77;
self::$type = 'opened';
$this->mailgunServiceMock->expects($this->once())->method('removeEvents')->will($this->returnCallback(array($this, 'removeEventsCallback')));
$this->mailgunServiceMock->expects($this->once())->method('removeEvents')->willReturnCallback(array($this, 'removeEventsCallback'));

$tester = new CommandTester($command);
$tester->execute(array('date' => '33 days ago', 'type' => self::$type));
$display = $tester->getDisplay();
$this->assertContains('All MailgunEvents (& their CustomVariables & Attachments) older than', $display);
$this->assertContains("of type '".self::$type."' have been deleted (77).", $display);
$this->assertStringContainsString('All MailgunEvents (& their CustomVariables & Attachments) older than', $display);
$this->assertStringContainsString("of type '".self::$type."' have been deleted (77).", $display);
}

/**
* @expectedException \InvalidArgumentException
*/
public function testDeleteOldEntriesWithInvalidType()
{
$this->expectException(\Symfony\Component\DependencyInjection\Exception\InvalidArgumentException::class);
$application = new Application();
$application->add(new DeleteOldEntriesCommand($this->mailgunServiceMock));
$application->addCommand(new DeleteOldEntriesCommand($this->mailgunServiceMock));
$command = $this->getDeleteOldEntriesCommand($application);

$tester = new CommandTester($command);
Expand Down
10 changes: 5 additions & 5 deletions Tests/Controller/MailgunControllerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,12 @@ private function loginUserIfRequired(Client $client, $url, $username = 'dominik'
// if redirected to a login-page, login as admin-user
if (5 == $crawler->filter('input')->count() && 1 == $crawler->filter('#username')->count() && 1 == $crawler->filter('#password')->count()) {
// set the password of the admin
$userProvider = $this->getContainer()->get('fos_user.user_provider.username_email');
$userProvider = $this->getAppContainer()->get('fos_user.user_provider.username_email');
$user = $userProvider->loadUserByUsername($username);
$user->setPlainPassword($password);
$user->addRole('ROLE_ADMIN');

$userManager = $this->getContainer()->get('fos_user.user_manager');
$userManager = $this->getAppContainer()->get('fos_user.user_manager');
$userManager->updateUser($user);

$crawler = $crawler->filter("input[type='submit']");
Expand Down Expand Up @@ -90,7 +90,7 @@ private function loginUserIfRequired(Client $client, $url, $username = 'dominik'
*
* @return \Symfony\Component\DependencyInjection\ContainerInterface
*/
private function getContainer()
private function getAppContainer()
{
if (null == $this->appContainer) {
$this->appContainer = static::$kernel->getContainer();
Expand All @@ -104,15 +104,15 @@ private function getContainer()
*/
private function getRouter()
{
return $this->getContainer()->get('router');
return $this->getAppContainer()->get('router');
}

/**
* @return EntityManager
*/
private function getEntityManager()
{
return $this->getContainer()->get('doctrine.orm.entity_manager');
return $this->getAppContainer()->get('doctrine.orm.entity_manager');
}

/**
Expand Down
Loading
Loading