Skip to content

Commit 488499c

Browse files
committed
Added mocking for test tools
1 parent d53a542 commit 488499c

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+2324
-1701
lines changed

.github/workflows/main.yml

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,6 @@ jobs:
5252
path: node_modules
5353
key: ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}
5454

55-
- name: Install NPM packages
56-
if: steps.node_modules-cache.outputs.cache-hit != 'true'
57-
run: npm ci --include=dev
58-
5955
- name: Install PHP versions
6056
uses: shivammathur/setup-php@v2
6157
with:
@@ -155,10 +151,6 @@ jobs:
155151
path: node_modules
156152
key: ${{ runner.os }}-build-${{ hashFiles('**/package.json') }}-${{ hashFiles('**/package-lock.json') }}
157153

158-
- name: Install NPM packages
159-
if: steps.node_modules-cache.outputs.cache-hit != 'true'
160-
run: npm ci --include=dev
161-
162154
- name: Install PHP versions
163155
uses: shivammathur/setup-php@v2
164156
with:

README.md

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@
33
<p align="center">A powerful and easy-to-use package for managing Git hooks within your Laravel projects. Improve your code quality, reduce the time spent on code reviews, and catch potential bugs before they make it into your repository.</p>
44

55
<p align="center">
6-
<a href="https://packagist.org/packages/igorsgm/laravel-git-hooks">
7-
<img src="https://img.shields.io/packagist/v/igorsgm/laravel-git-hooks.svg?style=flat-square" alt="Latest Version on Packagist">
6+
<a href="https://packagist.org/packages/indy2kro/laravel-git-hooks">
7+
<img src="https://img.shields.io/packagist/v/indy2kro/laravel-git-hooks.svg?style=flat-square" alt="Latest Version on Packagist">
88
</a>
9-
<a href="https://github.com/igorsgm/laravel-git-hooks/actions/workflows/main.yml/badge.svg">
10-
<img src="https://img.shields.io/github/actions/workflow/status/igorsgm/laravel-git-hooks/main.yml?style=flat-square" alt="Build Status">
9+
<a href="https://github.com/indy2kro/laravel-git-hooks/actions/workflows/main.yml/badge.svg">
10+
<img src="https://img.shields.io/github/actions/workflow/status/indy2kro/laravel-git-hooks/main.yml?style=flat-square" alt="Build Status">
1111
</a>
12-
<img src="https://img.shields.io/scrutinizer/coverage/g/igorsgm/laravel-git-hooks/master?style=flat-square" alt="Test Coverage">
13-
<img src="https://img.shields.io/scrutinizer/quality/g/igorsgm/laravel-git-hooks/master?style=flat-square" alt="Code Quality">
14-
<a href="https://packagist.org/packages/igorsgm/laravel-git-hooks">
15-
<img src="https://img.shields.io/packagist/dt/igorsgm/laravel-git-hooks.svg?style=flat-square" alt="Total Downloads">
12+
<img src="https://img.shields.io/scrutinizer/coverage/g/indy2kro/laravel-git-hooks/master?style=flat-square" alt="Test Coverage">
13+
<img src="https://img.shields.io/scrutinizer/quality/g/indy2kro/laravel-git-hooks/master?style=flat-square" alt="Code Quality">
14+
<a href="https://packagist.org/packages/indy2kro/laravel-git-hooks">
15+
<img src="https://img.shields.io/packagist/dt/indy2kro/laravel-git-hooks.svg?style=flat-square" alt="Total Downloads">
1616
</a>
1717
</p>
1818

@@ -22,6 +22,8 @@
2222
<img src="https://user-images.githubusercontent.com/14129843/234191523-859b962d-bfdf-4df7-88da-9c80ddb93607.png" alt="Laravel Git Hooks usage sample">
2323
</p>
2424

25+
This is a fork of <a href="https://github.com/igorsgm/laravel-git-hooks">igorsgm/laravel-git-hooks</a> maintained for latest versions.
26+
2527
## ✨ Features
2628

2729
- **Pre-configured Hooks:** Laravel Git Hooks comes with pre-configured pre-commit hooks for popular tools, such as Laravel Pint, PHPCS, ESLint, Prettier, Larastan, Enlightn, Rector, PHP Insights and Blade Formatter, making it easy to enforce coding standards and style guidelines right away.
@@ -36,7 +38,7 @@
3638

3739
- You can install the package via composer:
3840
```bash
39-
composer require igorsgm/laravel-git-hooks --dev
41+
composer require indy2kro/laravel-git-hooks --dev
4042
```
4143

