Skip to content

Commit 27162bc

Browse files
committed
- Remove the use of Laravel's basePath() method in favor of Laravel base_path function.
- Replace calls to ->getLaravel() with app()
1 parent aa3cb42 commit 27162bc

File tree

7 files changed

+8
-51
lines changed

7 files changed

+8
-51
lines changed

src/Traits/WithCommitMessage.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ public function handle()
3131
{
3232
$file = $this->argument('file');
3333

34-
$message = $this->messageStorage->get(
35-
$this->getLaravel()->basePath($file)
36-
);
34+
$message = $this->messageStorage->get(base_path($file));
3735

3836
try {
3937
$this->sendMessageThroughHooks(
@@ -58,7 +56,7 @@ private function getMessagePath(): string
5856
{
5957
$file = $this->argument('file');
6058

61-
return $this->getLaravel()->basePath($file);
59+
return base_path($file);
6260
}
6361

6462
/**

src/Traits/WithPipeline.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@ trait WithPipeline
1717
*/
1818
protected function makePipeline(): Pipeline
1919
{
20-
$pipeline = new HooksPipeline(
21-
$this->getLaravel(),
22-
$this->getHook()
23-
);
20+
$pipeline = new HooksPipeline(app(), $this->getHook());
2421

2522
return $pipeline
2623
->through($this->getRegisteredHooks())
27-
->withCallback($this->showInfoAboutHook())
28-
->withExceptionCallback($this->showHookErrorAndExit());
24+
->withCallback($this->showInfoAboutHook());
25+
// ->withExceptionCallback($this->showHookErrorAndExit());
2926
}
3027

3128
/**

tests/Console/Commands/CommitMessageTest.php

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@ public function test_requires_file_argument()
3434

3535
public function test_a_message_should_be_send_through_the_hook_pipes()
3636
{
37-
$app = $this->makeApplication();
38-
$app->allows('basePath')->andReturnUsing(function ($path = null) {
39-
return $path;
40-
});
41-
42-
$app->allows('make')->andReturnUsing(function ($class) {
43-
return new $class;
44-
});
45-
4637
Config::set('git-hooks', [
4738
'commit-msg' => [
4839
CommitMessageTestHook1::class,
@@ -58,12 +49,10 @@ public function test_a_message_should_be_send_through_the_hook_pipes()
5849

5950
$commitMessageStorage
6051
->expects('update')
61-
->with('tmp/COMMIT_MESSAGE', 'Test commit hook1 hook2');
52+
->with(base_path('tmp/COMMIT_MESSAGE'), 'Test commit hook1 hook2');
6253

6354
$command = new CommitMessage($commitMessageStorage);
6455

65-
$command->setLaravel($app);
66-
6756
$input = Mockery::mock(\Symfony\Component\Console\Input\InputInterface::class);
6857
$input->allows('getArgument')
6958
->with('file')
@@ -90,15 +79,6 @@ public function test_a_message_should_be_send_through_the_hook_pipes()
9079

9180
public function test_pass_hook_config_into_hook_object()
9281
{
93-
$app = $this->makeApplication();
94-
$app->allows('make')->andReturnUsing(function ($class, array $parameters = []) {
95-
return new $class(...array_values($parameters));
96-
});
97-
98-
$app->allows('basePath')->andReturnUsing(function ($path = null) {
99-
return $path;
100-
});
101-
10282
Config::set('git-hooks', [
10383
'commit-msg' => [
10484
CommitMessageTestHook4::class => [
@@ -116,12 +96,10 @@ public function test_pass_hook_config_into_hook_object()
11696

11797
$commitMessageStorage
11898
->expects('update')
119-
->with('tmp/COMMIT_MESSAGE', 'Test commit hello world');
99+
->with(base_path('tmp/COMMIT_MESSAGE'), 'Test commit hello world');
120100

121101
$command = new CommitMessage($commitMessageStorage);
122102

123-
$command->setLaravel($app);
124-
125103
$input = Mockery::mock(\Symfony\Component\Console\Input\InputInterface::class);
126104
$input->allows('getArgument')
127105
->with('file')

tests/Console/Commands/PostCommitTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ public function test_a_message_should_be_send_through_the_hook_pipes()
4545
],
4646
]);
4747

48-
$app = $this->makeApplication();
4948
$command = new PostCommit();
50-
$command->setLaravel($app);
5149

5250
$gitHelper = Mockery::mock('alias:'.GitHelper::class);
5351
$gitHelper->expects('getLastCommitFromLog')

tests/Console/Commands/PreCommitTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,9 +46,7 @@ public function test_a_message_should_be_send_through_the_hook_pipes()
4646
],
4747
]);
4848

49-
$app = $this->makeApplication();
5049
$command = new PreCommit();
51-
$command->setLaravel($app);
5250

5351
$gitHelper = Mockery::mock('alias:'.GitHelper::class);
5452
$gitHelper->expects('getListOfChangedFiles')->andReturns('AM src/ChangedFiles.php');

tests/Console/Commands/PrePushTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ public function test_a_message_should_be_send_through_the_hook_pipes()
4545
],
4646
]);
4747

48-
$app = $this->makeApplication();
4948
$command = new PrePush();
50-
$command->setLaravel($app);
5149

5250
$gitHelper = Mockery::mock('alias:'.GitHelper::class);
5351
$gitHelper->expects('getLastCommitFromLog')

tests/Console/Commands/PrepareCommitMessageTest.php

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,6 @@ public function test_requires_file_argument()
3434

3535
public function test_a_message_should_be_send_through_the_hook_pipes()
3636
{
37-
$app = $this->makeApplication();
38-
$app->allows('basePath')->andReturnUsing(function ($path = null) {
39-
return $path;
40-
});
41-
42-
$app->allows('make')->andReturnUsing(function ($class) {
43-
return new $class;
44-
});
45-
4637
Config::set('git-hooks', [
4738
'prepare-commit-msg' => [
4839
PrepareCommitMessageTestHook1::class,
@@ -58,7 +49,7 @@ public function test_a_message_should_be_send_through_the_hook_pipes()
5849

5950
$commitMessageStorage
6051
->expects('update')
61-
->with('tmp/COMMIT_MESSAGE', 'Test commit hook1 hook2');
52+
->with(base_path('tmp/COMMIT_MESSAGE'), 'Test commit hook1 hook2');
6253

6354
$command = new PrepareCommitMessage($commitMessageStorage);
6455

@@ -68,7 +59,6 @@ public function test_a_message_should_be_send_through_the_hook_pipes()
6859
->with('file')
6960
->andReturns('tmp/COMMIT_MESSAGE');
7061

71-
$command->setLaravel($app);
7262
$command->setInput($input);
7363

7464
$output = Mockery::mock(OutputStyle::class);

0 commit comments

Comments
 (0)