Permalink
Browse files

OXDEV-1580 Distinguish EE functionality to EE repo

  • Loading branch information...
MantasVaitkunas committed Oct 10, 2018
1 parent 8e3548b commit e0a520e9876c0f0f8a77fd04d9f7f99d1149302d
@@ -9,8 +9,6 @@
use OxidEsales\Eshop\Core\MailValidator;
use OxidEsales\Eshop\Core\Module\ModuleList;
use OxidEsales\Eshop\Core\Registry;
use OxidEsales\EshopCommunity\Internal\Console\ShopSwitchException;
use OxidEsales\Facts\Facts;
/**
* @internal
@@ -49,42 +47,4 @@ public function getModules()
return $moduleList->getList();
}
/**
* Switch to subshop by defined ID.
*
* @param int $shopId
* @throws ShopSwitchException
*/
public function switchToShop(int $shopId)
{
if ((new Facts())->isEnterprise()) {
$_POST['shp'] = $shopId;
$_POST['actshop'] = $shopId;
$keepThese = [\OxidEsales\Eshop\Core\ConfigFile::class, 'logger'];
$registryKeys = Registry::getKeys();
foreach ($registryKeys as $key) {
if (in_array($key, $keepThese)) {
continue;
}
Registry::set($key, null);
}
$utilsObject = new \OxidEsales\Eshop\Core\UtilsObject;
$utilsObject->resetInstanceCache();
Registry::set(\OxidEsales\Eshop\Core\UtilsObject::class, $utilsObject);
\OxidEsales\Eshop\Core\Module\ModuleVariablesLocator::resetModuleVariables();
Registry::getSession()->setVariable('shp', $shopId);
// Ensure we get rid of all instances of config, even the one in Core\Base
Registry::set(\OxidEsales\Eshop\Core\Config::class, null);
Registry::getConfig()->setConfig(null);
Registry::set(\OxidEsales\Eshop\Core\Config::class, null);
$moduleVariablesCache = new \OxidEsales\Eshop\Core\FileCache();
$shopIdCalculator = new \OxidEsales\Eshop\Core\ShopIdCalculator($moduleVariablesCache);
if (($shopId !== $shopIdCalculator->getShopId()) ||
($shopId !== Registry::getConfig()->getShopId())) {
throw new ShopSwitchException('Failed to switch to subshop with id - ' . $shopId . '.'
. ' Does this subshop exists?');
}
}
}
}
@@ -6,8 +6,6 @@
namespace OxidEsales\EshopCommunity\Internal\Adapter;
use OxidEsales\EshopCommunity\Internal\Console\ShopSwitchException;
/**
* @internal
*/
@@ -29,11 +27,4 @@ public function translateString($string);
* @return array
*/
public function getModules();
/**
* Switch active shop.
* @throws ShopSwitchException
* @param int $shopId
*/
public function switchToShop(int $shopId);
}

This file was deleted.

Oops, something went wrong.
@@ -30,59 +30,26 @@ class Executor implements ExecutorInterface
*/
private $commandsCollectionBuilder;
/**
* @var ConsoleOutput
*/
private $consoleOutput;
/**
* @var ShopAdapterInterface
*/
private $shopAdapter;
/**
* @param Application $application
* @param ConsoleOutputInterface $consoleOutput
* @param CommandsCollectionBuilder $commandsCollectionBuilder
* @param ShopAdapterInterface $shopAdapter
*/
public function __construct(
Application $application,
ConsoleOutputInterface $consoleOutput,
CommandsCollectionBuilder $commandsCollectionBuilder,
ShopAdapterInterface $shopAdapter
CommandsCollectionBuilder $commandsCollectionBuilder
) {
$this->application = $application;
$this->consoleOutput = $consoleOutput;
$this->commandsCollectionBuilder = $commandsCollectionBuilder;
$this->shopAdapter = $shopAdapter;
}
/**
* @inheritdoc
*/
public function execute(InputInterface $input = null, OutputInterface $output = null)
{
if (null === $input) {
$input = new ArgvInput();
}
if (null === $output) {
$output = new ConsoleOutput();
}
$shopId = (int) $input->getParameterOption('--shop-id', 1);
$shopId = $shopId === 0 ? 1 : $shopId;
try {
$this->shopAdapter->switchToShop($shopId);
foreach ($this->commandsCollectionBuilder->build()->toArray() as $command) {
$this->application->add($command);
}
$this->application->run($input, $output);
} catch (ShopSwitchException $shopSwitchException) {
$output->writeln('<error>'.$shopSwitchException->getMessage().'</error>');
if ($this->application->isAutoExitEnabled()) {
exit(1);
}
foreach ($this->commandsCollectionBuilder->build()->toArray() as $command) {
$this->application->add($command);
}
$this->application->run($input, $output);
}
}

This file was deleted.

