Skip to content

Commit ae76abc

Browse files
committed
wip PintPreCommitHookTests updated
1 parent 54bcc63 commit ae76abc

File tree

6 files changed

+52
-22
lines changed

6 files changed

+52
-22
lines changed

tests/Datasets/GitLogsDataset.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
dataset('lastCommitLogText', [
4-
'default git log' => sprintf('commit %s
4+
'Default Git Log' => sprintf('commit %s
55
Author: Igor Moraes <[email protected]>
66
Date: Wed Nov 9 04:50:40 2022 -0800
77
@@ -10,7 +10,7 @@
1010
]);
1111

1212
dataset('mergeLogText', [
13-
'merge git log' => sprintf("commit %s
13+
'Merge Git Log' => sprintf("commit %s
1414
Merge: 123abc 456def
1515
Author: Igor Moraes <[email protected]>
1616
Date: Wed Nov 9 04:50:40 2022 -0800
@@ -21,9 +21,9 @@
2121
]);
2222

2323
dataset('listOfChangedFiles', [
24-
'list of changed files' => 'AM src/ChangedFiles.php',
24+
'List Of Changed Files' => 'AM src/ChangedFiles.php',
2525
]);
2626

2727
dataset('listOfFixableFiles', [
28-
'list of fixable files' => 'AM temp/ClassWithFixableIssues.php',
28+
'List of Fixable Files' => 'AM temp/ClassWithFixableIssues.php',
2929
]);

tests/Datasets/ModifiedFilesDataset.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22

33
dataset('modifiedFilesMeta', [
4-
'empty log' => [
4+
'Empty Log' => [
55
'',
66
false,
77
false,
@@ -10,7 +10,7 @@
1010
false,
1111
false,
1212
],
13-
'added and modified files' => [
13+
'Added and Modified Files' => [
1414
'AM src/ChangedFiles.php',
1515
true,
1616
true,
@@ -19,7 +19,7 @@
1919
true,
2020
true,
2121
],
22-
'modified file' => [
22+
'Modified File' => [
2323
' M src/Console/Commands/CommitMessage.php',
2424
false,
2525
true,
@@ -28,7 +28,7 @@
2828
false,
2929
true,
3030
],
31-
'deleted file' => [
31+
'Deleted File' => [
3232
' D LICENSE',
3333
false,
3434
false,
@@ -37,7 +37,7 @@
3737
false,
3838
false,
3939
],
40-
'untracked file' => [
40+
'Untracked File' => [
4141
'?? LICENSE',
4242
false,
4343
false,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
dataset('pintConfigurations', [
4+
'Config File' => [
5+
[
6+
'path' => '../../../bin/pint',
7+
'config' => __DIR__.'/../Fixtures/pintFixture.json',
8+
],
9+
],
10+
'Preset' => [
11+
[
12+
'path' => '../../../bin/pint',
13+
'preset' => 'psr12',
14+
],
15+
],
16+
]);

tests/Features/Commands/Hooks/PintPreCommitHookTest.php

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,22 @@
3939
expect($result)->toBe('passed');
4040
})->with('modifiedFilesList');
4141

42+
test('Skips Pint check when there is none php files added to commit', function ($pintConfiguration) {
43+
$this->config->set('git-hooks.code_analyzers.laravel_pint', $pintConfiguration);
44+
$this->config->set('git-hooks.pre-commit', [
45+
PintPreCommitHook::class,
46+
]);
47+
48+
$this->makeTempFile('sample.js',
49+
file_get_contents(__DIR__.'/../../../Fixtures/sample.js')
50+
);
51+
52+
GitHooks::shouldReceive('isMergeInProgress')->andReturn(false);
53+
GitHooks::shouldReceive('getListOfChangedFiles')->andReturn('AM src/sample.js');
54+
55+
$this->artisan('git-hooks:pre-commit')->assertSuccessful();
56+
})->with('pintConfigurations');
57+
4258
test('Throws HookFailException and notifies when Pint is not installed', function ($listOfFixableFiles) {
4359
$this->config->set('git-hooks.code_analyzers.laravel_pint', [
4460
'path' => 'inexistent/path/to/pint',
@@ -54,13 +70,10 @@
5470
$this->artisan('git-hooks:pre-commit')
5571
->expectsOutputToContain('Pint is not installed.')
5672
->assertExitCode(1);
57-
})->with('listOfFixableFiles');
73+
})->with('listOfFixableFiles', 'pintConfigurations');
5874

59-
test('Fails commit when Pint is not passing and user does not autofix the files', function ($listOfFixableFiles) {
60-
$this->config->set('git-hooks.code_analyzers.laravel_pint', [
61-
'path' => '../../../bin/pint',
62-
'preset' => 'psr12',
63-
]);
75+
test('Fails commit when Pint is not passing and user does not autofix the files', function ($pintConfiguration, $listOfFixableFiles) {
76+
$this->config->set('git-hooks.code_analyzers.laravel_pint', $pintConfiguration);
6477
$this->config->set('git-hooks.pre-commit', [
6578
PintPreCommitHook::class,
6679
]);
@@ -77,13 +90,10 @@
7790
->expectsOutputToContain('COMMIT FAILED')
7891
->expectsConfirmation('Would you like to attempt to correct files automagically?', 'no')
7992
->assertExitCode(1);
80-
})->with('listOfFixableFiles');
93+
})->with('pintConfigurations', 'listOfFixableFiles');
8194

82-
test('Commit passes when Pint fixes fix the files', function ($listOfFixableFiles) {
83-
$this->config->set('git-hooks.code_analyzers.laravel_pint', [
84-
'path' => '../../../bin/pint',
85-
'preset' => 'psr12',
86-
]);
95+
test('Commit passes when Pint fixes fix the files', function ($pintConfiguration, $listOfFixableFiles) {
96+
$this->config->set('git-hooks.code_analyzers.laravel_pint', $pintConfiguration);
8797
$this->config->set('git-hooks.pre-commit', [
8898
PintPreCommitHook::class,
8999
]);
@@ -103,4 +113,4 @@
103113
$this->artisan('git-hooks:pre-commit')
104114
->doesntExpectOutputToContain('Pint Failed')
105115
->assertSuccessful();
106-
})->with('listOfFixableFiles');
116+
})->with('pintConfigurations', 'listOfFixableFiles');

tests/Fixtures/pintFixture.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"preset": "psr12"
3+
}

tests/Fixtures/sample.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("Hello, world!");

0 commit comments

Comments
 (0)