Skip to content

Commit 93ea2e4

Browse files
committed
- PostCommitTest implemented
- CommitMessageTest fixed - orchestra/testbench upgraded
1 parent b636c88 commit 93ea2e4

File tree

4 files changed

+37
-24
lines changed

4 files changed

+37
-24
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,8 @@
3131
},
3232
"require-dev": {
3333
"laravel/pint": "^1.2",
34-
"mockery/mockery": "^1.4.4",
35-
"orchestra/testbench": "^6.0",
34+
"mockery/mockery": "^1.5.1",
35+
"orchestra/testbench": "^7.0",
3636
"pestphp/pest": "^1.22",
3737
"pestphp/pest-plugin-mock": "^1.0",
3838
"phpunit/phpunit": "^9.0"

tests/Feature/CommitMessageTest.php

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
use Igorsgm\GitHooks\Tests\Fixtures\CommitMessageTestHook1;
55
use Igorsgm\GitHooks\Tests\Fixtures\CommitMessageTestHook2;
66
use Igorsgm\GitHooks\Tests\Fixtures\CommitMessageTestHook4;
7-
use Illuminate\Support\Facades\Artisan;
87

98
test('Commit Message is sent through HookPipes', function () {
109
$commitMessageHooks = [
@@ -25,15 +24,11 @@
2524
GitHooks::shouldReceive('updateCommitMessageContentInFile')
2625
->with(base_path($file), 'Test commit hook1 hook2');
2726

28-
$this->artisan('git-hooks:commit-msg', ['file' => $file]);
29-
30-
$output = Artisan::output();
27+
$command = $this->artisan('git-hooks:commit-msg', ['file' => $file])
28+
->assertExitCode(0);
3129

3230
foreach ($commitMessageHooks as $hook) {
33-
$this->assertStringContainsString(
34-
sprintf('Hook: %s...', resolve($hook)->getName()),
35-
$output
36-
);
31+
$command->expectsOutputToContain(sprintf('Hook: %s...', resolve($hook)->getName()));
3732
}
3833
});
3934

@@ -58,16 +53,11 @@
5853
GitHooks::shouldReceive('updateCommitMessageContentInFile')
5954
->with(base_path($file), 'Test commit hello world');
6055

61-
$this->artisan('git-hooks:commit-msg', ['file' => $file]);
62-
63-
$output = Artisan::output();
56+
$command = $this->artisan('git-hooks:commit-msg', ['file' => $file])
57+
->assertExitCode(0);
6458

6559
foreach ($commitMessageHooks as $hook => $parameters) {
6660
$hook = resolve($hook, compact('parameters'));
67-
68-
$this->assertStringContainsString(
69-
sprintf('Hook: %s...', $hook->getName()),
70-
$output
71-
);
61+
$command->expectsOutputToContain(sprintf('Hook: %s...', $hook->getName()));
7262
}
7363
});

tests/Feature/PostCommitTest.php

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+
$commitHash = 'b636c88159e121d0c8276c417576d57ebb380dc3';
9+
10+
$postCommitHook1 = mock(PostCommitHook::class)->expect(
11+
handle: fn(Log $log, Closure $closure) => expect($log->getHash())->toBe($commitHash)
12+
);
13+
$postCommitHook2 = clone $postCommitHook1;
14+
15+
$this->config->set('git-hooks.post-commit', [
16+
$postCommitHook1,
17+
$postCommitHook2,
18+
]);
19+
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+
");
27+
28+
$this->artisan('git-hooks:post-commit')->assertSuccessful();
29+
});

tests/TestCase.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,6 @@ class TestCase extends \Orchestra\Testbench\TestCase
1212
*/
1313
public $config;
1414

15-
protected function setUp(): void
16-
{
17-
parent::setUp();
18-
$this->withoutMockingConsoleOutput();
19-
}
20-
2115
/**
2216
* Define environment setup.
2317
*

0 commit comments

Comments
 (0)