File tree Expand file tree Collapse file tree 6 files changed +48
-18
lines changed Expand file tree Collapse file tree 6 files changed +48
-18
lines changed Original file line number Diff line number Diff line change 19
19
->andReturn ('Test commit ' );
20
20
21
21
GitHooks::shouldReceive ('getListOfChangedFiles ' )
22
- ->andReturn (' AM src/ChangedFiles.php ' );
22
+ ->andReturn (mockListOfChangedFiles () );
23
23
24
24
GitHooks::shouldReceive ('updateCommitMessageContentInFile ' )
25
25
->with (base_path ($ file ), 'Test commit hook1 hook2 ' );
48
48
->andReturn ('Test commit ' );
49
49
50
50
GitHooks::shouldReceive ('getListOfChangedFiles ' )
51
- ->andReturn (' AM src/ChangedFiles.php ' );
51
+ ->andReturn (mockListOfChangedFiles () );
52
52
53
53
GitHooks::shouldReceive ('updateCommitMessageContentInFile ' )
54
54
->with (base_path ($ file ), 'Test commit hello world ' );
Original file line number Diff line number Diff line change 5
5
use Igorsgm \GitHooks \Git \Log ;
6
6
7
7
test ('Git Log is sent through HookPipes ' , function () {
8
- $ commitHash = 'b636c88159e121d0c8276c417576d57ebb380dc3 ' ;
9
-
10
8
$ postCommitHook1 = mock (PostCommitHook::class)->expect (
11
- handle: fn (Log $ log , Closure $ closure ) => expect ($ log ->getHash ())->toBe ($ commitHash )
9
+ handle: fn (Log $ log , Closure $ closure ) => expect ($ log ->getHash ())->toBe (mockCommitHash () )
12
10
);
13
11
$ postCommitHook2 = clone $ postCommitHook1 ;
14
12
17
15
$ postCommitHook2 ,
18
16
]);
19
17
20
- GitHooks::shouldReceive ('getLastCommitFromLog ' )
21
- ->andReturn ("commit $ commitHash
22
- Author: Igor Moraes <[email protected] >
23
- Date: Wed Nov 9 04:50:40 2022 -0800
24
-
25
- wip
26
- " );
18
+ GitHooks::shouldReceive ('getLastCommitFromLog ' )->andReturn (mockLastCommitLog ());
27
19
28
20
$ this ->artisan ('git-hooks:post-commit ' )->assertSuccessful ();
29
21
});
Original file line number Diff line number Diff line change 6
6
use Igorsgm \GitHooks \Git \ChangedFiles ;
7
7
8
8
it ('sends ChangedFiles through HookPipes ' , function () {
9
- $ changedFilesString = 'AM src/ChangedFiles.php ' ;
10
-
11
9
$ preCommitHook1 = mock (PreCommitHook::class)->expect (
12
- handle: function (ChangedFiles $ files , Closure $ closure ) use ( $ changedFilesString ) {
10
+ handle: function (ChangedFiles $ files , Closure $ closure ) {
13
11
$ firstChangedFile = (string ) $ files ->getFiles ()->first ();
14
- expect ($ firstChangedFile )->toBe ($ changedFilesString );
12
+ expect ($ firstChangedFile )->toBe (mockListOfChangedFiles () );
15
13
}
16
14
);
17
15
$ preCommitHook2 = clone $ preCommitHook1 ;
21
19
$ preCommitHook2 ,
22
20
]);
23
21
24
- GitHooks::shouldReceive ('getListOfChangedFiles ' )->andReturn ($ changedFilesString );
22
+ GitHooks::shouldReceive ('getListOfChangedFiles ' )->andReturn (mockListOfChangedFiles () );
25
23
26
24
$ this ->artisan ('git-hooks:pre-commit ' )->assertSuccessful ();
27
25
});
Original file line number Diff line number Diff line change
1
+ <?php
2
+
3
+ use Igorsgm \GitHooks \Contracts \PostCommitHook ;
4
+ use Igorsgm \GitHooks \Facades \GitHooks ;
5
+ use Igorsgm \GitHooks \Git \Log ;
6
+
7
+ test ('Git Log is sent through HookPipes ' , function () {
8
+ $ prePushHook1 = mock (PostCommitHook::class)->expect (
9
+ handle: fn (Log $ log , Closure $ closure ) => expect ($ log ->getHash ())->toBe (mockCommitHash ())
10
+ );
11
+ $ prePushHook2 = clone $ prePushHook1 ;
12
+
13
+ $ this ->config ->set ('git-hooks.pre-push ' , [
14
+ $ prePushHook1 ,
15
+ $ prePushHook2 ,
16
+ ]);
17
+
18
+ GitHooks::shouldReceive ('getLastCommitFromLog ' )->andReturn (mockLastCommitLog ());
19
+
20
+ $ this ->artisan ('git-hooks:pre-push ' )->assertSuccessful ();
21
+ });
Original file line number Diff line number Diff line change 18
18
->andReturn ('Test commit ' );
19
19
20
20
GitHooks::shouldReceive ('getListOfChangedFiles ' )
21
- ->andReturn (' AM src/ChangedFiles.php ' );
21
+ ->andReturn (mockListOfChangedFiles () );
22
22
23
23
GitHooks::shouldReceive ('updateCommitMessageContentInFile ' )
24
24
->with (base_path ($ file ), 'Test commit hook1 hook2 ' );
Original file line number Diff line number Diff line change 41
41
| global functions to help you to reduce the number of lines of code in your test files.
42
42
|
43
43
*/
44
+ function mockCommitHash ()
45
+ {
46
+ return 'da39a3ee5e6b4b0d3255bfef95601890afd80709 ' ;
47
+ }
48
+
49
+ function mockListOfChangedFiles ()
50
+ {
51
+ return 'AM src/ChangedFiles.php ' ;
52
+ }
53
+
54
+ function mockLastCommitLog ()
55
+ {
56
+ return sprintf ('commit %s
57
+ Author: Igor Moraes <[email protected] >
58
+ Date: Wed Nov 9 04:50:40 2022 -0800
59
+
60
+ wip
61
+ ' , mockCommitHash ());
62
+ }
You can’t perform that action at this time.
0 commit comments