diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 798e99d0c..bb6e3ac10 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -1,10 +1,5 @@ parameters: ignoreErrors: - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getId\\(\\)\\.$#" - count: 3 - path: src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php - - message: "#^Method Wallabag\\\\AnnotationBundle\\\\Controller\\\\WallabagAnnotationController\\:\\:postAnnotationAction\\(\\) should return Symfony\\\\Component\\\\HttpFoundation\\\\JsonResponse but returns Symfony\\\\Component\\\\Form\\\\FormInterface\\\\.$#" count: 1 @@ -15,71 +10,6 @@ parameters: count: 1 path: src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getConfig\\(\\)\\.$#" - count: 1 - path: src/Wallabag/ApiBundle/Controller/ConfigRestController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getId\\(\\)\\.$#" - count: 2 - path: src/Wallabag/ApiBundle/Controller/DeveloperController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getId\\(\\)\\.$#" - count: 8 - path: src/Wallabag/ApiBundle/Controller/EntryRestController.php - - - - message: "#^Cannot assign new offset to string\\.$#" - count: 2 - path: src/Wallabag/ApiBundle/Controller/EntryRestController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getId\\(\\)\\.$#" - count: 1 - path: src/Wallabag/ApiBundle/Controller/SearchRestController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getId\\(\\)\\.$#" - count: 7 - path: src/Wallabag/ApiBundle/Controller/TagRestController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getConfig\\(\\)\\.$#" - count: 1 - path: src/Wallabag/ApiBundle/Controller/TaggingRuleRestController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getConfig\\(\\)\\.$#" - count: 3 - path: src/Wallabag/CoreBundle/Controller/ConfigController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getId\\(\\)\\.$#" - count: 11 - path: src/Wallabag/CoreBundle/Controller/ConfigController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:setBackupCodes\\(\\)\\.$#" - count: 3 - path: src/Wallabag/CoreBundle/Controller/ConfigController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:setEmailTwoFactor\\(\\)\\.$#" - count: 3 - path: src/Wallabag/CoreBundle/Controller/ConfigController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:setGoogleAuthenticatorSecret\\(\\)\\.$#" - count: 3 - path: src/Wallabag/CoreBundle/Controller/ConfigController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:setPlainPassword\\(\\)\\.$#" - count: 1 - path: src/Wallabag/CoreBundle/Controller/ConfigController.php - - message: "#^Call to an undefined method Wallabag\\\\CoreBundle\\\\Entity\\\\RuleInterface\\:\\:getConfig\\(\\)\\.$#" count: 1 @@ -90,26 +20,6 @@ parameters: count: 6 path: src/Wallabag/CoreBundle/Controller/ConfigController.php - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getId\\(\\)\\.$#" - count: 12 - path: src/Wallabag/CoreBundle/Controller/EntryController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getId\\(\\)\\.$#" - count: 6 - path: src/Wallabag/CoreBundle/Controller/ExportController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getId\\(\\)\\.$#" - count: 1 - path: src/Wallabag/CoreBundle/Controller/SiteCredentialController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getId\\(\\)\\.$#" - count: 8 - path: src/Wallabag/CoreBundle/Controller/TagController.php - - message: "#^Call to an undefined method Spiriit\\\\Bundle\\\\FormFilterBundle\\\\Filter\\\\Query\\\\QueryInterface\\:\\:getExpressionBuilder\\(\\)\\.$#" count: 1 @@ -120,16 +30,6 @@ parameters: count: 10 path: src/Wallabag/CoreBundle/Form/Type/EntryFilterType.php - - - message: "#^Call to an undefined method DOMNode\\:\\:getAttribute\\(\\)\\.$#" - count: 1 - path: src/Wallabag/CoreBundle/Helper/DownloadImages.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getId\\(\\)\\.$#" - count: 1 - path: src/Wallabag/ImportBundle/Controller/BrowserController.php - - message: "#^Call to an undefined method Wallabag\\\\ImportBundle\\\\Import\\\\ImportInterface\\:\\:setFilepath\\(\\)\\.$#" count: 1 @@ -140,16 +40,6 @@ parameters: count: 1 path: src/Wallabag/ImportBundle/Controller/BrowserController.php - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getId\\(\\)\\.$#" - count: 1 - path: src/Wallabag/ImportBundle/Controller/DeliciousController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getId\\(\\)\\.$#" - count: 1 - path: src/Wallabag/ImportBundle/Controller/HtmlController.php - - message: "#^Call to an undefined method Wallabag\\\\ImportBundle\\\\Import\\\\ImportInterface\\:\\:setFilepath\\(\\)\\.$#" count: 1 @@ -160,31 +50,6 @@ parameters: count: 1 path: src/Wallabag/ImportBundle/Controller/HtmlController.php - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getId\\(\\)\\.$#" - count: 1 - path: src/Wallabag/ImportBundle/Controller/InstapaperController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getId\\(\\)\\.$#" - count: 1 - path: src/Wallabag/ImportBundle/Controller/PinboardController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getConfig\\(\\)\\.$#" - count: 1 - path: src/Wallabag/ImportBundle/Controller/PocketController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getId\\(\\)\\.$#" - count: 1 - path: src/Wallabag/ImportBundle/Controller/ReadabilityController.php - - - - message: "#^Call to an undefined method Symfony\\\\Component\\\\Security\\\\Core\\\\User\\\\UserInterface\\:\\:getId\\(\\)\\.$#" - count: 1 - path: src/Wallabag/ImportBundle/Controller/WallabagController.php - - message: "#^Call to an undefined method Wallabag\\\\ImportBundle\\\\Import\\\\ImportInterface\\:\\:setFilepath\\(\\)\\.$#" count: 1 diff --git a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php index 704cc9a90..e5ffc6fdf 100644 --- a/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php +++ b/src/Wallabag/AnnotationBundle/Controller/WallabagAnnotationController.php @@ -15,6 +15,7 @@ use Wallabag\AnnotationBundle\Form\EditAnnotationType; use Wallabag\AnnotationBundle\Form\NewAnnotationType; use Wallabag\AnnotationBundle\Repository\AnnotationRepository; use Wallabag\CoreBundle\Entity\Entry; +use Wallabag\UserBundle\Entity\User; class WallabagAnnotationController extends AbstractFOSRestController { @@ -146,6 +147,17 @@ class WallabagAnnotationController extends AbstractFOSRestController } } + /** + * @return User|null + */ + protected function getUser() + { + $user = parent::getUser(); + \assert(null === $user || $user instanceof User); + + return $user; + } + private function validateAnnotation(AnnotationRepository $annotationRepository, int $annotationId, int $userId) { $annotation = $annotationRepository->findOneByIdAndUserId($annotationId, $userId); diff --git a/src/Wallabag/ApiBundle/Controller/DeveloperController.php b/src/Wallabag/ApiBundle/Controller/DeveloperController.php index 5c920e5bd..48a163d21 100644 --- a/src/Wallabag/ApiBundle/Controller/DeveloperController.php +++ b/src/Wallabag/ApiBundle/Controller/DeveloperController.php @@ -3,7 +3,6 @@ namespace Wallabag\ApiBundle\Controller; use Doctrine\ORM\EntityManagerInterface; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; @@ -12,6 +11,7 @@ use Symfony\Contracts\Translation\TranslatorInterface; use Wallabag\ApiBundle\Entity\Client; use Wallabag\ApiBundle\Form\Type\ClientType; use Wallabag\ApiBundle\Repository\ClientRepository; +use Wallabag\CoreBundle\Controller\AbstractController; class DeveloperController extends AbstractController { diff --git a/src/Wallabag/ApiBundle/Controller/EntryRestController.php b/src/Wallabag/ApiBundle/Controller/EntryRestController.php index 609085c1f..a69978591 100644 --- a/src/Wallabag/ApiBundle/Controller/EntryRestController.php +++ b/src/Wallabag/ApiBundle/Controller/EntryRestController.php @@ -93,13 +93,13 @@ class EntryRestController extends WallabagRestController $returnId = (null === $request->query->get('return_id')) ? false : (bool) $request->query->get('return_id'); - $hashedUrls = $request->query->get('hashed_urls', []); + $hashedUrls = $request->query->all('hashed_urls'); $hashedUrl = $request->query->get('hashed_url', ''); if (!empty($hashedUrl)) { $hashedUrls[] = $hashedUrl; } - $urls = $request->query->get('urls', []); + $urls = $request->query->all('urls'); $url = $request->query->get('url', ''); if (!empty($url)) { $urls[] = $url; diff --git a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php index de504db7d..c0ff32bdf 100644 --- a/src/Wallabag/ApiBundle/Controller/WallabagRestController.php +++ b/src/Wallabag/ApiBundle/Controller/WallabagRestController.php @@ -130,4 +130,15 @@ class WallabagRestController extends AbstractFOSRestController return (new JsonResponse())->setJson($json); } + + /** + * @return User|null + */ + protected function getUser() + { + $user = parent::getUser(); + \assert(null === $user || $user instanceof User); + + return $user; + } } diff --git a/src/Wallabag/CoreBundle/Controller/AbstractController.php b/src/Wallabag/CoreBundle/Controller/AbstractController.php new file mode 100644 index 000000000..fc12a93b3 --- /dev/null +++ b/src/Wallabag/CoreBundle/Controller/AbstractController.php @@ -0,0 +1,20 @@ +getIterator(); while ($iterator->valid()) { - $srcsetAttribute = $iterator->current()->getAttribute('srcset'); + $node = $iterator->current(); + \assert($node instanceof \DOMElement); + + $srcsetAttribute = $node->getAttribute('srcset'); if ('' !== $srcsetAttribute) { // Couldn't start with " OR ' OR a white space diff --git a/src/Wallabag/ImportBundle/Controller/BrowserController.php b/src/Wallabag/ImportBundle/Controller/BrowserController.php index 326ae7279..8658b6422 100644 --- a/src/Wallabag/ImportBundle/Controller/BrowserController.php +++ b/src/Wallabag/ImportBundle/Controller/BrowserController.php @@ -2,11 +2,11 @@ namespace Wallabag\ImportBundle\Controller; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Contracts\Translation\TranslatorInterface; +use Wallabag\CoreBundle\Controller\AbstractController; use Wallabag\ImportBundle\Form\Type\UploadImportType; use Wallabag\ImportBundle\Import\ImportInterface; diff --git a/src/Wallabag/ImportBundle/Controller/DeliciousController.php b/src/Wallabag/ImportBundle/Controller/DeliciousController.php index bed54498b..f1bccbd38 100644 --- a/src/Wallabag/ImportBundle/Controller/DeliciousController.php +++ b/src/Wallabag/ImportBundle/Controller/DeliciousController.php @@ -4,10 +4,10 @@ namespace Wallabag\ImportBundle\Controller; use Craue\ConfigBundle\Util\Config; use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; use Symfony\Contracts\Translation\TranslatorInterface; +use Wallabag\CoreBundle\Controller\AbstractController; use Wallabag\ImportBundle\Form\Type\UploadImportType; use Wallabag\ImportBundle\Import\DeliciousImport; use Wallabag\ImportBundle\Redis\Producer as RedisProducer; diff --git a/src/Wallabag/ImportBundle/Controller/HtmlController.php b/src/Wallabag/ImportBundle/Controller/HtmlController.php index e9515561f..2f3bd73e6 100644 --- a/src/Wallabag/ImportBundle/Controller/HtmlController.php +++ b/src/Wallabag/ImportBundle/Controller/HtmlController.php @@ -2,11 +2,11 @@ namespace Wallabag\ImportBundle\Controller; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Contracts\Translation\TranslatorInterface; +use Wallabag\CoreBundle\Controller\AbstractController; use Wallabag\ImportBundle\Form\Type\UploadImportType; use Wallabag\ImportBundle\Import\ImportInterface; diff --git a/src/Wallabag/ImportBundle/Controller/ImportController.php b/src/Wallabag/ImportBundle/Controller/ImportController.php index 55578df9f..afc57d690 100644 --- a/src/Wallabag/ImportBundle/Controller/ImportController.php +++ b/src/Wallabag/ImportBundle/Controller/ImportController.php @@ -4,9 +4,9 @@ namespace Wallabag\ImportBundle\Controller; use Craue\ConfigBundle\Util\Config; use Predis\Client; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Security\Core\Authorization\AuthorizationCheckerInterface; +use Wallabag\CoreBundle\Controller\AbstractController; use Wallabag\ImportBundle\Consumer\RabbitMQConsumerTotalProxy; use Wallabag\ImportBundle\Import\ImportChain; diff --git a/src/Wallabag/ImportBundle/Controller/InstapaperController.php b/src/Wallabag/ImportBundle/Controller/InstapaperController.php index 03d562916..852f206a8 100644 --- a/src/Wallabag/ImportBundle/Controller/InstapaperController.php +++ b/src/Wallabag/ImportBundle/Controller/InstapaperController.php @@ -4,10 +4,10 @@ namespace Wallabag\ImportBundle\Controller; use Craue\ConfigBundle\Util\Config; use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; use Symfony\Contracts\Translation\TranslatorInterface; +use Wallabag\CoreBundle\Controller\AbstractController; use Wallabag\ImportBundle\Form\Type\UploadImportType; use Wallabag\ImportBundle\Import\InstapaperImport; use Wallabag\ImportBundle\Redis\Producer as RedisProducer; diff --git a/src/Wallabag/ImportBundle/Controller/PinboardController.php b/src/Wallabag/ImportBundle/Controller/PinboardController.php index 6c81e8eb6..fe74675ca 100644 --- a/src/Wallabag/ImportBundle/Controller/PinboardController.php +++ b/src/Wallabag/ImportBundle/Controller/PinboardController.php @@ -4,10 +4,10 @@ namespace Wallabag\ImportBundle\Controller; use Craue\ConfigBundle\Util\Config; use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; use Symfony\Contracts\Translation\TranslatorInterface; +use Wallabag\CoreBundle\Controller\AbstractController; use Wallabag\ImportBundle\Form\Type\UploadImportType; use Wallabag\ImportBundle\Import\PinboardImport; use Wallabag\ImportBundle\Redis\Producer as RedisProducer; diff --git a/src/Wallabag/ImportBundle/Controller/PocketController.php b/src/Wallabag/ImportBundle/Controller/PocketController.php index 2ca509bc1..4a9f6fd87 100644 --- a/src/Wallabag/ImportBundle/Controller/PocketController.php +++ b/src/Wallabag/ImportBundle/Controller/PocketController.php @@ -4,13 +4,13 @@ namespace Wallabag\ImportBundle\Controller; use Craue\ConfigBundle\Util\Config; use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\Form\Extension\Core\Type\CheckboxType; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\Routing\Annotation\Route; use Symfony\Component\Routing\Generator\UrlGeneratorInterface; use Symfony\Contracts\Translation\TranslatorInterface; +use Wallabag\CoreBundle\Controller\AbstractController; use Wallabag\ImportBundle\Import\PocketImport; use Wallabag\ImportBundle\Redis\Producer as RedisProducer; diff --git a/src/Wallabag/ImportBundle/Controller/ReadabilityController.php b/src/Wallabag/ImportBundle/Controller/ReadabilityController.php index fb2c22262..bbdd8782e 100644 --- a/src/Wallabag/ImportBundle/Controller/ReadabilityController.php +++ b/src/Wallabag/ImportBundle/Controller/ReadabilityController.php @@ -4,10 +4,10 @@ namespace Wallabag\ImportBundle\Controller; use Craue\ConfigBundle\Util\Config; use OldSound\RabbitMqBundle\RabbitMq\Producer as RabbitMqProducer; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\Routing\Annotation\Route; use Symfony\Contracts\Translation\TranslatorInterface; +use Wallabag\CoreBundle\Controller\AbstractController; use Wallabag\ImportBundle\Form\Type\UploadImportType; use Wallabag\ImportBundle\Import\ReadabilityImport; use Wallabag\ImportBundle\Redis\Producer as RedisProducer; diff --git a/src/Wallabag/ImportBundle/Controller/WallabagController.php b/src/Wallabag/ImportBundle/Controller/WallabagController.php index fd22c8eec..b31af25ff 100644 --- a/src/Wallabag/ImportBundle/Controller/WallabagController.php +++ b/src/Wallabag/ImportBundle/Controller/WallabagController.php @@ -2,11 +2,11 @@ namespace Wallabag\ImportBundle\Controller; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\HttpFoundation\RedirectResponse; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Contracts\Translation\TranslatorInterface; +use Wallabag\CoreBundle\Controller\AbstractController; use Wallabag\ImportBundle\Form\Type\UploadImportType; use Wallabag\ImportBundle\Import\ImportInterface; diff --git a/src/Wallabag/UserBundle/Controller/ManageController.php b/src/Wallabag/UserBundle/Controller/ManageController.php index aadd0ca55..3665d842e 100644 --- a/src/Wallabag/UserBundle/Controller/ManageController.php +++ b/src/Wallabag/UserBundle/Controller/ManageController.php @@ -10,7 +10,6 @@ use Pagerfanta\Doctrine\ORM\QueryAdapter as DoctrineORMAdapter; use Pagerfanta\Exception\OutOfRangeCurrentPageException; use Pagerfanta\Pagerfanta; use Scheb\TwoFactorBundle\Security\TwoFactor\Provider\Google\GoogleAuthenticatorInterface; -use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Symfony\Component\Form\Form; use Symfony\Component\Form\FormInterface; @@ -18,6 +17,7 @@ use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpFoundation\Response; use Symfony\Component\Routing\Annotation\Route; use Symfony\Contracts\Translation\TranslatorInterface; +use Wallabag\CoreBundle\Controller\AbstractController; use Wallabag\UserBundle\Entity\User; use Wallabag\UserBundle\Form\NewUserType; use Wallabag\UserBundle\Form\SearchUserType; diff --git a/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php b/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php index 3bba785d9..aa28072b1 100644 --- a/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php +++ b/tests/Wallabag/AnnotationBundle/WallabagAnnotationTestCase.php @@ -4,12 +4,8 @@ namespace Tests\Wallabag\AnnotationBundle; use FOS\UserBundle\Model\UserInterface; use FOS\UserBundle\Model\UserManager; -use FOS\UserBundle\Security\LoginManager; use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; -use Symfony\Component\BrowserKit\Cookie; -use Symfony\Component\HttpFoundation\Session\SessionInterface; -use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; abstract class WallabagAnnotationTestCase extends WebTestCase { @@ -51,19 +47,11 @@ abstract class WallabagAnnotationTestCase extends WebTestCase /** @var UserManager $userManager */ $userManager = $container->get('fos_user.user_manager.test'); - /** @var LoginManager $loginManager */ - $loginManager = $container->get('fos_user.security.login_manager.test'); $firewallName = $container->getParameter('fos_user.firewall_name'); $this->user = $userManager->findUserBy(['username' => 'admin']); - $loginManager->logInUser($firewallName, $this->user); - // save the login token into the session and put it in a cookie - $container->get(SessionInterface::class)->set('_security_' . $firewallName, serialize($container->get(TokenStorageInterface::class)->getToken())); - $container->get(SessionInterface::class)->save(); - - $session = $container->get(SessionInterface::class); - $client->getCookieJar()->set(new Cookie($session->getName(), $session->getId())); + $client->loginUser($this->user, $firewallName); return $client; } diff --git a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php index 2dc3e9aed..53047001b 100644 --- a/tests/Wallabag/ApiBundle/WallabagApiTestCase.php +++ b/tests/Wallabag/ApiBundle/WallabagApiTestCase.php @@ -5,12 +5,8 @@ namespace Tests\Wallabag\ApiBundle; use Doctrine\ORM\EntityManagerInterface; use FOS\UserBundle\Model\UserInterface; use FOS\UserBundle\Model\UserManager; -use FOS\UserBundle\Security\LoginManager; use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; -use Symfony\Component\BrowserKit\Cookie; -use Symfony\Component\HttpFoundation\Session\SessionInterface; -use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Wallabag\UserBundle\Entity\User; abstract class WallabagApiTestCase extends WebTestCase @@ -51,19 +47,11 @@ abstract class WallabagApiTestCase extends WebTestCase /** @var UserManager $userManager */ $userManager = $container->get('fos_user.user_manager.test'); - /** @var LoginManager $loginManager */ - $loginManager = $container->get('fos_user.security.login_manager.test'); $firewallName = $container->getParameter('fos_user.firewall_name'); $this->user = $userManager->findUserBy(['username' => 'admin']); - $loginManager->logInUser($firewallName, $this->user); - // save the login token into the session and put it in a cookie - $container->get(SessionInterface::class)->set('_security_' . $firewallName, serialize($container->get(TokenStorageInterface::class)->getToken())); - $container->get(SessionInterface::class)->save(); - - $session = $container->get(SessionInterface::class); - $client->getCookieJar()->set(new Cookie($session->getName(), $session->getId())); + $client->loginUser($this->user, $firewallName); return $client; } diff --git a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php index 767b682df..a5654a83f 100644 --- a/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php +++ b/tests/Wallabag/CoreBundle/WallabagCoreTestCase.php @@ -6,10 +6,8 @@ use Doctrine\ORM\EntityManagerInterface; use Symfony\Bundle\FrameworkBundle\Console\Application; use Symfony\Bundle\FrameworkBundle\KernelBrowser; use Symfony\Bundle\FrameworkBundle\Test\WebTestCase; -use Symfony\Component\BrowserKit\Cookie; use Symfony\Component\Console\Input\ArrayInput; use Symfony\Component\Console\Output\NullOutput; -use Symfony\Component\HttpFoundation\Session\SessionInterface; use Symfony\Component\Security\Core\Authentication\Token\Storage\TokenStorageInterface; use Wallabag\UserBundle\Entity\User; @@ -88,10 +86,8 @@ abstract class WallabagCoreTestCase extends WebTestCase public function logInAs($username) { $container = $this->client->getContainer(); - $session = $container->get(SessionInterface::class); $userManager = $container->get('fos_user.user_manager.test'); - $loginManager = $container->get('fos_user.security.login_manager.test'); $firewallName = $container->getParameter('fos_user.firewall_name'); $user = $userManager->findUserBy(['username' => $username]); @@ -100,13 +96,7 @@ abstract class WallabagCoreTestCase extends WebTestCase throw new \Exception('Unable to find user "' . $username . '". Does fixtures were loaded?'); } - $loginManager->logInUser($firewallName, $user); - - $session->set('_security_' . $firewallName, serialize($container->get(TokenStorageInterface::class)->getToken())); - $session->save(); - - $cookie = new Cookie($session->getName(), $session->getId()); - $this->client->getCookieJar()->set($cookie); + $this->client->loginUser($user, $firewallName); } /**