4244
- Publish the config file and customize it in the way you want:

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
{
2-
"name": "igorsgm/laravel-git-hooks",
2+
"name": "indy2kro/laravel-git-hooks",
33
"description": "🪝• Efficiently manage Git hooks in Laravel projects. Enhance code quality, save time on reviews, and prevent bugs from entering your repository.",
44
"keywords": [
5-
"igorsgm",
65
"laravel-git-hooks",
76
"git",
87
"git-hooks",
@@ -11,7 +10,7 @@
1110
"pre-commit-hook",
1211
"pint-pre-commit"
1312
],
14-
"homepage": "https://github.com/igorsgm/laravel-git-hooks",
13+
"homepage": "https://github.com/indy2kro/laravel-git-hooks",
1514
"license": "MIT",
1615
"type": "library",
1716
"authors": [

src/Console/Commands/Hooks/BaseCodeAnalyzerPreCommitHook.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -198,11 +198,15 @@ public function getDockerContainer(): string
198198
*/
199199
protected function analizeCommittedFiles(Collection $commitFiles): self
200200
{
201-
/** @var Collection<int, ChangedFile> $chunk */
201+
/**
202+
* @var Collection<int, ChangedFile> $chunk
203+
*/
202204
foreach ($commitFiles->chunk($this->chunkSize) as $chunk) {
203205
$filePaths = [];
204206

205-
/** @var ChangedFile $file */
207+
/**
208+
* @var ChangedFile $file
209+
*/
206210
foreach ($chunk as $file) {
207211
if (! $this->canFileBeAnalyzed($file)) {
208212
continue;
@@ -351,9 +355,9 @@ protected function suggestAutoFixOrExit(): bool
351355
return true;
352356
}
353357
} else {
354-
if (Terminal::hasSttyAvailable() &&
355-
$this->command->confirm('Would you like to attempt to correct files automagically?') &&
356-
$this->autoFixFiles()
358+
if (Terminal::hasSttyAvailable()
359+
&& $this->command->confirm('Would you like to attempt to correct files automagically?')
360+
&& $this->autoFixFiles()
357361
) {
358362
return true;
359363
}

src/Console/Commands/Hooks/ESLintPreCommitHook.php

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,15 @@ public function handle(ChangedFiles $files, Closure $next): mixed
3939
*/
4040
public function analyzerCommand(): string
4141
{
42-
return trim(implode(' ', [
43-
$this->getAnalyzerExecutable(),
44-
$this->configParam,
45-
$this->additionalParams(),
46-
]));
42+
return trim(
43+
implode(
44+
' ', [
45+
$this->getAnalyzerExecutable(),
46+
$this->configParam,
47+
$this->additionalParams(),
48+
]
49+
)
50+
);
4751
}
4852

4953
/**

src/Console/Commands/MakeHook.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,12 @@ public function handle()
4949
$supportedHooks = GitHooks::getSupportedHooks();
5050

5151
if (! in_array($this->argument('hookType'), $supportedHooks)) {
52-
$this->getOutput()->writeln(sprintf(
53-
'<bg=red;fg=white> ERROR </> Invalid hook type. Valid types are: <comment>%s</comment>',
54-
implode(', ', $supportedHooks)
55-
));
52+
$this->getOutput()->writeln(
53+
sprintf(
54+
'<bg=red;fg=white> ERROR </> Invalid hook type. Valid types are: <comment>%s</comment>',
55+
implode(', ', $supportedHooks)
56+
)
57+
);
5658

5759
return true;
5860
}

src/Git/Log.php

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -41,22 +41,24 @@ public function __construct(protected string $log)
4141
*/
4242
private function parse(array $lines): void
4343
{
44-
$handlers = collect([
45-
'commit' => function ($line): void {
46-
preg_match('/(?<hash>[a-z0-9]{40})/', $line, $matches);
47-
$this->hash = $matches['hash'] ?? null;
48-
},
49-
'Author' => function ($line): void {
50-
$this->author = substr($line, strlen('Author:') + 1);
51-
},
52-
'Date' => function ($line): void {
53-
$this->date = Carbon::parse(substr($line, strlen('Date:') + 3));
54-
},
55-
'Merge' => function ($line): void {
56-
$merge = substr($line, strlen('Merge:') + 1);
57-
$this->merge = explode(' ', $merge);
58-
},
59-
]);
44+
$handlers = collect(
45+
[
46+
'commit' => function ($line): void {
47+
preg_match('/(?<hash>[a-z0-9]{40})/', $line, $matches);
48+
$this->hash = $matches['hash'] ?? null;
49+
},
50+
'Author' => function ($line): void {
51+
$this->author = substr($line, strlen('Author:') + 1);
52+
},
53+
'Date' => function ($line): void {
54+
$this->date = Carbon::parse(substr($line, strlen('Date:') + 3));
55+
},
56+
'Merge' => function ($line): void {
57+
$merge = substr($line, strlen('Merge:') + 1);
58+
$this->merge = explode(' ', $merge);
59+
},
60+
]
61+
);
6062

6163
foreach ($lines as $line) {
6264
$handler = $handlers->first(fn ($handler, $prefix) => Str::startsWith($line, $prefix));

src/GitHooksServiceProvider.php

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,20 +14,24 @@ class GitHooksServiceProvider extends ServiceProvider
1414
public function boot(): void
1515
{
1616
if ($this->app->runningInConsole()) {
17-
$this->publishes([
18-
__DIR__.'/../config/git-hooks.php' => $this->app->configPath('git-hooks.php'),
19-
], 'laravel-git-hooks');
17+
$this->publishes(
18+
[
19+
__DIR__.'/../config/git-hooks.php' => $this->app->configPath('git-hooks.php'),
20+
], 'laravel-git-hooks'
21+
);
2022

2123
// Registering package commands.
22-
$this->commands([
23-
\Igorsgm\GitHooks\Console\Commands\RegisterHooks::class,
24-
\Igorsgm\GitHooks\Console\Commands\CommitMessage::class,
25-
\Igorsgm\GitHooks\Console\Commands\PreCommit::class,
26-
\Igorsgm\GitHooks\Console\Commands\PrepareCommitMessage::class,
27-
\Igorsgm\GitHooks\Console\Commands\PostCommit::class,
28-
\Igorsgm\GitHooks\Console\Commands\PrePush::class,
29-
\Igorsgm\GitHooks\Console\Commands\MakeHook::class,
30-
]);
24+
$this->commands(
25+
[
26+
\Igorsgm\GitHooks\Console\Commands\RegisterHooks::class,
27+
\Igorsgm\GitHooks\Console\Commands\CommitMessage::class,
28+
\Igorsgm\GitHooks\Console\Commands\PreCommit::class,
29+
\Igorsgm\GitHooks\Console\Commands\PrepareCommitMessage::class,
30+
\Igorsgm\GitHooks\Console\Commands\PostCommit::class,
31+
\Igorsgm\GitHooks\Console\Commands\PrePush::class,
32+
\Igorsgm\GitHooks\Console\Commands\MakeHook::class,
33+
]
34+
);
3135
}
3236
}
3337

src/Traits/GitHelper.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ public function updateCommitMessageContentInFile(string $path, string $message):
4848
*/
4949
public function isMergeInProgress(): bool
5050
{
51-
$command = $this->runCommands('git merge HEAD', [
52-
'silent' => true,
53-
]);
51+
$command = $this->runCommands(
52+
'git merge HEAD', [
53+
'silent' => true,
54+
]
55+
);
5456

5557
// If a merge is in progress, the process returns code 128
5658
return $command->getExitCode() === 128;

src/Traits/ProcessHelper.php

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,13 @@ public function runCommands(string|array $commands, array $params = []): Process
4949
}
5050
}
5151

52-
$process->run(! $showOutput ? null : function (string $line) use ($output): void {
53-
if ($output !== null) {
54-
$output->write(' '.$line);
52+
$process->run(
53+
! $showOutput ? null : function (string $line) use ($output): void {
54+
if ($output !== null) {
55+
$output->write(' '.$line);
56+
}
5557
}
56-
});
58+
);
5759

5860
return $process;
5961
}
@@ -64,13 +66,15 @@ public function runCommands(string|array $commands, array $params = []): Process
6466
*/
6567
public function transformCommands(string|array $commands, callable $callback): array
6668
{
67-
return array_map(function ($value) use ($callback) {
68-
if (str_starts_with($value, 'chmod')) {
69-
return $value;
70-
}
71-
72-
return $callback($value);
73-
}, (array) $commands);
69+
return array_map(
70+
function ($value) use ($callback) {
71+
if (str_starts_with($value, 'chmod')) {
72+
return $value;
73+
}
74+
75+
return $callback($value);
76+
}, (array) $commands
77+
);
7478
}
7579

7680
/**

0 commit comments

Comments
 (0)