Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Directories are not shown in strict alphabetical order #941

Open
CJDennis opened this issue Sep 16, 2022 · 1 comment
Open

Directories are not shown in strict alphabetical order #941

CJDennis opened this issue Sep 16, 2022 · 1 comment

Comments

@CJDennis
Copy link

Q A
php-code-coverage version 9.2.17
PHP version 7.4.24
Driver PCOV
PCOV version (if used) 7.4.13
Installation Method Composer
Usage Method Codeception
PHPUnit version (if used) 9.5.24

Dirctories should be shown in alphabetical order. In the screenshot, EntityRepository comes before Entity but it should be after.
image

@sebastianbergmann
Copy link
Owner

Would this help?

diff --git a/src/Report/Html/Renderer/Directory.php b/src/Report/Html/Renderer/Directory.php
index 1d7334b3..850f0a53 100644
--- a/src/Report/Html/Renderer/Directory.php
+++ b/src/Report/Html/Renderer/Directory.php
@@ -15,6 +15,7 @@
 use SebastianBergmann\CodeCoverage\FileCouldNotBeWrittenException;
 use SebastianBergmann\CodeCoverage\Node\AbstractNode as Node;
 use SebastianBergmann\CodeCoverage\Node\Directory as DirectoryNode;
+use SebastianBergmann\CodeCoverage\Node\File as FileNode;
 use SebastianBergmann\Template\Exception;
 use SebastianBergmann\Template\Template;
 
@@ -32,11 +33,29 @@ public function render(DirectoryNode $node, string $file): void
 
         $items = $this->renderItem($node, true);
 
-        foreach ($node->directories() as $item) {
+        $directories = $node->directories();
+
+        usort(
+            $directories,
+            static function (DirectoryNode $a, DirectoryNode $b) {
+                return $a->name() <=> $b->name();
+            }
+        );
+
+        foreach ($directories as $item) {
             $items .= $this->renderItem($item);
         }
 
-        foreach ($node->files() as $item) {
+        $files = $node->files();
+
+        usort(
+            $files,
+            static function (FileNode $a, FileNode $b) {
+                return $a->name() <=> $b->name();
+            }
+        );
+
+        foreach ($files as $item) {
             $items .= $this->renderItem($item);
         }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants