]> git.immae.eu Git - github/wallabag/wallabag.git/commitdiff
Use translator interface instead of final class 1587/head
authorJeremy Benoist <jeremy.benoist@gmail.com>
Sun, 17 Jan 2016 11:52:30 +0000 (12:52 +0100)
committerJeremy Benoist <jeremy.benoist@gmail.com>
Sun, 17 Jan 2016 11:56:04 +0000 (12:56 +0100)
Symfony use a different class when in dev mode and prod mode.

Prod loads `Symfony\Bundle\FrameworkBundle\Translation\Translator`.
Dev loads `Symfony\Component\Translation\DataCollectorTranslator` to gather information for the debug bar.

Fix #1585

src/Wallabag/CoreBundle/Repository/EntryRepository.php
src/Wallabag/UserBundle/Mailer/AuthCodeMailer.php
src/Wallabag/UserBundle/Tests/Mailer/AuthCodeMailerTest.php

index 82eb947462ea1db1e7653d9ffc725313c04ab127..87e34dc997c50fbea9d7864290f554d3d236983f 100644 (file)
@@ -255,7 +255,7 @@ class EntryRepository extends EntityRepository
      *
      * @param int $userId
      *
-     * @return integer
+     * @return int
      */
     public function countAllEntriesByUsername($userId)
     {
index f1960070dd24dc52fd56c11654f7a5731a591679..be370e71d98677fbb0e48940b18f9bf3868c56b6 100644 (file)
@@ -4,7 +4,7 @@ namespace Wallabag\UserBundle\Mailer;
 
 use Scheb\TwoFactorBundle\Model\Email\TwoFactorInterface;
 use Scheb\TwoFactorBundle\Mailer\AuthCodeMailerInterface;
-use Symfony\Component\Translation\DataCollectorTranslator;
+use Symfony\Component\Translation\TranslatorInterface;
 
 /**
  * Custom mailer for TwoFactorBundle email.
@@ -22,7 +22,7 @@ class AuthCodeMailer implements AuthCodeMailerInterface
     /**
      * Translator for email content.
      *
-     * @var DataCollectorTranslator
+     * @var TranslatorInterface
      */
     private $translator;
 
@@ -50,13 +50,13 @@ class AuthCodeMailer implements AuthCodeMailerInterface
     /**
      * Initialize the auth code mailer with the SwiftMailer object.
      *
-     * @param \Swift_Mailer           $mailer
-     * @param DataCollectorTranslator $translator
-     * @param string                  $senderEmail
-     * @param string                  $senderName
-     * @param string                  $supportUrl
+     * @param \Swift_Mailer       $mailer
+     * @param TranslatorInterface $translator
+     * @param string              $senderEmail
+     * @param string              $senderName
+     * @param string              $supportUrl
      */
-    public function __construct(\Swift_Mailer $mailer, DataCollectorTranslator $translator, $senderEmail, $senderName, $supportUrl)
+    public function __construct(\Swift_Mailer $mailer, TranslatorInterface $translator, $senderEmail, $senderName, $supportUrl)
     {
         $this->mailer = $mailer;
         $this->translator = $translator;
index 9122576a3a5ebd7d65a60dea2b5ca8bdbe9993c5..61e960f9cdefe4b179b0635ea2b35974c4b22172 100644 (file)
@@ -6,7 +6,6 @@ use Wallabag\UserBundle\Entity\User;
 use Wallabag\UserBundle\Mailer\AuthCodeMailer;
 use Symfony\Component\Translation\Translator;
 use Symfony\Component\Translation\Loader\ArrayLoader;
-use Symfony\Component\Translation\DataCollectorTranslator;
 
 /**
  * @see https://www.pmg.com/blog/integration-testing-swift-mailer/
@@ -28,7 +27,7 @@ class AuthCodeMailerTest extends \PHPUnit_Framework_TestCase
 {
     protected $mailer;
     protected $spool;
-    protected $dataCollector;
+    protected $translator;
 
     protected function setUp()
     {
@@ -39,14 +38,12 @@ class AuthCodeMailerTest extends \PHPUnit_Framework_TestCase
         );
         $this->mailer = new \Swift_Mailer($transport);
 
-        $translator = new Translator('en');
-        $translator->addLoader('array', new ArrayLoader());
-        $translator->addResource('array', array(
+        $this->translator = new Translator('en');
+        $this->translator->addLoader('array', new ArrayLoader());
+        $this->translator->addResource('array', array(
             'auth_code.mailer.subject' => 'auth_code subject',
             'auth_code.mailer.body' => 'Hi %user%, here is the code: %code% and the support: %support%',
         ), 'en', 'wallabag_user');
-
-        $this->dataCollector = new DataCollectorTranslator($translator);
     }
 
     public function testSendEmail()
@@ -59,7 +56,7 @@ class AuthCodeMailerTest extends \PHPUnit_Framework_TestCase
 
         $authCodeMailer = new AuthCodeMailer(
             $this->mailer,
-            $this->dataCollector,
+            $this->translator,
             'nobody@test.io',
             'wallabag test',
             'http://0.0.0.0'