Oops, something went wrong.
@@ -4,17 +4,12 @@ services:
public: true
arguments:
- '@symfony.component.console.application'
- '@Symfony\Component\Console\Output\ConsoleOutputInterface'
- '@console.commands_collection_builder'
- '@OxidEsales\EshopCommunity\Internal\Adapter\ShopAdapterInterface'
symfony.component.console.application:
class: Symfony\Component\Console\Application
public: false
calls:
- method: setDispatcher
arguments:
- '@event_dispatcher'
- method: setCommandLoader
arguments:
- '@console.command_loader'
@@ -65,9 +60,3 @@ services:
symfony.component.console.input.argv_input:
class: Symfony\Component\Console\Input\ArgvInput
public: false
console.command_event_subscriber:
class: OxidEsales\EshopCommunity\Internal\Console\CommandEventSubscriber
public: false
tags:
- { name: kernel.event_subscriber }
@@ -8,9 +8,7 @@
use OxidEsales\EshopCommunity\Internal\Console\CommandsCollectionBuilder;
use OxidEsales\EshopCommunity\Internal\Console\Executor;
use OxidEsales\EshopCommunity\Internal\Adapter\ShopAdapter;
use Symfony\Component\Console\Application;
use Symfony\Component\Console\Output\ConsoleOutput;
use Symfony\Component\Console\Output\StreamOutput;
/**
@@ -19,12 +17,14 @@
trait ConsoleTrait
{
/**
* @param $commandsCollectionBuilder
* @param Application $application
* @param CommandsCollectionBuilder $commandsCollectionBuilder
* @param $input
* @return string
*/
protected function execute(CommandsCollectionBuilder $commandsCollectionBuilder, $input): string
protected function execute(Application $application, CommandsCollectionBuilder $commandsCollectionBuilder, $input): string
{
$executor = new Executor($this->getConsoleApplication(), new ConsoleOutput(), $commandsCollectionBuilder, new ShopAdapter());
$executor = new Executor($application, $commandsCollectionBuilder);
$output = new StreamOutput(fopen('php://memory', 'w', false));
$executor->execute($input, $output);
@@ -34,14 +34,4 @@ protected function execute(CommandsCollectionBuilder $commandsCollectionBuilder,
return $display;
}
/**
* @return object
*/
private function getConsoleApplication(): Application
{
$application = $this->get('symfony.component.console.application');
$application->setAutoExit(false);
return $application;
}
}
@@ -26,22 +26,16 @@ class ExecutorTest extends TestCase
use ConsoleTrait;
use ContainerTrait;
public function testIfShopIdInGlobalOptionsList()
{
$consoleOutput = $this->execute(
new CommandsCollectionBuilder(),
new ArrayInput(['command' => 'list'])
);
$this->assertRegexp('/--shop-id/', $consoleOutput);
}
public function testIfRegisteredCommandInList()
{
$commands = $this->getMockBuilder(CommandsProvidableInterface::class)->getMock();
$commands->method('getCommands')->willReturn([new TestCommand()]);
$commandsCollectionBuilder = new CommandsCollectionBuilder($commands);
$consoleOutput = $this->execute($commandsCollectionBuilder, new ArrayInput(['command' => 'list']));
$consoleOutput = $this->execute(
$this->getApplication(),
$commandsCollectionBuilder,
new ArrayInput(['command' => 'list'])
);
$this->assertRegexp('/oe:tests:test-command/', $consoleOutput);
}
@@ -52,10 +46,22 @@ public function testCommandExecution()
$commands->method('getCommands')->willReturn([new TestCommand()]);
$commandsCollectionBuilder = new CommandsCollectionBuilder($commands);
$consoleOutput = $this->execute(
$this->getApplication(),
$commandsCollectionBuilder,
new ArrayInput(['command' => 'oe:tests:test-command'])
);
$this->assertSame('Command have been executed!'.PHP_EOL, $consoleOutput);
}
/**
* @return Application
*/
private function getApplication(): Application
{
$application = $this->get('symfony.component.console.application');
$application->setAutoExit(false);
return $application;
}
}
@@ -18,6 +18,7 @@ public function testModuleActivation()
$moduleId = 'testmodule';
$consoleOutput = $this->execute(
$this->getApplication(),
$this->get('console.commands_collection_builder'),
new ArrayInput(['command' => 'oe:module:activate', 'module-id' => $moduleId])
);
@@ -37,6 +38,7 @@ public function testWhenModuleAlreadyActive()
$moduleId = 'testmodule';
$consoleOutput = $this->execute(
$this->getApplication(),
$this->get('console.commands_collection_builder'),
new ArrayInput(['command' => 'oe:module:activate', 'module-id' => $moduleId])
);
@@ -50,6 +52,7 @@ public function testNonExistingModuleActivation()
{
$moduleId = 'test';
$consoleOutput = $this->execute(
$this->getApplication(),
$this->get('console.commands_collection_builder'),
new ArrayInput(['command' => 'oe:module:activate', 'module-id' => $moduleId])
);

0 comments on commit e0a520e

Please sign in to comment.