Repository: phpbench/phpbench (php)

Issue:
BUG: Mixed up labels in HTML output: bar_chart_time / benchmark
Got following HTML output (pay Attention to the small labels like `bench_parser_old_big_ast`):

![image](https://user-images.githubusercontent.com/85400359/139585261-8c6d0161-75d7-4be4-a506-d449a46fe231.png)

Expected labels in the following order or as shown in the console:

bench_parser_old_big_ast
bench_parser_new_big_ast
bench_parser_old_medium_ast
bench_parser_new_medium_ast
bench_parser_old_small_ast
bench_parser_new_small_ast

![image](https://user-images.githubusercontent.com/85400359/139585290-2b624b81-1f11-4e29-a14e-4616e424e505.png)

The order of the test results is right but the labels seem to be mixed up in the HTML view.

Pull request description:
Do not sort the XAxes
Fixes #931 

Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index e757f4ad..433ef86a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -14,6 +14,7 @@ Bug fixes:
 
 - Fix property (`.`) access precedence, it is now the same as `[` array
   access #928
+- Fix bug with misassigned labels in bar chart #931
 - Safely removed non-functioning config option `report.html_output_dir` #930
 
 1.1.2 (2021-09-25)
diff --git a/lib/Report/Model/BarChart.php b/lib/Report/Model/BarChart.php
index 7bebf9ab..37e67977 100644
--- a/lib/Report/Model/BarChart.php
+++ b/lib/Report/Model/BarChart.php
@@ -67,12 +67,12 @@ class BarChart implements ComponentInterface
             return [];
         }
 
+        // use all unique discreet points as the X axes values
         $xAxes = array_unique(array_merge(...array_map(function (BarChartDataSet $dataSet) {
             return $dataSet->xSeries();
         }, $this->dataSets)));
-        sort($xAxes);
 
-        return $xAxes;
+        return array_values($xAxes);
     }
 
     public function isEmpty(): bool


Test patch:
diff --git a/tests/Unit/Report/Model/BarChartTest.php b/tests/Unit/Report/Model/BarChartTest.php
index a71761df..f91186ce 100644
--- a/tests/Unit/Report/Model/BarChartTest.php
+++ b/tests/Unit/Report/Model/BarChartTest.php
@@ -31,7 +31,7 @@ class BarChartTest extends TestCase
             new BarChartDataSet('one', [12, 26, 31, 46], [1, 1, 1, 1], [1, 1, 1, 1]),
         ], 'Bar Chart One', 'foo');
 
-        self::assertEquals([12, 26, 31, 46], $chart->xAxes());
+        self::assertEquals([12, 31, 46, 26], $chart->xAxes());
     }
 
     public function testKnowsIfItsEmpty(): void
@@ -59,4 +59,20 @@ class BarChartTest extends TestCase
 
         self::assertEquals(['one', 2, 3], $chart->xLabels());
     }
+
+    public function testXLabelReplacementWithLabels(): void
+    {
+        $chart = new BarChart(
+            [
+                new BarChartDataSet('one', ['bench_one', 'bench_two', 'bench_three'], [1,2,3], [1,2,3]),
+            ],
+            'Bar Chart One',
+            'foo',
+            [
+                1 => 'five',
+            ]
+        );
+
+        self::assertEquals(['bench_one', 'five', 'bench_three'], $chart->xLabels());
+    }
 }