fix tests

This commit is contained in:
Daniel Seifert 2024-05-10 16:48:29 +02:00
parent 36ee1a5957
commit 69b33d3538
6 changed files with 33 additions and 20 deletions

View File

@ -149,8 +149,6 @@ abstract class ExportBase implements QueryBase
* @return array
* @throws DBALException
* @throws Exception
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function getExportData(array $query): array
{
@ -166,9 +164,7 @@ abstract class ExportBase implements QueryBase
);
}
/** @var Connection $connection */
$connection = ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get();
$rows = $connection->executeQuery($queryString, $parameters)->fetchAllAssociative();
$rows = $this->getConnection()->executeQuery($queryString, $parameters)->fetchAllAssociative();
if (count($rows) <= 0) {
throw oxNew(
@ -183,6 +179,11 @@ abstract class ExportBase implements QueryBase
return [ $rows, $fieldNames ];
}
protected function getConnection(): Connection
{
return ContainerFactory::getInstance()->getContainer()->get(ConnectionProviderInterface::class)->get();
}
public function registerFormElement(Input $input): void
{
if ($input instanceof Radio || $input instanceof Checkbox) {

View File

@ -18,6 +18,7 @@ namespace D3\DataWizard\tests\unit\Application\Model\Exceptions;
use D3\DataWizard\Application\Model\Exceptions\DebugException;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use OxidEsales\Eshop\Core\Registry;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
@ -51,7 +52,7 @@ class DebugExceptionTest extends d3ModCfgUnitTestCase
);
$this->assertStringContainsString(
'Debug',
Registry::getLang()->translateString('D3_DATAWIZARD_DEBUG'),
$this->callMethod(
$this->_oModel,
'getMessage'

View File

@ -18,6 +18,7 @@ namespace D3\DataWizard\tests\unit\Application\Model\Exceptions;
use D3\DataWizard\Application\Model\Exceptions\ExportFileException;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use OxidEsales\Eshop\Core\Registry;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
@ -51,7 +52,7 @@ class ExportFileExceptionTest extends d3ModCfgUnitTestCase
);
$this->assertStringContainsString(
'EXPORTFILEERROR',
Registry::getLang()->translateString('D3_DATAWIZARD_ERR_EXPORTFILEERROR'),
$this->callMethod(
$this->_oModel,
'getMessage'

View File

@ -18,6 +18,7 @@ namespace D3\DataWizard\tests\unit\Application\Model\Exceptions;
use D3\DataWizard\Application\Model\Exceptions\NoSuitableRendererException;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Exception;
use OxidEsales\Eshop\Core\Registry;
use PHPUnit\Framework\MockObject\MockObject;
use ReflectionException;
@ -51,7 +52,7 @@ class NoSuitableRendererExceptionTest extends d3ModCfgUnitTestCase
);
$this->assertStringContainsString(
'NOSUITABLERENDERER',
Registry::getLang()->translateString('D3_DATAWIZARD_ERR_NOSUITABLERENDERER'),
$this->callMethod(
$this->_oModel,
'getMessage'

View File

@ -23,6 +23,8 @@ use D3\DataWizard\Application\Model\ExportRenderer\RendererInterface;
use D3\DataWizard\tests\tools\d3TestExport;
use D3\ModCfg\Application\Model\d3filesystem;
use D3\ModCfg\Tests\unit\d3ModCfgUnitTestCase;
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver\Result;
use FormManager\Inputs\Hidden;
use FormManager\Inputs\Number;
use FormManager\Inputs\Radio;
@ -320,17 +322,17 @@ class ExportBaseTest extends d3ModCfgUnitTestCase
}
/**
* @covers \D3\DataWizard\Application\Model\ExportBase::d3GetDb
* @covers \D3\DataWizard\Application\Model\ExportBase::getConnection
* @test
* @throws ReflectionException
*/
public function canGetDb()
public function canGetConnection()
{
$this->assertInstanceOf(
Database::class,
Connection::class,
$this->callMethod(
$this->_oModel,
'd3GetDb'
'getConnection'
)
);
}
@ -542,19 +544,26 @@ class ExportBaseTest extends d3ModCfgUnitTestCase
*/
public function canGetExportData($query, $throwsException, $dbResult)
{
/** @var Database|MockObject $dbMock */
$dbMock = $this->getMockBuilder(Database::class)
->onlyMethods(['getAll'])
/** @var Result|MockObject $resultMock */
$resultMock = $this->getMockBuilder(Result::class)
->onlyMethods(get_class_methods(Result::class))
->getMock();
$dbMock->expects($this->exactly((int) !$throwsException))->method('getAll')->willReturn($dbResult);
$resultMock->method('fetchAllAssociative')->willReturn($dbResult);
/** @var Database|MockObject $connectionMock */
$connectionMock = $this->getMockBuilder(Connection::class)
->disableOriginalConstructor()
->onlyMethods(['executeQuery'])
->getMock();
$connectionMock->expects($this->exactly((int) !$throwsException))->method('executeQuery')->willReturn($resultMock);
/** @var d3TestExport|MockObject $modelMock */
$modelMock = $this->getMockBuilder(d3TestExport::class)
->onlyMethods([
'd3GetDb',
'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;

View File

@ -90,14 +90,14 @@
{{ shorttext }}...
</p>
<p class="card-text collapse" id="collapseExample">
...{{ description|replace(shorttext, '') }}
...{{ description|replace({shorttext:''}) }}
</p>
{% endif %}
{% endif %}
{% if item.hasFormElements() %}
{% for formElement in item.getFormElements() %}
{{ formElement }}
{{ formElement|raw }}
{% endfor %}
{% endif %}