11 Commits

29 changed files with 161 additions and 98 deletions

View File

@ -19,14 +19,11 @@ use D3\DataWizard\Application\Model\Configuration;
use D3\DataWizard\Application\Model\Exceptions\DataWizardException; use D3\DataWizard\Application\Model\Exceptions\DataWizardException;
use D3\DataWizard\Application\Model\Exceptions\DebugException; use D3\DataWizard\Application\Model\Exceptions\DebugException;
use D3\ModCfg\Application\Model\d3database; use D3\ModCfg\Application\Model\d3database;
use D3\ModCfg\Application\Model\Exception\d3_cfg_mod_exception;
use D3\ModCfg\Application\Model\Exception\d3ShopCompatibilityAdapterException;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController; use OxidEsales\Eshop\Application\Controller\Admin\AdminDetailsController;
use OxidEsales\Eshop\Core\Config; use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException; use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
use OxidEsales\Eshop\Core\Exception\StandardException;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
class d3ActionWizard extends AdminDetailsController class d3ActionWizard extends AdminDetailsController
@ -43,7 +40,7 @@ class d3ActionWizard extends AdminDetailsController
$this->configuration = oxNew(Configuration::class); $this->configuration = oxNew(Configuration::class);
} }
public function getGroups() public function getGroups(): array
{ {
return $this->configuration->getActionGroups(); return $this->configuration->getActionGroups();
} }
@ -55,9 +52,6 @@ class d3ActionWizard extends AdminDetailsController
/** /**
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
* @throws StandardException
* @throws d3ShopCompatibilityAdapterException
* @throws d3_cfg_mod_exception
*/ */
public function runTask() public function runTask()
{ {
@ -93,7 +87,7 @@ class d3ActionWizard extends AdminDetailsController
/** /**
* @return Config * @return Config
*/ */
public function d3GetConfig() public function d3GetConfig(): Config
{ {
return Registry::getConfig(); return Registry::getConfig();
} }

View File

@ -45,7 +45,7 @@ class d3ExportWizard extends AdminDetailsController
$this->configuration = oxNew(Configuration::class); $this->configuration = oxNew(Configuration::class);
} }
public function getGroups() public function getGroups(): array
{ {
return $this->configuration->getExportGroups(); return $this->configuration->getExportGroups();
} }
@ -101,7 +101,7 @@ class d3ExportWizard extends AdminDetailsController
/** /**
* @return Config * @return Config
*/ */
public function d3GetConfig() public function d3GetConfig(): Config
{ {
return Registry::getConfig(); return Registry::getConfig();
} }

View File

@ -95,7 +95,7 @@ abstract class ActionBase implements QueryBase
* @return DatabaseInterface|null * @return DatabaseInterface|null
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
*/ */
public function d3GetDb() public function d3GetDb(): ?DatabaseInterface
{ {
return DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC ); return DatabaseProvider::getDb( DatabaseProvider::FETCH_MODE_ASSOC );
} }

View File

