mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-02-08 21:28:40 +00:00
fix tests NO_CI
This commit is contained in:
parent
2ea1d0373d
commit
8f96fe36c7
|
|
@ -151,4 +151,26 @@ abstract class BuilderAbstract
|
||||||
* @since 1.0.0
|
* @since 1.0.0
|
||||||
*/
|
*/
|
||||||
abstract public function execute() : ?\PDOStatement;
|
abstract public function execute() : ?\PDOStatement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get bind parameter type.
|
||||||
|
*
|
||||||
|
* @param mixed $value Value to bind
|
||||||
|
*
|
||||||
|
* @return int
|
||||||
|
*
|
||||||
|
* @throws \Exception
|
||||||
|
*
|
||||||
|
* @since 1.0.0
|
||||||
|
*/
|
||||||
|
public static function getBindParamType(mixed $value) : int
|
||||||
|
{
|
||||||
|
if (\is_int($value)) {
|
||||||
|
return \PDO::PARAM_INT;
|
||||||
|
} elseif (\is_string($value) || \is_float($value)) {
|
||||||
|
return \PDO::PARAM_STR;
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new \Exception();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1423,28 +1423,6 @@ class Builder extends BuilderAbstract
|
||||||
return $sth;
|
return $sth;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Get bind parameter type.
|
|
||||||
*
|
|
||||||
* @param mixed $value Value to bind
|
|
||||||
*
|
|
||||||
* @return int
|
|
||||||
*
|
|
||||||
* @throws \Exception
|
|
||||||
*
|
|
||||||
* @since 1.0.0
|
|
||||||
*/
|
|
||||||
public static function getBindParamType(mixed $value) : int
|
|
||||||
{
|
|
||||||
if (\is_int($value)) {
|
|
||||||
return \PDO::PARAM_INT;
|
|
||||||
} elseif (\is_string($value) || \is_float($value)) {
|
|
||||||
return \PDO::PARAM_STR;
|
|
||||||
}
|
|
||||||
|
|
||||||
throw new \Exception();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get column name
|
* Get column name
|
||||||
*
|
*
|
||||||
|
|
|
||||||
|
|
@ -378,7 +378,7 @@ class Builder extends BuilderAbstract
|
||||||
/**
|
/**
|
||||||
* {@inheritdoc}
|
* {@inheritdoc}
|
||||||
*/
|
*/
|
||||||
public function execute() : ?\PDOStatement
|
public function prepare() : ?\PDOStatement
|
||||||
{
|
{
|
||||||
$sth = null;
|
$sth = null;
|
||||||
$sql = '';
|
$sql = '';
|
||||||
|
|
@ -389,7 +389,49 @@ class Builder extends BuilderAbstract
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$sth->execute();
|
foreach ($this->binds as $key => $bind) {
|
||||||
|
if (!isset($bind['type'])) {
|
||||||
|
$bind['type'] = self::getBindParamType($bind['value']);
|
||||||
|
}
|
||||||
|
|
||||||
|
$sth->bindParam(\is_int($key) ? $key + 1 : $key, $bind['value'], $bind['type']);
|
||||||
|
}
|
||||||
|
} catch (\Throwable $t) {
|
||||||
|
// @codeCoverageIgnoreStart
|
||||||
|
\phpOMS\Log\FileLogger::getInstance()->error(
|
||||||
|
\phpOMS\Log\FileLogger::MSG_FULL, [
|
||||||
|
'message' => $t->getMessage() . ':' . $sql,
|
||||||
|
'line' => __LINE__,
|
||||||
|
'file' => self::class,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
\phpOMS\Log\FileLogger::getInstance()->error(
|
||||||
|
\phpOMS\Log\FileLogger::MSG_FULL, [
|
||||||
|
'message' => \json_encode($this->binds),
|
||||||
|
'line' => __LINE__,
|
||||||
|
'file' => self::class,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
$sth = null;
|
||||||
|
// @codeCoverageIgnoreEnd
|
||||||
|
}
|
||||||
|
|
||||||
|
return $sth;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritdoc}
|
||||||
|
*/
|
||||||
|
public function execute() : ?\PDOStatement
|
||||||
|
{
|
||||||
|
$sth = null;
|
||||||
|
try {
|
||||||
|
$sth = $this->prepare();
|
||||||
|
if ($sth !== null) {
|
||||||
|
$sth->execute();
|
||||||
|
}
|
||||||
|
|
||||||
if ($this->hasPostQuery) {
|
if ($this->hasPostQuery) {
|
||||||
$sqls = $this->grammar->compilePostQueries($this);
|
$sqls = $this->grammar->compilePostQueries($this);
|
||||||
|
|
@ -402,7 +444,15 @@ class Builder extends BuilderAbstract
|
||||||
// @codeCoverageIgnoreStart
|
// @codeCoverageIgnoreStart
|
||||||
\phpOMS\Log\FileLogger::getInstance()->error(
|
\phpOMS\Log\FileLogger::getInstance()->error(
|
||||||
\phpOMS\Log\FileLogger::MSG_FULL, [
|
\phpOMS\Log\FileLogger::MSG_FULL, [
|
||||||
'message' => $t->getMessage() . ':' . $sql,
|
'message' => $t->getMessage() . ':' . $this->toSql(),
|
||||||
|
'line' => __LINE__,
|
||||||
|
'file' => self::class,
|
||||||
|
]
|
||||||
|
);
|
||||||
|
|
||||||
|
\phpOMS\Log\FileLogger::getInstance()->error(
|
||||||
|
\phpOMS\Log\FileLogger::MSG_FULL, [
|
||||||
|
'message' => \json_encode($this->binds),
|
||||||
'line' => __LINE__,
|
'line' => __LINE__,
|
||||||
'file' => self::class,
|
'file' => self::class,
|
||||||
]
|
]
|
||||||
|
|
|
||||||
|
|
@ -72,8 +72,8 @@ final class SpreadsheetDatabaseMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
#[\PHPUnit\Framework\Attributes\TestDox('Data can be inserted into a database from an ods files')]
|
#[\PHPUnit\Framework\Attributes\TestDox('Data can be inserted into a database from an ods files')]
|
||||||
public function testInsertOds() : void
|
public function testInsertOds() : void
|
||||||
{
|
{
|
||||||
$mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.ods');
|
$mapper = new SpreadsheetDatabaseMapper($this->sqlite);
|
||||||
$mapper->insert();
|
$mapper->import(__DIR__ . '/insert.ods', 'insert_1');
|
||||||
|
|
||||||
$builder = new Builder($this->sqlite, true);
|
$builder = new Builder($this->sqlite, true);
|
||||||
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
||||||
|
|
@ -104,8 +104,8 @@ final class SpreadsheetDatabaseMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
#[\PHPUnit\Framework\Attributes\TestDox('Data can be inserted into a database from a xls files')]
|
#[\PHPUnit\Framework\Attributes\TestDox('Data can be inserted into a database from a xls files')]
|
||||||
public function testInsertXls() : void
|
public function testInsertXls() : void
|
||||||
{
|
{
|
||||||
$mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.xls');
|
$mapper = new SpreadsheetDatabaseMapper($this->sqlite);
|
||||||
$mapper->insert();
|
$mapper->import(__DIR__ . '/insert.xls', 'insert_1');
|
||||||
|
|
||||||
$builder = new Builder($this->sqlite, true);
|
$builder = new Builder($this->sqlite, true);
|
||||||
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
||||||
|
|
@ -136,8 +136,8 @@ final class SpreadsheetDatabaseMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
#[\PHPUnit\Framework\Attributes\TestDox('Data can be inserted into a database from a xlsx files')]
|
#[\PHPUnit\Framework\Attributes\TestDox('Data can be inserted into a database from a xlsx files')]
|
||||||
public function testInsertXlsx() : void
|
public function testInsertXlsx() : void
|
||||||
{
|
{
|
||||||
$mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.xlsx');
|
$mapper = new SpreadsheetDatabaseMapper($this->sqlite);
|
||||||
$mapper->insert();
|
$mapper->import(__DIR__ . '/insert.xlsx', 'insert_1');
|
||||||
|
|
||||||
$builder = new Builder($this->sqlite, true);
|
$builder = new Builder($this->sqlite, true);
|
||||||
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
||||||
|
|
@ -168,8 +168,8 @@ final class SpreadsheetDatabaseMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
#[\PHPUnit\Framework\Attributes\TestDox('Data can be updated in a database from an ods files')]
|
#[\PHPUnit\Framework\Attributes\TestDox('Data can be updated in a database from an ods files')]
|
||||||
public function testUpdateOds() : void
|
public function testUpdateOds() : void
|
||||||
{
|
{
|
||||||
$mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.ods');
|
$mapper = new SpreadsheetDatabaseMapper($this->sqlite);
|
||||||
$mapper->insert();
|
$mapper->import(__DIR__ . '/insert.ods', 'insert_1');
|
||||||
|
|
||||||
$builder = new Builder($this->sqlite, true);
|
$builder = new Builder($this->sqlite, true);
|
||||||
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
||||||
|
|
@ -195,8 +195,8 @@ final class SpreadsheetDatabaseMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
$data
|
$data
|
||||||
);
|
);
|
||||||
|
|
||||||
$mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/update.ods');
|
$mapper = new SpreadsheetDatabaseMapper($this->sqlite);
|
||||||
$mapper->update();
|
$mapper->update(__DIR__ . '/update.ods', 'insert_1');
|
||||||
|
|
||||||
$builder = new Builder($this->sqlite, true);
|
$builder = new Builder($this->sqlite, true);
|
||||||
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
||||||
|
|
@ -227,8 +227,8 @@ final class SpreadsheetDatabaseMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
#[\PHPUnit\Framework\Attributes\TestDox('Data can be updated in a database from a xls files')]
|
#[\PHPUnit\Framework\Attributes\TestDox('Data can be updated in a database from a xls files')]
|
||||||
public function testUpdateXls() : void
|
public function testUpdateXls() : void
|
||||||
{
|
{
|
||||||
$mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.xls');
|
$mapper = new SpreadsheetDatabaseMapper($this->sqlite);
|
||||||
$mapper->insert();
|
$mapper->import(__DIR__ . '/insert.xls', 'insert_1');
|
||||||
|
|
||||||
$builder = new Builder($this->sqlite, true);
|
$builder = new Builder($this->sqlite, true);
|
||||||
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
||||||
|
|
@ -254,8 +254,8 @@ final class SpreadsheetDatabaseMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
$data
|
$data
|
||||||
);
|
);
|
||||||
|
|
||||||
$mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/update.xls');
|
$mapper = new SpreadsheetDatabaseMapper($this->sqlite);
|
||||||
$mapper->update();
|
$mapper->update(__DIR__ . '/update.xls', 'insert_1');
|
||||||
|
|
||||||
$builder = new Builder($this->sqlite, true);
|
$builder = new Builder($this->sqlite, true);
|
||||||
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
||||||
|
|
@ -286,8 +286,8 @@ final class SpreadsheetDatabaseMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
#[\PHPUnit\Framework\Attributes\TestDox('Data can be updated in a database from a xlsx files')]
|
#[\PHPUnit\Framework\Attributes\TestDox('Data can be updated in a database from a xlsx files')]
|
||||||
public function testUpdateXlsx() : void
|
public function testUpdateXlsx() : void
|
||||||
{
|
{
|
||||||
$mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.xlsx');
|
$mapper = new SpreadsheetDatabaseMapper($this->sqlite);
|
||||||
$mapper->insert();
|
$mapper->import(__DIR__ . '/insert.xlsx', 'insert_1');
|
||||||
|
|
||||||
$builder = new Builder($this->sqlite, true);
|
$builder = new Builder($this->sqlite, true);
|
||||||
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
||||||
|
|
@ -313,8 +313,8 @@ final class SpreadsheetDatabaseMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
$data
|
$data
|
||||||
);
|
);
|
||||||
|
|
||||||
$mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/update.xlsx');
|
$mapper = new SpreadsheetDatabaseMapper($this->sqlite);
|
||||||
$mapper->update();
|
$mapper->update(__DIR__ . '/update.xlsx', 'insert_1');
|
||||||
|
|
||||||
$builder = new Builder($this->sqlite, true);
|
$builder = new Builder($this->sqlite, true);
|
||||||
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
||||||
|
|
@ -349,8 +349,8 @@ final class SpreadsheetDatabaseMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
\unlink(__DIR__ . '/select.ods');
|
\unlink(__DIR__ . '/select.ods');
|
||||||
}
|
}
|
||||||
|
|
||||||
$mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.ods');
|
$mapper = new SpreadsheetDatabaseMapper($this->sqlite);
|
||||||
$mapper->insert();
|
$mapper->import(__DIR__ . '/insert.ods', 'insert_1');
|
||||||
|
|
||||||
$builder = new Builder($this->sqlite, true);
|
$builder = new Builder($this->sqlite, true);
|
||||||
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
||||||
|
|
@ -381,7 +381,7 @@ final class SpreadsheetDatabaseMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
$builder = new Builder($this->sqlite, true);
|
$builder = new Builder($this->sqlite, true);
|
||||||
$data = $builder->select('int', 'decimal', 'bool', 'varchar', 'datetime')->from('insert_1');
|
$data = $builder->select('int', 'decimal', 'bool', 'varchar', 'datetime')->from('insert_1');
|
||||||
|
|
||||||
$mapper->select([$builder]);
|
$mapper->export(__DIR__ . '/select.ods', [$builder]);
|
||||||
|
|
||||||
self::assertTrue($this->compareSelectInsertSheet(__DIR__ . '/select.ods', __DIR__ . '/insert.ods'));
|
self::assertTrue($this->compareSelectInsertSheet(__DIR__ . '/select.ods', __DIR__ . '/insert.ods'));
|
||||||
|
|
||||||
|
|
@ -398,8 +398,8 @@ final class SpreadsheetDatabaseMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
\unlink(__DIR__ . '/select.xls');
|
\unlink(__DIR__ . '/select.xls');
|
||||||
}
|
}
|
||||||
|
|
||||||
$mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.xls');
|
$mapper = new SpreadsheetDatabaseMapper($this->sqlite);
|
||||||
$mapper->insert();
|
$mapper->import(__DIR__ . '/insert.xls', 'insert_1');
|
||||||
|
|
||||||
$builder = new Builder($this->sqlite, true);
|
$builder = new Builder($this->sqlite, true);
|
||||||
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
||||||
|
|
@ -430,7 +430,7 @@ final class SpreadsheetDatabaseMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
$builder = new Builder($this->sqlite, true);
|
$builder = new Builder($this->sqlite, true);
|
||||||
$data = $builder->select('int', 'decimal', 'bool', 'varchar', 'datetime')->from('insert_1');
|
$data = $builder->select('int', 'decimal', 'bool', 'varchar', 'datetime')->from('insert_1');
|
||||||
|
|
||||||
$mapper->select([$builder]);
|
$mapper->export(__DIR__ . '/select.xls', [$builder]);
|
||||||
|
|
||||||
self::assertTrue($this->compareSelectInsertSheet(__DIR__ . '/select.xls', __DIR__ . '/insert.xls'));
|
self::assertTrue($this->compareSelectInsertSheet(__DIR__ . '/select.xls', __DIR__ . '/insert.xls'));
|
||||||
|
|
||||||
|
|
@ -447,8 +447,8 @@ final class SpreadsheetDatabaseMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
\unlink(__DIR__ . '/select.xlsx');
|
\unlink(__DIR__ . '/select.xlsx');
|
||||||
}
|
}
|
||||||
|
|
||||||
$mapper = new SpreadsheetDatabaseMapper($this->sqlite, __DIR__ . '/insert.xlsx');
|
$mapper = new SpreadsheetDatabaseMapper($this->sqlite);
|
||||||
$mapper->insert();
|
$mapper->import(__DIR__ . '/insert.xlsx', 'insert_1');
|
||||||
|
|
||||||
$builder = new Builder($this->sqlite, true);
|
$builder = new Builder($this->sqlite, true);
|
||||||
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
$data = $builder->select('insert_1.*')->from('insert_1')->execute()?->fetchAll(\PDO::FETCH_ASSOC) ?? [];
|
||||||
|
|
@ -479,7 +479,7 @@ final class SpreadsheetDatabaseMapperTest extends \PHPUnit\Framework\TestCase
|
||||||
$builder = new Builder($this->sqlite, true);
|
$builder = new Builder($this->sqlite, true);
|
||||||
$data = $builder->select('int', 'decimal', 'bool', 'varchar', 'datetime')->from('insert_1');
|
$data = $builder->select('int', 'decimal', 'bool', 'varchar', 'datetime')->from('insert_1');
|
||||||
|
|
||||||
$mapper->select([$builder]);
|
$mapper->export(__DIR__ . '/select.xlsx', [$builder]);
|
||||||
|
|
||||||
self::assertTrue($this->compareSelectInsertSheet(__DIR__ . '/select.xlsx', __DIR__ . '/insert.xlsx'));
|
self::assertTrue($this->compareSelectInsertSheet(__DIR__ . '/select.xlsx', __DIR__ . '/insert.xlsx'));
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user