mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-15 20:46:26 +00:00
Additional Test
This commit is contained in:
@@ -165,13 +165,13 @@ class Sort extends LookupRefValidations
|
||||
$sortOrder = self::validateSortOrder($sortOrder);
|
||||
}
|
||||
|
||||
/** @return mixed[] */
|
||||
private static function validateSortVector(mixed $sortVector, int $sortArraySize): array
|
||||
/**
|
||||
* @param mixed[] $sortVector
|
||||
*
|
||||
* @return mixed[]
|
||||
*/
|
||||
private static function validateSortVector(array $sortVector, int $sortArraySize): array
|
||||
{
|
||||
if (!is_array($sortVector)) {
|
||||
throw new Exception(ExcelError::VALUE());
|
||||
}
|
||||
|
||||
// It doesn't matter if it's a row or a column vectors, it works either way
|
||||
$sortVector = Functions::flattenArray($sortVector);
|
||||
if (count($sortVector) !== $sortArraySize) {
|
||||
|
||||
@@ -88,6 +88,7 @@ class SortByBetterTest extends TestCase
|
||||
public function testSortByRow(array $expectedResult, array $matrix, string $byArray, ?int $sortOrder = null, ?string $byArray2 = null, ?int $sortOrder2 = null): void
|
||||
{
|
||||
$sheet = $this->getSheet($matrix);
|
||||
$sheet->fromArray([['B'], ['D'], ['A'], ['C'], ['H'], ['G'], ['F'], ['E']], null, 'G1', true);
|
||||
$formula = "=SORTBY({$this->range}, $byArray";
|
||||
if ($sortOrder !== null) {
|
||||
$formula .= ", $sortOrder";
|
||||
@@ -136,6 +137,20 @@ class SortByBetterTest extends TestCase
|
||||
self::sampleDataForSimpleSort(),
|
||||
'A1:A8',
|
||||
],
|
||||
'More realistic example of when to use SORTBY vs SORT' => [
|
||||
[
|
||||
['Amy', 22],
|
||||
['Tom', 52],
|
||||
['Sal', 73],
|
||||
['Fred', 65],
|
||||
['Hector', 66],
|
||||
['Xi', 19],
|
||||
['Srivan', 39],
|
||||
['Fritz', 19],
|
||||
],
|
||||
self::sampleDataForSimpleSort(),
|
||||
'G1:G8',
|
||||
],
|
||||
'Simple sort by name descending' => [
|
||||
[
|
||||
['Xi', 19],
|
||||
|
||||
Reference in New Issue
Block a user