@ -15,11 +15,7 @@ declare(strict_types=1);
namespace D3\DataWizard\Application\Model; namespace D3\DataWizard\Application\Model;
use D3\DataWizard\Application\Model\Actions\FixArtextendsItems;
use D3\DataWizard\Application\Model\Exceptions\DataWizardException; use D3\DataWizard\Application\Model\Exceptions\DataWizardException;
use D3\DataWizard\Application\Model\Exports\InactiveCategories;
use D3\DataWizard\Application\Model\Exports\KeyFigures;
use OxidEsales\Eshop\Core\Registry;
class Configuration class Configuration
{ {

View File

@ -25,6 +25,7 @@ use Doctrine\DBAL\DBALException;
use FormManager\Inputs\Checkbox; use FormManager\Inputs\Checkbox;
use FormManager\Inputs\Input; use FormManager\Inputs\Input;
use FormManager\Inputs\Radio; use FormManager\Inputs\Radio;
use OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface;
use OxidEsales\Eshop\Core\DatabaseProvider; use OxidEsales\Eshop\Core\DatabaseProvider;
use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException; use OxidEsales\Eshop\Core\Exception\DatabaseConnectionException;
use OxidEsales\Eshop\Core\Exception\DatabaseErrorException; use OxidEsales\Eshop\Core\Exception\DatabaseErrorException;
@ -94,7 +95,7 @@ abstract class ExportBase implements QueryBase
/** /**
* @return RendererBridge * @return RendererBridge
*/ */
public function getRendererBridge() public function getRendererBridge(): RendererBridge
{ {
return oxNew(RendererBridge::class); return oxNew(RendererBridge::class);
} }
@ -224,9 +225,7 @@ abstract class ExportBase implements QueryBase
*/ */
protected function executeExport(string $format, $path): string protected function executeExport(string $format, $path): string
{ {
[$rows, $fieldNames] = $this->getExportData($this->getQuery()); $content = $this->getContent( $format );
$content = $this->renderContent($rows, $fieldNames, $format);
/** @var $oFS d3filesystem */ /** @var $oFS d3filesystem */
$oFS = $this->getFileSystem(); $oFS = $this->getFileSystem();
@ -244,10 +243,10 @@ abstract class ExportBase implements QueryBase
} }
/** /**
* @return \OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface|null * @return DatabaseInterface|null
* @throws DatabaseConnectionException * @throws DatabaseConnectionException
*/ */
protected function d3GetDb(): ?\OxidEsales\Eshop\Core\Database\Adapter\DatabaseInterface protected function d3GetDb(): ?DatabaseInterface
{ {
return DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC); return DatabaseProvider::getDb(DatabaseProvider::FETCH_MODE_ASSOC);
} }
@ -259,4 +258,21 @@ abstract class ExportBase implements QueryBase
{ {
return oxNew(d3filesystem::class); return oxNew(d3filesystem::class);
} }
/**
* @param string $format
*
* @return string
* @throws DatabaseConnectionException
* @throws DatabaseErrorException
* @throws Exceptions\NoSuitableRendererException
*/
public function getContent( string $format ): string
{
[ $rows, $fieldNames ] = $this->getExportData( $this->getQuery() );
$content = $this->renderContent( $rows, $fieldNames, $format );
return $content;
}
} }

View File

