Skip to content
This repository has been archived by the owner on Feb 6, 2022. It is now read-only.

Commit

Permalink
bug #262 Fix deprecations under Symfony 4.2 (chalasr)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.2-dev branch.

Discussion
----------

Fix deprecations under Symfony 4.2

Commits
-------

515e411 Fix deprecations under Symfony 4.2
  • Loading branch information
fabpot committed Oct 27, 2018
2 parents 0b156f3 + 515e411 commit 39317cc
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 11 deletions.
50 changes: 50 additions & 0 deletions Command/AbstractSwiftMailerCommand.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<?php

/*
* This file is part of the Symfony package.
*
* (c) Fabien Potencier <fabien@symfony.com>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/

namespace Symfony\Bundle\SwiftmailerBundle\Command;

use Symfony\Component\Console\Command\Command;
use Symfony\Component\DependencyInjection\ContainerInterface;

/**
* @internal
*/
abstract class AbstractSwiftMailerCommand extends Command
{
/**
* @var ContainerInterface|null
*/
private $container;

public function setContainer(ContainerInterface $container = null)
{
$this->container = $container;
}

/**
* @return ContainerInterface
*
* @throws \LogicException
*/
protected function getContainer()
{
if (null === $this->container) {
$application = $this->getApplication();
if (null === $application) {
throw new \LogicException('The container cannot be retrieved as the application instance is not yet set.');
}

$this->container = $application->getKernel()->getContainer();
}

return $this->container;
}
}
2 changes: 1 addition & 1 deletion Command/DebugCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
*
* @author Jérémy Romey <jeremy@free-agent.fr>
*/
class DebugCommand extends ContainerAwareCommand
class DebugCommand extends AbstractSwiftMailerCommand
{
protected static $defaultName = 'debug:swiftmailer';

Expand Down
2 changes: 1 addition & 1 deletion Command/NewEmailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
*
* @author Gusakov Nikita <dev@nkt.me>
*/
class NewEmailCommand extends ContainerAwareCommand
class NewEmailCommand extends AbstractSwiftMailerCommand
{
protected static $defaultName = 'swiftmailer:email:send';

Expand Down
2 changes: 1 addition & 1 deletion Command/SendEmailCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
* @author Clément JOBEILI <clement.jobeili@gmail.com>
* @author Toni Uebernickel <tuebernickel@gmail.com>
*/
class SendEmailCommand extends ContainerAwareCommand
class SendEmailCommand extends AbstractSwiftMailerCommand
{
protected static $defaultName = 'swiftmailer:spool:send';

Expand Down
8 changes: 4 additions & 4 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ public function __construct($debug)
*/
public function getConfigTreeBuilder()
{
$treeBuilder = new TreeBuilder();
$rootNode = $treeBuilder->root('swiftmailer');
$treeBuilder = new TreeBuilder('swiftmailer');
$rootNode = method_exists(TreeBuilder::class, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('swiftmailer');

$rootNode
->beforeNormalization()
Expand Down Expand Up @@ -82,8 +82,8 @@ public function getConfigTreeBuilder()
*/
private function getMailersNode()
{
$treeBuilder = new TreeBuilder();
$node = $treeBuilder->root('mailers');
$treeBuilder = new TreeBuilder('mailers');
$node = method_exists(TreeBuilder::class, 'getRootNode') ? $treeBuilder->getRootNode() : $treeBuilder->root('mailers');

$node
->requiresAtLeastOneElement()
Expand Down
14 changes: 10 additions & 4 deletions Tests/Command/SendEmailCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@

namespace Symfony\Bundle\SwiftmailerBundle\Tests\Command;

use Symfony\Bundle\FrameworkBundle\Console\Application;
use Symfony\Bundle\SwiftmailerBundle\Command\SendEmailCommand;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\Container;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\KernelInterface;

class SendEmailCommandTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -127,12 +129,16 @@ private function buildContainer(\Swift_Transport $transport, \Swift_Transport $r
/**
* @return CommandTester
*/
private function executeCommand(ContainerInterface $container, $input = [], $options = [])
private function executeCommand(ContainerInterface $container, $input = array(), $options = array())
{
$command = new SendEmailCommand();
$command->setContainer($container);
$kernel = $this->getMockBuilder(KernelInterface::class)->getMock();
$kernel->expects($this->any())->method('getContainer')->willReturn($container);
$kernel->expects($this->any())->method('getBundles')->willReturn(array());

$tester = new CommandTester($command);
$application = new Application($kernel);
$application->add(new SendEmailCommand());

$tester = new CommandTester($application->get('swiftmailer:spool:send'));
$tester->execute($input, $options);

return $tester;
Expand Down

0 comments on commit 39317cc

Please sign in to comment.