Split up loadFirstRow

Signed-off-by: Kamil Tekiela <tekiela246@gmail.com>
This commit is contained in:
Kamil Tekiela 2023-04-19 22:50:12 +01:00
parent c3224a50a0
commit a2a35c19de
3 changed files with 39 additions and 31 deletions

View File

@ -244,23 +244,20 @@ class InsertEdit
/**
* No primary key given, just load first row
*
* @param string $table name of the table
* @param string $db name of the database
*
* @return array<int, ResultInterface|false[]>
* @phpstan-return array{ResultInterface, false[]}
*/
private function loadFirstRow(string $table, string $db): array
private function loadFirstRow(string $table, string $db): ResultInterface
{
$result = $this->dbi->query(
return $this->dbi->query(
'SELECT * FROM ' . Util::backquote($db)
. '.' . Util::backquote($table) . ' LIMIT 1;',
);
// Can be a string on some old configuration storage settings
$rows = array_fill(0, (int) $GLOBALS['cfg']['InsertRows'], false);
}
return [$result, $rows];
/** @return false[] */
private function getInsertRows(): array
{
// Can be a string on some old configuration storage settings
return array_fill(0, (int) $GLOBALS['cfg']['InsertRows'], false);
}
/**
@ -1770,7 +1767,8 @@ class InsertEdit
// we are inserting
$insertMode = true;
$whereClause = null;
[$result, $rows] = $this->loadFirstRow($table, $db);
$result = $this->loadFirstRow($table, $db);
$rows = $this->getInsertRows();
$whereClauses = null;
$whereClauseArray = [];
$foundUniqueKey = false;

View File

@ -14897,6 +14897,7 @@
<code>$result</code>
<code>$result</code>
<code>$result</code>
<code>$result</code>
</MixedAssignment>
</file>
<file src="test/classes/InternalRelationsTest.php">

View File

@ -336,23 +336,8 @@ class InsertEditTest extends AbstractTestCase
$this->assertFalse($result);
}
/** @return list<array{int|string, array<bool>}> */
public static function dataProviderConfigValueInsertRows(): array
public function testLoadFirstRow(): void
{
return [[2, [false, false]], ['2', [false, false]], [3, [false, false, false]], ['3', [false, false, false]]];
}
/**
* Test for loadFirstRow
*
* @param array<bool> $rowsValue
*
* @dataProvider dataProviderConfigValueInsertRows
*/
public function testLoadFirstRow(string|int $configValue, array $rowsValue): void
{
$GLOBALS['cfg']['InsertRows'] = $configValue;
$resultStub = $this->createMock(DummyResult::class);
$dbi = $this->getMockBuilder(DatabaseInterface::class)
@ -380,10 +365,34 @@ class InsertEditTest extends AbstractTestCase
['table', 'db'],
);
$this->assertEquals(
[$resultStub, $rowsValue],
$result,
$this->assertEquals($resultStub, $result);
}
/** @return list<array{int|string, array<false>}> */
public static function dataProviderConfigValueInsertRows(): array
{
return [[2, [false, false]], ['2', [false, false]], [3, [false, false, false]], ['3', [false, false, false]]];
}
/**
* Test for loadFirstRow
*
* @param array<false> $rowsValue
*
* @dataProvider dataProviderConfigValueInsertRows
*/
public function testGetInsertRows(string|int $configValue, array $rowsValue): void
{
$GLOBALS['cfg']['InsertRows'] = $configValue;
$result = $this->callFunction(
$this->insertEdit,
InsertEdit::class,
'getInsertRows',
[],
);
$this->assertEquals($rowsValue, $result);
}
/**