Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to Symfony 5 #27

Closed
wants to merge 6 commits into from
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ composer.lock

# mkdocs
/docs

/.idea
6 changes: 6 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,15 @@ language: php
php:
- 7.1
- 7.2
- 7.3
- 7.4
env:
- SYMFONY_VERSION=4.0.*
- SYMFONY_VERSION=4.1.*
- SYMFONY_VERSION=4.2.*
- SYMFONY_VERSION=4.3.*
- SYMFONY_VERSION=4.4.*
- SYMFONY_VERSION=5.0.*
before_install:
- composer require "symfony/config:${SYMFONY_VERSION}" --no-update
- composer require "symfony/dependency-injection:${SYMFONY_VERSION}" --no-update
Expand Down
9 changes: 7 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@
"name": "Mailjet API",
"email": "[email protected]",
"homepage": "https://dev.mailjet.com/"
},
{
"name": "Rémi JARJAT",
"email": "[email protected]",
"homepage": "https://github.com/Dreeckan"
}
],
"autoload": {
Expand All @@ -35,8 +40,8 @@
"mailjet/mailjet-swiftmailer": "^2.0"
},
"require-dev": {
"phpspec/phpspec": "~4@dev",
"symfony/symfony": "~4.0 | ~4.1"
"phpspec/phpspec": "^6.0",
"symfony/symfony": "^4.0 | ^5.0"
},
"config": {
"bin-dir": "bin"
Expand Down
19 changes: 18 additions & 1 deletion spec/Command/EventCommandSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,29 @@

namespace spec\Mailjet\MailjetBundle\Command;

use Symfony\Component\DependencyInjection\ContainerInterface;
use Mailjet\MailjetBundle\Manager\EventCallbackUrlManager;
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\Routing\RouterInterface;

class EventCommandSpec extends ObjectBehavior
{
/**
* @param EventCallbackUrlManager $eventCallbackUrlManager
* @param RouterInterface $router
*/
public function let(
EventCallbackUrlManager $eventCallbackUrlManager,
RouterInterface $router
) {
$this->beConstructedWith(
$eventCallbackUrlManager,
$router,
'mailjet.event_endpoint_route',
'mailjet.event_endpoint_token'
);
}

function it_is_initializable()
{
Expand Down
14 changes: 14 additions & 0 deletions spec/Command/SyncContactMetadataCommandSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,22 @@
use PhpSpec\ObjectBehavior;
use Prophecy\Argument;

use Mailjet\MailjetBundle\Manager\ContactMetadataManager;

class SyncContactMetadataCommandSpec extends ObjectBehavior
{
/**
* @param ContactMetadataManager $eventCallbackUrlManager
*/
public function let(
ContactMetadataManager $metadataManager
) {
$this->beConstructedWith(
$metadataManager,
'mailjet.contact_metadata'
);
}

function it_is_initializable()
{
$this->shouldHaveType('Mailjet\MailjetBundle\Command\SyncContactMetadataCommand');
Expand Down
6 changes: 6 additions & 0 deletions spec/Command/SyncUserCommandSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,15 @@

use PhpSpec\ObjectBehavior;
use Prophecy\Argument;
use Mailjet\MailjetBundle\Synchronizer\ContactsListSynchronizer;

class SyncUserCommandSpec extends ObjectBehavior
{
public function let(ContactsListSynchronizer $synchronizer)
{
$this->beConstructedWith($synchronizer, []);
}

function it_is_initializable()
{
$this->shouldHaveType('Mailjet\MailjetBundle\Command\SyncUserCommand');
Expand Down
22 changes: 11 additions & 11 deletions spec/Controller/EventControllerSpec.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ function let(ContainerInterface $container)
function it_is_initializable()
{
$this->shouldHaveType('Mailjet\MailjetBundle\Controller\EventController');
$this->shouldHaveType('Symfony\Bundle\FrameworkBundle\Controller\Controller');
$this->shouldHaveType('Symfony\Bundle\FrameworkBundle\Controller\AbstractController');

}

Expand Down Expand Up @@ -78,7 +78,7 @@ function it_pass_with_simple_payload(ContainerInterface $container, EventDispatc
$container->getParameter('mailjet.event_endpoint_token')->shouldBeCalled()->willReturn('12345678');
$container->get('event_dispatcher')->shouldBeCalled()->willReturn($eventDispatcher);

$eventDispatcher->dispatch(CallbackEvent::EVENT_UNSUB, new CallbackEvent(json_decode($data, true)))->shouldBeCalled();
$eventDispatcher->dispatch(new CallbackEvent(json_decode($data, true)), CallbackEvent::EVENT_UNSUB)->shouldBeCalled();

$this->indexAction($request, '12345678');
}
Expand Down Expand Up @@ -119,8 +119,8 @@ function it_pass_with_grouped_payload(ContainerInterface $container, EventDispat
$container->getParameter('mailjet.event_endpoint_token')->shouldBeCalled()->willReturn('12345678');
$container->get('event_dispatcher')->shouldBeCalled()->willReturn($eventDispatcher);

$eventDispatcher->dispatch(CallbackEvent::EVENT_SENT, new CallbackEvent(json_decode($data, true)[0]))->shouldBeCalled();
$eventDispatcher->dispatch(CallbackEvent::EVENT_SENT, new CallbackEvent(json_decode($data, true)[1]))->shouldBeCalled();
$eventDispatcher->dispatch(new CallbackEvent(json_decode($data, true)[0]), CallbackEvent::EVENT_SENT)->shouldBeCalled();
$eventDispatcher->dispatch(new CallbackEvent(json_decode($data, true)[1]), CallbackEvent::EVENT_SENT)->shouldBeCalled();

$this->indexAction($request, '12345678');
}
Expand Down Expand Up @@ -252,13 +252,13 @@ function it_test_all_event_type(ContainerInterface $container, EventDispatcherIn
$container->getParameter('mailjet.event_endpoint_token')->shouldBeCalled()->willReturn('12345678');
$container->get('event_dispatcher')->shouldBeCalled()->willReturn($eventDispatcher);

$eventDispatcher->dispatch(CallbackEvent::EVENT_SENT, new CallbackEvent(json_decode($data, true)[0]))->shouldBeCalled();
$eventDispatcher->dispatch(CallbackEvent::EVENT_OPEN, new CallbackEvent(json_decode($data, true)[1]))->shouldBeCalled();
$eventDispatcher->dispatch(CallbackEvent::EVENT_CLICK, new CallbackEvent(json_decode($data, true)[2]))->shouldBeCalled();
$eventDispatcher->dispatch(CallbackEvent::EVENT_BOUNCE, new CallbackEvent(json_decode($data, true)[3]))->shouldBeCalled();
$eventDispatcher->dispatch(CallbackEvent::EVENT_SPAM, new CallbackEvent(json_decode($data, true)[4]))->shouldBeCalled();
$eventDispatcher->dispatch(CallbackEvent::EVENT_BLOCKED, new CallbackEvent(json_decode($data, true)[5]))->shouldBeCalled();
$eventDispatcher->dispatch(CallbackEvent::EVENT_UNSUB, new CallbackEvent(json_decode($data, true)[6]))->shouldBeCalled();
$eventDispatcher->dispatch(new CallbackEvent(json_decode($data, true)[0]), CallbackEvent::EVENT_SENT)->shouldBeCalled();
$eventDispatcher->dispatch(new CallbackEvent(json_decode($data, true)[1]), CallbackEvent::EVENT_OPEN)->shouldBeCalled();
$eventDispatcher->dispatch(new CallbackEvent(json_decode($data, true)[2]), CallbackEvent::EVENT_CLICK)->shouldBeCalled();
$eventDispatcher->dispatch(new CallbackEvent(json_decode($data, true)[3]), CallbackEvent::EVENT_BOUNCE)->shouldBeCalled();
$eventDispatcher->dispatch(new CallbackEvent(json_decode($data, true)[4]), CallbackEvent::EVENT_SPAM)->shouldBeCalled();
$eventDispatcher->dispatch(new CallbackEvent(json_decode($data, true)[5]), CallbackEvent::EVENT_BLOCKED)->shouldBeCalled();
$eventDispatcher->dispatch(new CallbackEvent(json_decode($data, true)[6]), CallbackEvent::EVENT_UNSUB)->shouldBeCalled();

$this->indexAction($request, '12345678');
}
Expand Down
38 changes: 24 additions & 14 deletions src/Command/EventCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,29 @@

use Mailjet\MailjetBundle\Manager\EventCallbackUrlManager;
use Mailjet\MailjetBundle\Model\EventCallbackUrl;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Routing\RouterInterface;

class EventCommand extends ContainerAwareCommand
class EventCommand extends Command
{
public function __construct(
EventCallbackUrlManager $eventCallbackUrlManager,
RouterInterface $router,
$endPointRoute,
$endPointToken
) {
$this->eventCallbackUrlManager = $eventCallbackUrlManager;
$this->router = $router;
$this->endPointRoute = $endPointRoute;
$this->endPointToken = $endPointToken;

parent::__construct('mailjet:event-endpoint');
}

protected function configure()
{
$this
Expand Down Expand Up @@ -39,11 +54,6 @@ protected function execute(InputInterface $input, OutputInterface $output)
));
$url = sprintf('%s/%s', rtrim($domain, '/'), ltrim($uri, '/'));

/**
* @var EventCallbackUrlManager $manager
*/
$manager = $this->getContainer()->get('mailjet.service.event_callback_manager');

if ($input->getOption('event-type')) {
$eventTypes = $input->getOption('event-type');
} else {
Expand All @@ -54,12 +64,12 @@ protected function execute(InputInterface $input, OutputInterface $output)
$eventCallBackUrl = new EventCallbackUrl($url, $eventType, true);

try {
$manager->get($eventType);
$this->eventCallbackUrlManager->get($eventType);
$output->writeln('update '.$eventType);
$manager->update($eventType, $eventCallBackUrl);
$this->eventCallbackUrlManager->update($eventType, $eventCallBackUrl);
} catch (\Exception $e) {
$output->writeln('create '.$eventType);
$manager->create($eventCallBackUrl);
$this->eventCallbackUrlManager->create($eventCallBackUrl);
}
}

Expand All @@ -71,22 +81,22 @@ protected function execute(InputInterface $input, OutputInterface $output)
*/
protected function getRouter()
{
return $this->getContainer()->get('router');
return $this->router;
}

/**
* @return string
*/
protected function getRouteName()
{
return $this->getContainer()->getParameter('mailjet.event_endpoint_route');
return $this->endPointRoute;
}

/**
* @return string
*/
protected function getToken()
{
return $this->getContainer()->getParameter('mailjet.event_endpoint_token');
return $this->endPointToken;
}
}
29 changes: 20 additions & 9 deletions src/Command/SyncContactMetadataCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,42 @@

namespace Mailjet\MailjetBundle\Command;

use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Mailjet\MailjetBundle\Manager\ContactMetadataManager;
use Mailjet\MailjetBundle\Model\ContactMetadata;
use Mailjet\MailjetBundle\Provider\ProviderInterface;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;

use Mailjet\MailjetBundle\Model\ContactMetadata;
use Mailjet\MailjetBundle\Provider\ProviderInterface;

/**
* Class SyncUserCommand
* Sync users in a mailjet contact list
*
*/
class SyncContactMetadataCommand extends ContainerAwareCommand
class SyncContactMetadataCommand extends Command
{

/**
* @var array
*/
private $contactMetadata;

/**
* @param ContactMetadataManager $metadataManager
* @param array $contactMetadata
*/
public function __construct(
ContactMetadataManager $metadataManager,
$contactMetadata
) {
$this->metadataManager = $metadataManager;
$this->contactMetadata = $contactMetadata;

parent::__construct('mailjet:contactmetadata-sync');
}

/**
* {@inheritDoc}
*/
Expand All @@ -40,8 +54,6 @@ protected function configure()
protected function initialize(InputInterface $input, OutputInterface $output)
{
$output->writeln(sprintf('<info>%s</info>', $this->getDescription()));

$this->contactMetadata = $this->getContainer()->getParameter('mailjet.contact_metadata');
}

/**
Expand All @@ -52,11 +64,10 @@ protected function execute(InputInterface $input, OutputInterface $output)
// @TODO create a ContactMetadataSynchronizer
// @TODO update existing ContactMetadata (in order to not throw error...)
foreach ($this->contactMetadata as $contactMetadata) {

$metadataObj = new ContactMetadata($contactMetadata['name'], $contactMetadata['datatype']);

try {
$response = $this->getContainer()->get('mailjet.service.contact_metadata_manager')->create($metadataObj);
$response = $this->metadataManager->create($metadataObj);
$output->writeln(sprintf('<info>%s:%s added!</info>', $contactMetadata['name'], $contactMetadata['datatype']));
} catch (\Exception $e) {
$output->writeln(sprintf('<error>%s</error>', $e->getMessage()));
Expand Down
29 changes: 19 additions & 10 deletions src/Command/SyncUserCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,25 +2,23 @@

namespace Mailjet\MailjetBundle\Command;

use Mailjet\MailjetBundle\Model\ContactsList;
use Mailjet\MailjetBundle\Provider\ProviderInterface;
use Mailjet\MailjetBundle\Synchronizer\ContactsListSynchronizer;
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\DependencyInjection\Exception\ServiceNotFoundException;

use Mailjet\MailjetBundle\Model\ContactsList;
use Mailjet\MailjetBundle\Provider\ProviderInterface;

/**
* Class SyncUserCommand
* Sync users in a mailjet contact list
*
*/
class SyncUserCommand extends ContainerAwareCommand
class SyncUserCommand extends Command
{

/**
* @var array
*/
Expand All @@ -31,6 +29,20 @@ class SyncUserCommand extends ContainerAwareCommand
*/
private $synchronizer;

/**
* @param ContactsListSynchronizer $synchronizer
* @param array $lists
*/
public function __construct(
ContactsListSynchronizer $synchronizer,
array $lists = []
) {
$this->synchronizer = $synchronizer;
$this->lists = $lists;

parent::__construct('mailjet:user-sync');
}

/**
* {@inheritDoc}
*/
Expand All @@ -54,9 +66,6 @@ protected function configure()
protected function initialize(InputInterface $input, OutputInterface $output)
{
$output->writeln(sprintf('<info>%s</info>', $this->getDescription()));

$this->lists = $this->getContainer()->getParameter('mailjet.lists');
$this->synchronizer = $this->getContainer()->get('mailjet.service.contacts_list_synchronizer');
}

/**
Expand Down
Loading