@ -37,7 +37,7 @@ class Csv implements RendererInterface
$csv = $this->getCsv(); $csv = $this->getCsv();
$csv->insertOne( $fieldNames ); $csv->insertOne( $fieldNames );
$csv->insertAll( $rows ); $csv->insertAll( $rows );
return method_exists($csv, 'getContent') ? $csv->getContent() : (string) $csv; return (string) $csv;
} catch (Exception $e) { } catch (Exception $e) {
/** @var RenderException $newException */ /** @var RenderException $newException */
$newException = oxNew(RenderException::class, $e->getMessage(), $e->getCode(), $e ); $newException = oxNew(RenderException::class, $e->getMessage(), $e->getCode(), $e );
@ -86,7 +86,7 @@ class Csv implements RendererInterface
/** /**
* @return Config * @return Config
*/ */
public function d3GetConfig() public function d3GetConfig(): Config
{ {
return Registry::getConfig(); return Registry::getConfig();
} }

View File

@ -16,6 +16,7 @@ declare(strict_types=1);
namespace D3\DataWizard\Application\Model\ExportRenderer; namespace D3\DataWizard\Application\Model\ExportRenderer;
use D3\DataWizard\Application\Model\Exceptions\RenderException; use D3\DataWizard\Application\Model\Exceptions\RenderException;
use JsonException;
class Json implements RendererInterface class Json implements RendererInterface
{ {
@ -28,12 +29,15 @@ class Json implements RendererInterface
*/ */
public function getContent($rows, $fieldNames): string public function getContent($rows, $fieldNames): string
{ {
$flags = JSON_PRETTY_PRINT; try {
$flags = JSON_PRETTY_PRINT | JSON_THROW_ON_ERROR;
$json = json_encode( $rows, $flags ); $json = json_encode( $rows, $flags );
if ( $json === false ) {
throw oxNew( RenderException::class, json_last_error_msg(), json_last_error());
}
return $json; return $json;
} catch ( JsonException $e) {
/** @var RenderException $newException */
$newException = oxNew(RenderException::class, $e->getMessage(), $e->getCode(), $e );
throw $newException;
}
} }
public function getFileExtension(): string public function getFileExtension(): string

View File

@ -35,7 +35,7 @@ class Pretty implements RendererInterface
* @param $rows * @param $rows
* @return ArrayToTextTable * @return ArrayToTextTable
*/ */
public function getArrayToTextTableInstance($rows) public function getArrayToTextTableInstance($rows): ArrayToTextTable
{ {
return oxNew(ArrayToTextTable::class, $rows); return oxNew(ArrayToTextTable::class, $rows);
} }

View File

@ -35,7 +35,7 @@ class RendererBridge
]; ];
} }
public function getTranslatedRendererIdList() public function getTranslatedRendererIdList(): array
{ {
$rendererList = $this->getRendererList(); $rendererList = $this->getRendererList();
array_walk($rendererList, [$this, 'translateRendererId']); array_walk($rendererList, [$this, 'translateRendererId']);

View File

@ -1,5 +1,23 @@
# Changelog # Changelog
## 2.1.0.0 (2021-12-21)
#### Changed
- adjust to CLI extension which can export to STDOUT
---
## 2.0.0.0 (2021-12-20)
#### Added
- add tests
- make installable in OXID 6.4
#### Changed
- adjust code to PHP 7.3 and up
---
## 1.4.0.0 (2021-11-11) ## 1.4.0.0 (2021-11-11)
#### Added #### Added

View File

@ -18,7 +18,7 @@ Sample exports are included in the package d3/datawizardtasks. These are intende
In the console in the shop root (above source and vendor), execute the following command: In the console in the shop root (above source and vendor), execute the following command:
```bash ```bash
php composer require d3/datawizard php composer require d3/datawizard:^2.0
``` ```
Activate the module in the admin area of the shop in "Extensions -> Modules". Activate the module in the admin area of the shop in "Extensions -> Modules".

View File

@ -18,7 +18,7 @@ Im Paket d3/datawizardtasks sind Beispielexporte enthalten. Diese sollen als Imp
Auf der Konsole im Shoproot (oberhalb von source und vendor) folgenden Befehl ausfĂĽhren: Auf der Konsole im Shoproot (oberhalb von source und vendor) folgenden Befehl ausfĂĽhren:
```bash ```bash
php composer require d3/datawizard php composer require d3/datawizard:^2.0
``` ```
Aktivieren Sie das Modul im Shopadmin unter "Erweiterungen -> Module". Aktivieren Sie das Modul im Shopadmin unter "Erweiterungen -> Module".

View File

@ -25,14 +25,11 @@
"GPL-3.0-or-later" "GPL-3.0-or-later"
], ],
"require": { "require": {
"php": ">=7.1", "php": ">=7.3",
"oxid-esales/oxideshop-ce": "6.3 - 6.9", "oxid-esales/oxideshop-ce": "6.8 - 6.10",
"league/csv": "^9.0", "league/csv": "^9.0",
"mathieuviossat/arraytotexttable": "^1.0", "mathieuviossat/arraytotexttable": "^1.0",
"form-manager/form-manager": "^5.1 || ^6.1" "form-manager/form-manager": "^6.1"
},
"require-dev": {
"oxid-esales/oxideshop-ce": "6.8 - 6.9"
}, },
"extra": { "extra": {
"oxideshop": { "oxideshop": {

View File

@ -32,7 +32,7 @@ $aModule = [
'en' => '', 'en' => '',
], ],
'thumbnail' => '', 'thumbnail' => '',
'version' => '1.4.0.0', 'version' => '2.1.0.0',
'author' => 'D³ Data Development (Inh.: Thomas Dartsch)', 'author' => 'D³ Data Development (Inh.: Thomas Dartsch)',
'email' => 'support@shopmodule.com', 'email' => 'support@shopmodule.com',
'url' => 'https://www.oxidmodule.com/', 'url' => 'https://www.oxidmodule.com/',

View File

@ -11,5 +11,5 @@
* @link https://www.oxidmodule.com * @link https://www.oxidmodule.com
*/ */
define('D3DATAWIZARD_REQUIRE_MODCFG', true); const D3DATAWIZARD_REQUIRE_MODCFG = true;

View File

@ -13,6 +13,6 @@ class d3TestExport extends ExportBase
public function getQuery(): array public function getQuery(): array
{ {
return "SELECT 1"; return ["SELECT 1"];
} }
} }

View File

@ -94,7 +94,7 @@ class ActionBaseTest extends d3ModCfgUnitTestCase
); );
} }
public function canGetHasFormElementsDataProvider() public function canGetHasFormElementsDataProvider(): array
{ {
return [ return [
'hasFormElements' => [['abc', 'def'], true], 'hasFormElements' => [['abc', 'def'], true],

View File

@ -21,6 +21,7 @@ use D3\DataWizard\tests\tools\d3TestAction;
use D3\DataWizard\tests\tools\d3TestExport; use D3\DataWizard\tests\tools\d3TestExport;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase; use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class ConfigurationTest extends d3ModCfgUnitTestCase class ConfigurationTest extends d3ModCfgUnitTestCase
{ {
@ -44,7 +45,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Configuration::__construct * @covers \D3\DataWizard\Application\Model\Configuration::__construct
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canConstruct() public function canConstruct()
{ {
@ -65,7 +66,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Configuration::configure() * @covers \D3\DataWizard\Application\Model\Configuration::configure()
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canConfigure() public function canConfigure()
{ {
@ -80,7 +81,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Configuration::registerAction * @covers \D3\DataWizard\Application\Model\Configuration::registerAction
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canRegisterAction() public function canRegisterAction()
{ {
@ -113,7 +114,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Configuration::registerExport * @covers \D3\DataWizard\Application\Model\Configuration::registerExport
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canRegisterExport() public function canRegisterExport()
{ {
@ -166,7 +167,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Configuration::getGroupedActions() * @covers \D3\DataWizard\Application\Model\Configuration::getGroupedActions()
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canGetGroupedActions() public function canGetGroupedActions()
{ {
@ -190,7 +191,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Configuration::getGroupedExports() * @covers \D3\DataWizard\Application\Model\Configuration::getGroupedExports()
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canGetGroupedExports() public function canGetGroupedExports()
{ {
@ -214,7 +215,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Configuration::getActionGroups() * @covers \D3\DataWizard\Application\Model\Configuration::getActionGroups()
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canGetActionGroups() public function canGetActionGroups()
{ {
@ -238,7 +239,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Configuration::getExportGroups() * @covers \D3\DataWizard\Application\Model\Configuration::getExportGroups()
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canGetExportGroups() public function canGetExportGroups()
{ {
@ -262,7 +263,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Configuration::getActionsByGroup() * @covers \D3\DataWizard\Application\Model\Configuration::getActionsByGroup()
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canGetActionsByGroup() public function canGetActionsByGroup()
{ {
@ -287,7 +288,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Configuration::getExportsByGroup() * @covers \D3\DataWizard\Application\Model\Configuration::getExportsByGroup()
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canGetExportsByGroup() public function canGetExportsByGroup()
{ {
@ -312,7 +313,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Configuration::getAllActions() * @covers \D3\DataWizard\Application\Model\Configuration::getAllActions()
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canGetAllActions() public function canGetAllActions()
{ {
@ -343,7 +344,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Configuration::getAllExports() * @covers \D3\DataWizard\Application\Model\Configuration::getAllExports()
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canGetAllExports() public function canGetAllExports()
{ {
@ -374,7 +375,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Configuration::getActionById() * @covers \D3\DataWizard\Application\Model\Configuration::getActionById()
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
* @dataProvider canGetActionByIdDataProvider * @dataProvider canGetActionByIdDataProvider
*/ */
public function canGetActionById($id, $throwException) public function canGetActionById($id, $throwException)
@ -409,7 +410,7 @@ class ConfigurationTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Configuration::getExportById() * @covers \D3\DataWizard\Application\Model\Configuration::getExportById()
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
* @dataProvider canGetActionByIdDataProvider * @dataProvider canGetActionByIdDataProvider
*/ */
public function canGetExportById($id, $throwException) public function canGetExportById($id, $throwException)

View File

@ -17,7 +17,9 @@ namespace D3\DataWizard\tests\unit\Application\Model\Exceptions;
use D3\DataWizard\Application\Model\Exceptions\DebugException; use D3\DataWizard\Application\Model\Exceptions\DebugException;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase; use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class DebugExceptionTest extends d3ModCfgUnitTestCase class DebugExceptionTest extends d3ModCfgUnitTestCase
{ {
@ -27,13 +29,13 @@ class DebugExceptionTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Exceptions\DebugException::__construct * @covers \D3\DataWizard\Application\Model\Exceptions\DebugException::__construct
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canConstruct() public function canConstruct()
{ {
$code = '500'; $code = '500';
$exception = oxNew(\Exception::class); $exception = oxNew( Exception::class);
/** @var DebugException|MockObject $modelMock */ /** @var DebugException|MockObject $modelMock */
$modelMock = $this->getMockBuilder(DebugException::class) $modelMock = $this->getMockBuilder(DebugException::class)

View File

@ -17,7 +17,9 @@ namespace D3\DataWizard\tests\unit\Application\Model\Exceptions;
use D3\DataWizard\Application\Model\Exceptions\ExportFileException; use D3\DataWizard\Application\Model\Exceptions\ExportFileException;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase; use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class ExportFileExceptionTest extends d3ModCfgUnitTestCase class ExportFileExceptionTest extends d3ModCfgUnitTestCase
{ {
@ -27,13 +29,13 @@ class ExportFileExceptionTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Exceptions\ExportFileException::__construct * @covers \D3\DataWizard\Application\Model\Exceptions\ExportFileException::__construct
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canConstruct() public function canConstruct()
{ {
$code = '500'; $code = '500';
$exception = oxNew(\Exception::class); $exception = oxNew( Exception::class);
/** @var ExportFileException|MockObject $modelMock */ /** @var ExportFileException|MockObject $modelMock */
$modelMock = $this->getMockBuilder(ExportFileException::class) $modelMock = $this->getMockBuilder(ExportFileException::class)

View File

@ -19,8 +19,10 @@ use D3\DataWizard\Application\Model\Exceptions\InputUnvalidException;
use D3\DataWizard\Application\Model\ExportBase; use D3\DataWizard\Application\Model\ExportBase;
use D3\DataWizard\tests\tools\d3TestExport; use D3\DataWizard\tests\tools\d3TestExport;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase; use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use FormManager\Inputs\Number; use FormManager\Inputs\Number;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class InputUnvalidExceptionTest extends d3ModCfgUnitTestCase class InputUnvalidExceptionTest extends d3ModCfgUnitTestCase
{ {
@ -30,15 +32,14 @@ class InputUnvalidExceptionTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Exceptions\InputUnvalidException::__construct * @covers \D3\DataWizard\Application\Model\Exceptions\InputUnvalidException::__construct
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canConstruct() public function canConstruct()
{ {
$code = '500'; $code = '500';
$exception = oxNew(\Exception::class); $exception = oxNew( Exception::class);
/** @var Number $invalidField */
$invalidField = new Number(null, [ $invalidField = new Number(null, [
'required' => true, 'required' => true,
'min' => 1, 'min' => 1,

View File

@ -17,7 +17,9 @@ namespace D3\DataWizard\tests\unit\Application\Model\Exceptions;
use D3\DataWizard\Application\Model\Exceptions\NoSuitableRendererException; use D3\DataWizard\Application\Model\Exceptions\NoSuitableRendererException;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase; use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class NoSuitableRendererExceptionTest extends d3ModCfgUnitTestCase class NoSuitableRendererExceptionTest extends d3ModCfgUnitTestCase
{ {
@ -27,13 +29,13 @@ class NoSuitableRendererExceptionTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Exceptions\NoSuitableRendererException::__construct * @covers \D3\DataWizard\Application\Model\Exceptions\NoSuitableRendererException::__construct
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canConstruct() public function canConstruct()
{ {
$code = '500'; $code = '500';
$exception = oxNew(\Exception::class); $exception = oxNew( Exception::class);
/** @var NoSuitableRendererException|MockObject $modelMock */ /** @var NoSuitableRendererException|MockObject $modelMock */
$modelMock = $this->getMockBuilder(NoSuitableRendererException::class) $modelMock = $this->getMockBuilder(NoSuitableRendererException::class)

View File

@ -19,7 +19,9 @@ use D3\DataWizard\Application\Model\Exceptions\TaskException;
use D3\DataWizard\Application\Model\ExportBase; use D3\DataWizard\Application\Model\ExportBase;
use D3\DataWizard\tests\tools\d3TestExport; use D3\DataWizard\tests\tools\d3TestExport;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase; use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class TaskExceptionTest extends d3ModCfgUnitTestCase class TaskExceptionTest extends d3ModCfgUnitTestCase
{ {
@ -29,13 +31,13 @@ class TaskExceptionTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\Exceptions\TaskException::__construct * @covers \D3\DataWizard\Application\Model\Exceptions\TaskException::__construct
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canConstruct() public function canConstruct()
{ {
$code = '500'; $code = '500';
$exception = oxNew(\Exception::class); $exception = oxNew( Exception::class);
/** @var ExportBase|MockObject $taskMock */ /** @var ExportBase|MockObject $taskMock */
$taskMock = $this->getMockBuilder(d3TestExport::class) $taskMock = $this->getMockBuilder(d3TestExport::class)

View File

@ -99,7 +99,7 @@ class ExportBaseTest extends d3ModCfgUnitTestCase
); );
} }
public function canGetHasFormElementsDataProvider() public function canGetHasFormElementsDataProvider(): array
{ {
return [ return [
'hasFormElements' => [['abc', 'def'], true], 'hasFormElements' => [['abc', 'def'], true],
@ -285,16 +285,12 @@ class ExportBaseTest extends d3ModCfgUnitTestCase
/** @var d3TestExport|MockObject $modelMock */ /** @var d3TestExport|MockObject $modelMock */
$modelMock = $this->getMockBuilder(d3TestExport::class) $modelMock = $this->getMockBuilder(d3TestExport::class)
->onlyMethods([ ->onlyMethods([
'getQuery', 'getContent',
'getExportData',
'renderContent',
'getFileSystem', 'getFileSystem',
'getExportFileName' 'getExportFileName'
]) ])
->getMock(); ->getMock();
$modelMock->expects($this->atLeastOnce())->method('getQuery')->willReturn(['SELECT 1', ['arg1', 'arg2']]); $modelMock->expects($this->atLeastOnce())->method('getContent')->willReturn('some content');
$modelMock->expects($this->atLeastOnce())->method('getExportData')->willReturn([[1, 2], ['field1', 'field2']]);
$modelMock->expects($this->atLeastOnce())->method('renderContent')->willReturn('some content');
$modelMock->expects($this->atLeastOnce())->method('getFileSystem')->willReturn($fsMock); $modelMock->expects($this->atLeastOnce())->method('getFileSystem')->willReturn($fsMock);
$modelMock->expects($this->atLeastOnce())->method('getExportFileName')->willReturn('exportFileName'); $modelMock->expects($this->atLeastOnce())->method('getExportFileName')->willReturn('exportFileName');
@ -604,4 +600,35 @@ class ExportBaseTest extends d3ModCfgUnitTestCase
'fulfilled SELECT' => [' SELECT 1', false, [['field1' => 'content1', 'field2' => 'content2']]], 'fulfilled SELECT' => [' SELECT 1', false, [['field1' => 'content1', 'field2' => 'content2']]],
]; ];
} }
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::getContent
* @test
* @throws ReflectionException
*/
public function canGetContent()
{
/** @var d3TestExport|MockObject $modelMock */
$modelMock = $this->getMockBuilder(d3TestExport::class)
->onlyMethods([
'getQuery',
'getExportData',
'renderContent'
])
->getMock();
$modelMock->expects($this->atLeastOnce())->method('getQuery')->willReturn(['SELECT 1', ['arg1', 'arg2']]);
$modelMock->expects($this->atLeastOnce())->method('getExportData')->willReturn([[1, 2], ['field1', 'field2']]);
$modelMock->expects($this->atLeastOnce())->method('renderContent')->willReturn('some content');
$this->_oModel = $modelMock;
$this->assertSame(
'some content',
$this->callMethod(
$this->_oModel,
'getContent',
['CSV']
)
);
}
} }

View File

@ -22,6 +22,7 @@ use League\Csv\Writer;
use OxidEsales\Eshop\Core\Config; use OxidEsales\Eshop\Core\Config;
use OxidEsales\Eshop\Core\Registry; use OxidEsales\Eshop\Core\Registry;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class CsvTest extends ExportRendererTest class CsvTest extends ExportRendererTest
{ {
@ -38,7 +39,7 @@ class CsvTest extends ExportRendererTest
/** /**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getContent * @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getContent
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
* @dataProvider canGetContentDataProvider * @dataProvider canGetContentDataProvider
*/ */
public function canGetContent($blThrowException) public function canGetContent($blThrowException)
@ -48,25 +49,21 @@ class CsvTest extends ExportRendererTest
$valueList = ['value1', 'value2']; $valueList = ['value1', 'value2'];
/** @var Writer|MockObject $csvMock */ /** @var Writer|MockObject $csvMock */
$csvMockBuilder = $this->getMockBuilder(Writer::class); $csvMockBuilder = $this->getMockBuilder( Writer::class);
$csvMockBuilder->disableOriginalConstructor(); $csvMockBuilder->disableOriginalConstructor();
$onlyMethods = ['insertOne', 'insertAll']; $onlyMethods = ['__toString', 'insertOne', 'insertAll'];
if (method_exists($csvMockBuilder->getMock(), 'getContent')) {
$onlyMethods[] = 'getContent';
} else {
$csvMockBuilder->addMethods(['getContent']);
}
$csvMockBuilder->onlyMethods($onlyMethods); $csvMockBuilder->onlyMethods($onlyMethods);
$csvMock = $csvMockBuilder->getMock(); $csvMock = $csvMockBuilder->getMock();
$csvMock->method('insertOne')->willReturn(1);
$csvMock->method('insertAll')->willReturn(1);
if ($blThrowException) { if ($blThrowException) {
$csvMock->expects($this->atLeastOnce())->method('getContent')->willThrowException(oxNew(Exception::class)); $csvMock->expects($this->atLeastOnce())->method('__toString')->willThrowException(oxNew(Exception::class));
$this->expectException(RenderException::class); $this->expectException(RenderException::class);
} else { } else {
$csvMock->expects($this->atLeastOnce())->method('getContent')->willReturn($expected); $csvMock->expects($this->atLeastOnce())->method('__toString')->willReturn($expected);
} }
$csvMock->expects($this->atLeastOnce())->method('insertOne')->with($fieldList)->willReturn(1);
$csvMock->expects($this->atLeastOnce())->method('insertAll')->with($valueList)->willReturn(1);
/** @var Csv|MockObject $modelMock */ /** @var Csv|MockObject $modelMock */
$modelMock = $this->getMockBuilder(Csv::class) $modelMock = $this->getMockBuilder(Csv::class)
@ -99,7 +96,7 @@ class CsvTest extends ExportRendererTest
/** /**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getCsv * @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getCsv
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canGetCsv() public function canGetCsv()
{ {
@ -115,7 +112,7 @@ class CsvTest extends ExportRendererTest
/** /**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getCsv * @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::getCsv
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canGetCsvNoSettings() public function canGetCsvNoSettings()
{ {
@ -165,7 +162,7 @@ class CsvTest extends ExportRendererTest
/** /**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::d3GetConfig * @covers \D3\DataWizard\Application\Model\ExportRenderer\Csv::d3GetConfig
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canGetConfig() public function canGetConfig()
{ {

View File

@ -15,6 +15,7 @@ namespace D3\DataWizard\tests\unit\Application\Model\ExportRenderer;
use D3\DataWizard\Application\Model\ExportRenderer\RendererInterface; use D3\DataWizard\Application\Model\ExportRenderer\RendererInterface;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase; use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use ReflectionException;
abstract class ExportRendererTest extends d3ModCfgUnitTestCase abstract class ExportRendererTest extends d3ModCfgUnitTestCase
{ {
@ -33,7 +34,7 @@ abstract class ExportRendererTest extends d3ModCfgUnitTestCase
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Json::getFileExtension * @covers \D3\DataWizard\Application\Model\ExportRenderer\Json::getFileExtension
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getFileExtension * @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getFileExtension
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canGetFileExtension() public function canGetFileExtension()
{ {
@ -51,7 +52,7 @@ abstract class ExportRendererTest extends d3ModCfgUnitTestCase
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Json::getTitleTranslationId * @covers \D3\DataWizard\Application\Model\ExportRenderer\Json::getTitleTranslationId
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getTitleTranslationId * @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getTitleTranslationId
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canGetTitleTranslationId() public function canGetTitleTranslationId()
{ {

View File

@ -17,6 +17,7 @@ namespace D3\DataWizard\tests\unit\Application\Model\ExportRenderer;
use D3\DataWizard\Application\Model\Exceptions\RenderException; use D3\DataWizard\Application\Model\Exceptions\RenderException;
use D3\DataWizard\Application\Model\ExportRenderer\Json; use D3\DataWizard\Application\Model\ExportRenderer\Json;
use ReflectionException;
class JsonTest extends ExportRendererTest class JsonTest extends ExportRendererTest
{ {
@ -33,7 +34,7 @@ class JsonTest extends ExportRendererTest
/** /**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Json::getContent * @covers \D3\DataWizard\Application\Model\ExportRenderer\Json::getContent
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
* @dataProvider canGetContentDataProvider * @dataProvider canGetContentDataProvider
*/ */
public function canGetContent($valueList, $expectException) public function canGetContent($valueList, $expectException)

View File

@ -18,6 +18,7 @@ namespace D3\DataWizard\tests\unit\Application\Model\ExportRenderer;
use D3\DataWizard\Application\Model\ExportRenderer\Pretty; use D3\DataWizard\Application\Model\ExportRenderer\Pretty;
use MathieuViossat\Util\ArrayToTextTable; use MathieuViossat\Util\ArrayToTextTable;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class PrettyTest extends ExportRendererTest class PrettyTest extends ExportRendererTest
{ {
@ -34,7 +35,7 @@ class PrettyTest extends ExportRendererTest
/** /**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getContent * @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getContent
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canGetContent() public function canGetContent()
{ {
@ -69,7 +70,7 @@ class PrettyTest extends ExportRendererTest
/** /**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getArrayToTextTableInstance * @covers \D3\DataWizard\Application\Model\ExportRenderer\Pretty::getArrayToTextTableInstance
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canGetArrayToTextTableInstance() public function canGetArrayToTextTableInstance()
{ {

View File

@ -23,6 +23,7 @@ use D3\DataWizard\Application\Model\ExportRenderer\RendererBridge;
use D3\DataWizard\Application\Model\ExportRenderer\RendererInterface; use D3\DataWizard\Application\Model\ExportRenderer\RendererInterface;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase; use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use PHPUnit\Framework\MockObject\MockObject; use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
class RendererBridgeTest extends d3ModCfgUnitTestCase class RendererBridgeTest extends d3ModCfgUnitTestCase
{ {
@ -46,7 +47,7 @@ class RendererBridgeTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\RendererBridge::getRendererList * @covers \D3\DataWizard\Application\Model\ExportRenderer\RendererBridge::getRendererList
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canGetRendererList() public function canGetRendererList()
{ {
@ -62,7 +63,7 @@ class RendererBridgeTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\RendererBridge::getTranslatedRendererIdList * @covers \D3\DataWizard\Application\Model\ExportRenderer\RendererBridge::getTranslatedRendererIdList
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canGetTranslatedRendererIdList() public function canGetTranslatedRendererIdList()
{ {
@ -84,7 +85,7 @@ class RendererBridgeTest extends d3ModCfgUnitTestCase
/** /**
* @covers \D3\DataWizard\Application\Model\ExportRenderer\RendererBridge::translateRendererId * @covers \D3\DataWizard\Application\Model\ExportRenderer\RendererBridge::translateRendererId
* @test * @test
* @throws \ReflectionException * @throws ReflectionException
*/ */
public function canTranslateRendererId() public function canTranslateRendererId()
{ {
@ -108,7 +109,7 @@ class RendererBridgeTest extends d3ModCfgUnitTestCase
* @test * @test
* @param $format * @param $format
* @param $blThrowException * @param $blThrowException
* @throws \ReflectionException * @throws ReflectionException
* @dataProvider canGetRendererDataProvider * @dataProvider canGetRendererDataProvider
*/ */
public function canGetRenderer($format, $blThrowException) public function canGetRenderer($format, $blThrowException)