Skip to content

Commit

Permalink
Use symfony yaml loader instead of PrestaShop module loader because t…
Browse files Browse the repository at this point in the history
…he resolver is not correctly set wehn necessary
  • Loading branch information
jolelievre committed Jun 22, 2020
1 parent 350f935 commit ba29eb4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 13 deletions.
14 changes: 7 additions & 7 deletions src/Adapter/Module/Tab/ModuleTabRegister.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@
use PrestaShop\PrestaShop\Adapter\Module\Module;
use PrestaShopBundle\Entity\Repository\LangRepository;
use PrestaShopBundle\Entity\Repository\TabRepository;
use PrestaShopBundle\Routing\YamlModuleLoader;
use Psr\Log\LoggerInterface;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\Finder\Finder;
use Symfony\Component\Finder\SplFileInfo;
Expand Down Expand Up @@ -82,9 +82,9 @@ class ModuleTabRegister
private $languages;

/**
* @var YamlModuleLoader
* @var LoaderInterface
*/
private $moduleRoutingLoader;
private $routingConfigLoader;

/**
* @param TabRepository $tabRepository
Expand All @@ -93,7 +93,7 @@ class ModuleTabRegister
* @param TranslatorInterface $translator
* @param Filesystem $filesystem
* @param array $languages
* @param YamlModuleLoader $moduleRoutingLoader
* @param LoaderInterface $routingConfigLoader
*/
public function __construct(
TabRepository $tabRepository,
Expand All @@ -102,15 +102,15 @@ public function __construct(
TranslatorInterface $translator,
Filesystem $filesystem,
array $languages,
YamlModuleLoader $moduleRoutingLoader
LoaderInterface $routingConfigLoader
) {
$this->langRepository = $langRepository;
$this->tabRepository = $tabRepository;
$this->logger = $logger;
$this->translator = $translator;
$this->filesystem = $filesystem;
$this->languages = $languages;
$this->moduleRoutingLoader = $moduleRoutingLoader;
$this->routingConfigLoader = $routingConfigLoader;
}

/**
Expand Down Expand Up @@ -270,7 +270,7 @@ protected function getModuleControllersFromRouting(string $moduleName): array
}

$routingControllers = [];
$moduleRoutes = $this->moduleRoutingLoader->import($routingFile, 'module');
$moduleRoutes = $this->routingConfigLoader->import($routingFile, 'yaml');
foreach ($moduleRoutes->getIterator() as $route) {
$legacyController = $route->getDefault('_legacy_controller');
if (!empty($legacyController)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ services:
- "@translator"
- "@filesystem"
- "@=service('prestashop.adapter.legacy.context').getLanguages()"
- "@prestashop.bundle.routing.module_route_loader"
- "@routing.loader.yml"

prestashop.adapter.module.tab.unregister:
class: PrestaShop\PrestaShop\Adapter\Module\Tab\ModuleTabUnregister
Expand Down
11 changes: 6 additions & 5 deletions tests-legacy/Unit/Adapter/Module/Tab/ModuleTabRegisterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use LegacyTests\TestCase\UnitTestCase;
use PrestaShop\PrestaShop\Adapter\Module\Tab\ModuleTabRegister;
use PrestaShopBundle\Routing\YamlModuleLoader;
use Symfony\Component\Config\Loader\LoaderInterface;
use Symfony\Component\Filesystem\Filesystem;
use Symfony\Component\HttpFoundation\ParameterBag;
use Symfony\Component\Routing\Route;
Expand Down Expand Up @@ -154,7 +155,7 @@ protected function setUp()
$this->sfKernel->getContainer()->get('translator'),
$this->buildFilesystemMock(),
$this->languages,
$this->buildYamlModuleLoaderMock(),
$this->buildRoutingConfigLoaderMock(),
))
->getMock();
$this->tabRegister
Expand Down Expand Up @@ -186,15 +187,15 @@ protected function buildFilesystemMock()
return $filesystemMock;
}

protected function buildYamlModuleLoaderMock()
protected function buildRoutingConfigLoaderMock()
{
$moduleRoutingLoader = $this->getMockBuilder(YamlModuleLoader::class)
->setMethods(['import'])
$moduleRoutingLoader = $this->getMockBuilder(LoaderInterface::class)
->setMethods(['import', 'load', 'supports', 'getResolver', 'setResolver'])
->disableOriginalConstructor()
->getMock()
;

// We only need to mock the import method, it returns a RouteCollection, by default it returns a useless
// We only need to mock the import method, it returns a RouteCollection, by default the mock returns a useless
// Route object, but ONLY for the undeclared_symfony module it returns an additional one with the _legacy_controller
// option that will add an undeclared controller
$moduleRoutingLoader
Expand Down

0 comments on commit ba29eb4

Please sign in to comment.