From f13130f6ac085de5da303745c8a52279731723fe Mon Sep 17 00:00:00 2001 From: Igor Moraes Date: Sat, 10 Jun 2023 01:11:55 -0700 Subject: [PATCH] Improve commit files retrieval and update tests - Update BaseCodeAnalyzerPreCommitHook.php to use getStaged() instead of getAddedToCommit() for better accuracy in obtaining commit files. - Modify test descriptions and method calls in BaseCodeAnalyzerPreCommitHookTest.php to reflect the changes made to the main file. --- src/Console/Commands/Hooks/BaseCodeAnalyzerPreCommitHook.php | 2 +- .../Commands/Hooks/BaseCodeAnalyzerPreCommitHookTest.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Console/Commands/Hooks/BaseCodeAnalyzerPreCommitHook.php b/src/Console/Commands/Hooks/BaseCodeAnalyzerPreCommitHook.php index 9044906..481e986 100644 --- a/src/Console/Commands/Hooks/BaseCodeAnalyzerPreCommitHook.php +++ b/src/Console/Commands/Hooks/BaseCodeAnalyzerPreCommitHook.php @@ -74,7 +74,7 @@ public function __construct() */ public function handleCommittedFiles(ChangedFiles $files, Closure $next) { - $commitFiles = $files->getAddedToCommit(); + $commitFiles = $files->getStaged(); if ($commitFiles->isEmpty() || GitHooks::isMergeInProgress()) { return $next($files); diff --git a/tests/Features/Commands/Hooks/BaseCodeAnalyzerPreCommitHookTest.php b/tests/Features/Commands/Hooks/BaseCodeAnalyzerPreCommitHookTest.php index 443f48e..6cc4dfe 100644 --- a/tests/Features/Commands/Hooks/BaseCodeAnalyzerPreCommitHookTest.php +++ b/tests/Features/Commands/Hooks/BaseCodeAnalyzerPreCommitHookTest.php @@ -9,9 +9,9 @@ $this->initializeTempDirectory(base_path('temp')); }); -test('Skips check if there are no files added to commit', function () { +test('Skips check if there are no staged files in commit', function () { $changedFiles = mock(ChangedFiles::class) - ->shouldReceive('getAddedToCommit') + ->shouldReceive('getStaged') ->andReturn(collect()) ->getMock();