use current module setting service
Cette révision appartient à :
Parent
4cfcfb6d44
révision
f730a380ec
@ -17,6 +17,7 @@ namespace D3\DataWizard\Application\Model;
|
||||
|
||||
use D3\DataWizard\Application\Model\Exceptions\InputUnvalidException;
|
||||
use D3\DataWizard\Application\Model\Exceptions\TaskException;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use Doctrine\DBAL\Exception as DBALException;
|
||||
use FormManager\Inputs\Checkbox;
|
||||
use FormManager\Inputs\Input;
|
||||
@ -88,8 +89,7 @@ abstract class ActionBase implements QueryBase
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
$connection = ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get();
|
||||
$affected = (int) $connection->executeStatement($queryString, $parameters);
|
||||
$affected = (int) $this->getConnection()->executeStatement($queryString, $parameters);
|
||||
|
||||
/** @var TaskException $exception */
|
||||
$exception = oxNew(
|
||||
@ -105,6 +105,11 @@ abstract class ActionBase implements QueryBase
|
||||
throw $exception;
|
||||
}
|
||||
|
||||
protected function getConnection(): Connection
|
||||
{
|
||||
return ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
@ -17,16 +17,19 @@ namespace D3\DataWizard\tests\unit\Application\Controller\Admin;
|
||||
|
||||
use D3\DataWizard\Application\Controller\Admin\d3ActionWizard;
|
||||
use D3\DataWizard\Application\Model\Configuration;
|
||||
use D3\DataWizard\Application\Model\Constants;
|
||||
use D3\DataWizard\Application\Model\Exceptions\DataWizardException;
|
||||
use D3\DataWizard\Application\Model\Exceptions\DebugException;
|
||||
use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge;
|
||||
use D3\DataWizard\tests\tools\d3TestAction;
|
||||
use OxidEsales\Eshop\Core\Config;
|
||||
use Doctrine\DBAL\Exception as DBALException;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Request;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingService;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3ActionWizardTest extends d3AdminControllerTest
|
||||
class d3ActionWizardTest extends d3AdminController
|
||||
{
|
||||
/** @var d3ActionWizard */
|
||||
protected $_oController;
|
||||
@ -118,26 +121,21 @@ class d3ActionWizardTest extends d3AdminControllerTest
|
||||
$requestMock->expects($this->any())->method('getRequestEscapedParameter')->willReturnCallback([$this, 'executePassRequestCallback']);
|
||||
Registry::set(Request::class, $requestMock);
|
||||
|
||||
/** @var Config|MockObject $configMock */
|
||||
$configMock = $this->getMockBuilder(Config::class)
|
||||
->onlyMethods(['getConfigParam'])
|
||||
/** @var ModuleSettingService $settingsServiceMock */
|
||||
$settingsServiceMock = $this->getMockBuilder(ModuleSettingService::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['getBoolean'])
|
||||
->getMock();
|
||||
$configMock->expects($this->atLeastOnce())->method('getConfigParam')->willReturnCallback(
|
||||
function ($argName) use ($blDebug) {
|
||||
switch ($argName) {
|
||||
case 'd3datawizard_debug':
|
||||
return $blDebug;
|
||||
default:
|
||||
return Registry::getConfig()->getConfigParam($argName);
|
||||
}
|
||||
}
|
||||
);
|
||||
$settingsServiceMock->expects($this->once())->method('getBoolean')->with(
|
||||
$this->identicalTo('d3datawizard_debug'),
|
||||
$this->identicalTo(Constants::OXID_MODULE_ID)
|
||||
)->willReturn($blDebug);
|
||||
|
||||
/** @var d3ActionWizard|MockObject $controllerMock */
|
||||
$controllerMock = $this->getMockBuilder(d3ActionWizard::class)
|
||||
->onlyMethods(['d3GetConfig'])
|
||||
->onlyMethods(['getSettingsService'])
|
||||
->getMock();
|
||||
$controllerMock->method('d3GetConfig')->willReturn($configMock);
|
||||
$controllerMock->method('getSettingsService')->willReturn($settingsServiceMock);
|
||||
$this->_oController = $controllerMock;
|
||||
|
||||
/** @var d3TestAction|MockObject $actionMock */
|
||||
@ -148,7 +146,7 @@ class d3ActionWizardTest extends d3AdminControllerTest
|
||||
])
|
||||
->getMock();
|
||||
$actionMock->expects($this->atLeastOnce())->method('getQuery')->willReturn(['SELECT 1', ['1']]);
|
||||
$actionMock->expects($this->exactly((int) !$blDebug))->method('run')->willReturn(true);
|
||||
$actionMock->expects($this->exactly((int) !$blDebug))->method('run');
|
||||
|
||||
/** @var Configuration|MockObject $configurationMock */
|
||||
$configurationMock = $this->getMockBuilder(Configuration::class)
|
||||
@ -170,14 +168,11 @@ class d3ActionWizardTest extends d3AdminControllerTest
|
||||
|
||||
public function executePassRequestCallback($varName)
|
||||
{
|
||||
switch ($varName) {
|
||||
case 'taskid':
|
||||
return 'testTaskId';
|
||||
case 'format':
|
||||
return RendererBridge::FORMAT_CSV;
|
||||
default:
|
||||
return oxNew(Request::class)->getRequestEscapedParameter($varName);
|
||||
}
|
||||
return match ( $varName ) {
|
||||
'taskid' => 'testTaskId',
|
||||
'format' => RendererBridge::FORMAT_CSV,
|
||||
default => oxNew( Request::class )->getRequestEscapedParameter( $varName ),
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
@ -190,4 +185,15 @@ class d3ActionWizardTest extends d3AdminControllerTest
|
||||
'debug' => [true],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
*/
|
||||
public function runTaskFailedDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[DataWizardException::class],
|
||||
[DBALException::class],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -23,16 +23,18 @@ use D3\DataWizard\Application\Model\Exceptions\DebugException;
|
||||
use D3\DataWizard\tests\tools\d3TestAction;
|
||||
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
|
||||
use Doctrine\DBAL\Exception as DBALException;
|
||||
use Exception;
|
||||
use OxidEsales\Eshop\Core\Config;
|
||||
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Request;
|
||||
use OxidEsales\Eshop\Core\UtilsView;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingService;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use Psr\Log\LoggerInterface;
|
||||
use ReflectionException;
|
||||
|
||||
abstract class d3AdminControllerTest extends d3ModCfgUnitTestCase
|
||||
abstract class d3AdminController extends d3ModCfgUnitTestCase
|
||||
{
|
||||
/** @var d3ActionWizard|d3ExportWizard */
|
||||
protected $_oController;
|
||||
@ -54,7 +56,7 @@ abstract class d3AdminControllerTest extends d3ModCfgUnitTestCase
|
||||
*/
|
||||
public function testConstructor()
|
||||
{
|
||||
$this->setValue($this->_oController, 'configuration', null);
|
||||
$this->setValue($this->_oController, 'configuration', oxNew(Configuration::class));
|
||||
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
@ -82,7 +84,7 @@ abstract class d3AdminControllerTest extends d3ModCfgUnitTestCase
|
||||
$controllerMock = $this->getMockBuilder($this->testClassName)
|
||||
->onlyMethods(['execute'])
|
||||
->getMock();
|
||||
$controllerMock->expects($this->once())->method('execute')->willReturn(true);
|
||||
$controllerMock->expects($this->once())->method('execute');
|
||||
|
||||
$this->_oController = $controllerMock;
|
||||
|
||||
@ -104,9 +106,8 @@ abstract class d3AdminControllerTest extends d3ModCfgUnitTestCase
|
||||
{
|
||||
/** @var DataWizardException|DBALException|DatabaseErrorException|MockObject $exceptionMock */
|
||||
$exceptionMock = $this->getMockBuilder($exceptionClass)
|
||||
->disableOriginalConstructor()
|
||||
->setConstructorArgs(['exc_msg', 20, new Exception()])
|
||||
->getMock();
|
||||
$this->setValue($exceptionMock, 'message', 'exc_msg');
|
||||
|
||||
/** @var d3ActionWizard|d3ExportWizard|MockObject $controllerMock */
|
||||
$controllerMock = $this->getMockBuilder($this->testClassName)
|
||||
@ -137,18 +138,6 @@ abstract class d3AdminControllerTest extends d3ModCfgUnitTestCase
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return \string[][]
|
||||
*/
|
||||
public function runTaskFailedDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[DataWizardException::class],
|
||||
[DBALException::class],
|
||||
[DatabaseErrorException::class],
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::execute()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::execute()
|
||||
@ -244,18 +233,19 @@ abstract class d3AdminControllerTest extends d3ModCfgUnitTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::d3GetConfig
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::d3GetConfig
|
||||
* @test
|
||||
* @return void
|
||||
* @throws ReflectionException
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ActionWizard::getSettingsService()
|
||||
* @covers \D3\DataWizard\Application\Controller\Admin\d3ExportWizard::getSettingsService()
|
||||
*/
|
||||
public function canGetConfig()
|
||||
public function canGetSettingsService(): void
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Config::class,
|
||||
ModuleSettingService::class,
|
||||
$this->callMethod(
|
||||
$this->_oController,
|
||||
'd3GetConfig'
|
||||
'getSettingsService'
|
||||
)
|
||||
);
|
||||
}
|
@ -17,17 +17,22 @@ namespace D3\DataWizard\tests\unit\Application\Controller\Admin;
|
||||
|
||||
use D3\DataWizard\Application\Controller\Admin\d3ExportWizard;
|
||||
use D3\DataWizard\Application\Model\Configuration;
|
||||
use D3\DataWizard\Application\Model\Constants;
|
||||
use D3\DataWizard\Application\Model\Exceptions\DataWizardException;
|
||||
use D3\DataWizard\Application\Model\Exceptions\DebugException;
|
||||
use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge;
|
||||
use D3\DataWizard\tests\tools\d3TestAction;
|
||||
use D3\DataWizard\tests\tools\d3TestExport;
|
||||
use Doctrine\DBAL\Exception as DBALException;
|
||||
use OxidEsales\Eshop\Core\Config;
|
||||
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
|
||||
use OxidEsales\Eshop\Core\Registry;
|
||||
use OxidEsales\Eshop\Core\Request;
|
||||
use OxidEsales\EshopCommunity\Internal\Framework\Module\Facade\ModuleSettingService;
|
||||
use PHPUnit\Framework\MockObject\MockObject;
|
||||
use ReflectionException;
|
||||
|
||||
class d3ExportWizardTest extends d3AdminControllerTest
|
||||
class d3ExportWizardTest extends d3AdminController
|
||||
{
|
||||
/** @var d3ExportWizard */
|
||||
protected $_oController;
|
||||
@ -120,26 +125,21 @@ class d3ExportWizardTest extends d3AdminControllerTest
|
||||
//OnConsecutiveCalls('testTaskId', 'CSV');
|
||||
Registry::set(Request::class, $requestMock);
|
||||
|
||||
/** @var Config|MockObject $configMock */
|
||||
$configMock = $this->getMockBuilder(Config::class)
|
||||
->onlyMethods(['getConfigParam'])
|
||||
/** @var ModuleSettingService $settingsServiceMock */
|
||||
$settingsServiceMock = $this->getMockBuilder(ModuleSettingService::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['getBoolean'])
|
||||
->getMock();
|
||||
$configMock->expects($this->atLeastOnce())->method('getConfigParam')->willReturnCallback(
|
||||
function ($argName) use ($blDebug) {
|
||||
switch ($argName) {
|
||||
case 'd3datawizard_debug':
|
||||
return $blDebug;
|
||||
default:
|
||||
return Registry::getConfig()->getConfigParam($argName);
|
||||
}
|
||||
}
|
||||
);
|
||||
$settingsServiceMock->expects($this->once())->method('getBoolean')->with(
|
||||
$this->identicalTo('d3datawizard_debug'),
|
||||
$this->identicalTo(Constants::OXID_MODULE_ID)
|
||||
)->willReturn($blDebug);
|
||||
|
||||
/** @var d3ExportWizard|MockObject $controllerMock */
|
||||
$controllerMock = $this->getMockBuilder(d3ExportWizard::class)
|
||||
->onlyMethods(['d3GetConfig'])
|
||||
->onlyMethods(['getSettingsService'])
|
||||
->getMock();
|
||||
$controllerMock->method('d3GetConfig')->willReturn($configMock);
|
||||
$controllerMock->method('getSettingsService')->willReturn($settingsServiceMock);
|
||||
$this->_oController = $controllerMock;
|
||||
|
||||
/** @var d3TestAction|MockObject $exportMock */
|
||||
@ -192,4 +192,18 @@ class d3ExportWizardTest extends d3AdminControllerTest
|
||||
'debug' => [true],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @return string[][]
|
||||
*/
|
||||
public function runTaskFailedDataProvider(): array
|
||||
{
|
||||
return [
|
||||
[DataWizardException::class],
|
||||
[DBALException::class],
|
||||
[DatabaseErrorException::class],
|
||||
];
|
||||
}
|
||||
}
|
||||
|
@ -18,6 +18,7 @@ namespace D3\DataWizard\tests\unit\Application\Model;
|
||||
use D3\DataWizard\Application\Model\Exceptions\TaskException;
|
||||
use D3\DataWizard\tests\tools\d3TestAction;
|
||||
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
|
||||
use Doctrine\DBAL\Connection;
|
||||
use FormManager\Inputs\Hidden;
|
||||
use FormManager\Inputs\Number;
|
||||
use FormManager\Inputs\Radio;
|
||||
@ -258,17 +259,18 @@ class ActionBaseTest extends d3ModCfgUnitTestCase
|
||||
*/
|
||||
public function canExecuteAction($query, $throwsException)
|
||||
{
|
||||
/** @var Database|MockObject $dbMock */
|
||||
$dbMock = $this->getMockBuilder(Database::class)
|
||||
->onlyMethods(['execute'])
|
||||
/** @var Database|MockObject $connectionMock */
|
||||
$connectionMock = $this->getMockBuilder(Connection::class)
|
||||
->disableOriginalConstructor()
|
||||
->onlyMethods(['executeStatement'])
|
||||
->getMock();
|
||||
$dbMock->expects($this->exactly((int) !$throwsException))->method('execute')->willReturn(true);
|
||||
$connectionMock->expects($this->exactly((int) !$throwsException))->method('executeStatement')->willReturn(1);
|
||||
|
||||
/** @var d3TestAction|MockObject $modelMock */
|
||||
$modelMock = $this->getMockBuilder(d3TestAction::class)
|
||||
->onlyMethods(['d3GetDb'])
|
||||
->onlyMethods(['getConnection'])
|
||||
->getMock();
|
||||
$modelMock->expects($this->exactly((int) !$throwsException))->method('d3GetDb')->willReturn($dbMock);
|
||||
$modelMock->expects($this->exactly((int) !$throwsException))->method('getConnection')->willReturn($connectionMock);
|
||||
|
||||
$this->_oModel = $modelMock;
|
||||
|
||||
@ -299,17 +301,17 @@ class ActionBaseTest extends d3ModCfgUnitTestCase
|
||||
}
|
||||
|
||||
/**
|
||||
* @covers \D3\DataWizard\Application\Model\ActionBase::d3GetDb
|
||||
* @covers \D3\DataWizard\Application\Model\ActionBase::getConnection
|
||||
* @test
|
||||
* @throws ReflectionException
|
||||
*/
|
||||
public function canGetDb()
|
||||
public function canGetConnection()
|
||||
{
|
||||
$this->assertInstanceOf(
|
||||
Database::class,
|
||||
Connection::class,
|
||||
$this->callMethod(
|
||||
$this->_oModel,
|
||||
'd3GetDb'
|
||||
'getConnection'
|
||||
)
|
||||
);
|
||||
}
|
||||
|
Chargement…
Référencer dans un nouveau ticket
Block a user