Skip to content

Commit 88576f5

Browse files
authored
Revert "Pest Tests and Improvements"
1 parent 321ee6b commit 88576f5

Some content is hidden

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

57 files changed

+1251
-1237
lines changed

composer.json

Lines changed: 12 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,20 +22,18 @@
2222
],
2323
"require": {
2424
"php": "^7.2|^8.0",
25-
"illuminate/config": "^6.0|^7.0|^8.0|^9.0",
26-
"illuminate/console": "^6.0|^7.0|^8.0|^9.0",
27-
"illuminate/container": "^6.0|^7.0|^8.0|^9.0",
28-
"illuminate/contracts": "^6.0|^7.0|^8.0|^9.0",
29-
"illuminate/pipeline": "^6.0|^7.0|^8.0|^9.0",
30-
"illuminate/support": "^6.0|^7.0|^8.0|^9.0"
25+
"illuminate/container": "^5.6|^6.0|^7.0|^8.0|^9.0",
26+
"illuminate/config": "^5.6|^6.0|^7.0|^8.0|^9.0",
27+
"illuminate/support": "^5.6|^6.0|^7.0|^8.0|^9.0",
28+
"illuminate/contracts": "^5.6|^6.0|^7.0|^8.0|^9.0",
29+
"illuminate/console": "^5.6|^6.0|^7.0|^8.0|^9.0",
30+
"illuminate/pipeline": "^5.6|^6.0|^7.0|^8.0|^9.0"
3131
},
3232
"require-dev": {
33-
"laravel/pint": "^1.2",
34-
"mockery/mockery": "^1.5.1",
35-
"orchestra/testbench": "^7.0",
36-
"pestphp/pest": "^1.22",
37-
"pestphp/pest-plugin-mock": "^1.0",
38-
"phpunit/phpunit": "^9.0"
33+
"orchestra/testbench": "^6.0",
34+
"phpunit/phpunit": "^9.0",
35+
"mockery/mockery": "^1.4.4",
36+
"laravel/pint": "^1.2"
3937
},
4038
"autoload": {
4139
"psr-4": {
@@ -52,18 +50,15 @@
5250
"test-coverage": "vendor/bin/phpunit --coverage-html coverage"
5351
},
5452
"config": {
55-
"sort-packages": true,
56-
"allow-plugins": {
57-
"pestphp/pest-plugin": true
58-
}
53+
"sort-packages": true
5954
},
6055
"extra": {
6156
"laravel": {
6257
"providers": [
6358
"Igorsgm\\GitHooks\\GitHooksServiceProvider"
6459
],
6560
"aliases": {
66-
"GitHooks": "Igorsgm\\GitHooks\\Facades\\GitHooks"
61+
"GitHooks": "Igorsgm\\GitHooks\\GitHooksFacade"
6762
}
6863
}
6964
},

config/git-hooks.php

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,6 @@
7878
| Pre-Rebase Hooks
7979
|-----------------------------------------------------------------
8080
|
81-
| @TODO Implement support to pre-rebase hooks
82-
|
8381
| The pre-rebase hook runs before you rebase anything and can halt the process by exiting non-zero.
8482
| You can use this hook to disallow rebasing any commits that have already been pushed.
8583
| The example pre-rebase hook that Git installs does this, although it makes some assumptions that may not
@@ -95,8 +93,6 @@
9593
| Post-Rewrite Hooks
9694
|-----------------------------------------------------------------
9795
|
98-
| @TODO Implement support to post-rewrite hook
99-
|
10096
| The post-rewrite hook is run by commands that replace commits, such as git commit --amend and git rebase
10197
| (though not by git filter-branch). Its single argument is which command triggered the rewrite, and it receives
10298
| a list of rewrites on stdin. This hook has many of the same uses as the post-checkout and post-merge hooks.
@@ -111,8 +107,6 @@
111107
| Post-Checkout Hooks
112108
|-----------------------------------------------------------------
113109
|
114-
| @TODO Implement support to post-checkout hook
115-
|
116110
| After you run a successful git checkout, the post-checkout hook runs; you can use it to set up your working
117111
| directory properly for your project environment. This may mean moving in large binary files that you don't want
118112
| source controlled, auto-generating documentation, or something along those lines.
@@ -127,13 +121,10 @@
127121
| Post-Merge Hooks
128122
|-----------------------------------------------------------------
129123
|
130-
| @TODO Implement support to post-merge hook
131-
|
132124
| The post-merge hook runs after a successful merge command. You can use it to restore data in the working tree
133125
| that Git can't track, such as permissions data. This hook can likewise validate the presence of files external
134126
| to Git control that you may want copied in when the working tree changes.
135127
|
136-
|
137128
*/
138129
'post-merge' => [
139130

phpunit.xml

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,23 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
3+
backupGlobals="false"
4+
backupStaticAttributes="false"
45
bootstrap="vendor/autoload.php"
56
colors="true"
6-
>
7-
<testsuites>
8-
<testsuite name="Test Suite">
9-
<directory suffix="Test.php">./tests</directory>
10-
</testsuite>
11-
</testsuites>
12-
<coverage processUncoveredFiles="true">
7+
convertErrorsToExceptions="true"
8+
convertNoticesToExceptions="true"
9+
convertWarningsToExceptions="true"
10+
processIsolation="false"
11+
stopOnFailure="false"
12+
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd">
13+
<coverage>
1314
<include>
14-
<directory suffix=".php">./app</directory>
1515
<directory suffix=".php">./src</directory>
1616
</include>
1717
</coverage>
18+
<testsuites>
19+
<testsuite name="Unit">
20+
<directory suffix="Test.php">./tests</directory>
21+
</testsuite>
22+
</testsuites>
1823
</phpunit>

src/Console/Commands/PreCommit.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44

55
use Igorsgm\GitHooks\Contracts\HookCommand;
66
use Igorsgm\GitHooks\Exceptions\HookFailException;
7-
use Igorsgm\GitHooks\Facades\GitHooks;
87
use Igorsgm\GitHooks\Git\ChangedFiles;
8+
use Igorsgm\GitHooks\Git\GitHelper;
99
use Igorsgm\GitHooks\Traits\WithPipeline;
1010
use Illuminate\Console\Command;
1111

@@ -45,7 +45,7 @@ public function handle()
4545
try {
4646
$this->sendChangedFilesThroughHooks(
4747
new ChangedFiles(
48-
GitHooks::getListOfChangedFiles()
48+
GitHelper::getListOfChangedFiles()
4949
)
5050
);
5151
} catch (HookFailException $e) {

src/Console/Commands/RegisterHooks.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ class RegisterHooks extends Command
1212
*
1313
* @var string
1414
*/
15-
protected $signature = 'git-hooks:register';
15+
protected $signature = 'git-hooks:register-hooks';
1616

1717
/**
1818
* The console command description.
1919
*
2020
* @var string
2121
*/
22-
protected $description = 'Register or re-register git hooks for application';
22+
protected $description = 'Register git hooks for application';
2323

2424
/**
2525
* Execute the console command.
@@ -37,6 +37,6 @@ public function handle(GitHooks $gitHooks)
3737
$gitHooks->install($hook);
3838
}
3939

40-
$this->info('Git hooks have been successfully installed.');
40+
$this->info('Git hooks have been successfully created');
4141
}
4242
}

src/Traits/GitHelper.php renamed to src/Git/GitHelper.php

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

3-
namespace Igorsgm\GitHooks\Traits;
3+
namespace Igorsgm\GitHooks\Git;
44

5+
use Igorsgm\GitHooks\Traits\ProcessHelper;
56
use Symfony\Component\Process\Exception\ProcessFailedException;
67

7-
trait GitHelper
8+
class GitHelper
89
{
910
use ProcessHelper;
1011

1112
/**
1213
* @return string
1314
*/
14-
public function getListOfChangedFiles()
15+
public static function getListOfChangedFiles()
1516
{
16-
return $this->runCommandAndGetOutput('git status --short');
17+
return self::execAndGetCommandOutput('git status --short');
1718
}
1819

1920
/**
2021
* @return string
2122
*/
22-
public function getLastCommitFromLog()
23+
public static function getLastCommitFromLog()
2324
{
24-
return $this->runCommandAndGetOutput('git log -1 HEAD');
25+
return self::execAndGetCommandOutput('git log -1 HEAD');
2526
}
2627

2728
/**
2829
* @param string|array $commands
2930
* @return string
3031
*/
31-
private function runCommandAndGetOutput($commands)
32+
private static function execAndGetCommandOutput($commands)
3233
{
33-
$process = $this->runCommands($commands);
34+
$process = self::execCommands($commands);
3435

3536
if (! $process->isSuccessful()) {
3637
throw new ProcessFailedException($process);
@@ -45,7 +46,7 @@ private function runCommandAndGetOutput($commands)
4546
* @param string $filePath
4647
* @return string
4748
*/
48-
public function getCommitMessageContentFromFile(string $filePath): string
49+
public static function getCommitMessageContentFromFile(string $filePath): string
4950
{
5051
return file_get_contents($filePath);
5152
}
@@ -56,7 +57,7 @@ public function getCommitMessageContentFromFile(string $filePath): string
5657
* @param string $path
5758
* @param string $message
5859
*/
59-
public function updateCommitMessageContentInFile(string $path, string $message): void
60+
public static function updateCommitMessageContentInFile(string $path, string $message): void
6061
{
6162
file_put_contents($path, $message);
6263
}

src/GitHooks.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
namespace Igorsgm\GitHooks;
44

55
use Exception;
6-
use Igorsgm\GitHooks\Traits\GitHelper;
76

87
class GitHooks
98
{
10-
use GitHelper;
11-
129
/**
1310
* Get all supported git hooks
1411
*/

src/Facades/GitHooks.php renamed to src/GitHooksFacade.php

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

3-
namespace Igorsgm\GitHooks\Facades;
3+
namespace Igorsgm\GitHooks;
44

55
use Illuminate\Support\Facades\Facade;
66

77
/**
88
* @see \Igorsgm\GitHooks\GitHooks
99
*/
10-
class GitHooks extends Facade
10+
class GitHooksFacade extends Facade
1111
{
1212
/**
1313
* Get the registered name of the component.

src/HooksPipeline.php

Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@ class HooksPipeline extends Pipeline
1212
/**
1313
* @var Closure
1414
*/
15-
protected $pipeStartCallback;
15+
protected $callback;
1616

1717
/**
1818
* @var Closure
1919
*/
20-
protected $pipeEndCallback;
20+
protected $exceptionCallback;
2121

2222
/**
2323
* @var string
@@ -38,9 +38,9 @@ public function __construct(Container $container, string $hook)
3838
* @param Closure $callback
3939
* @return $this
4040
*/
41-
public function withPipeStartCallback(Closure $callback)
41+
public function withCallback(Closure $callback)
4242
{
43-
$this->pipeStartCallback = $callback;
43+
$this->callback = $callback;
4444

4545
return $this;
4646
}
@@ -49,9 +49,9 @@ public function withPipeStartCallback(Closure $callback)
4949
* @param Closure $callback
5050
* @return $this
5151
*/
52-
public function withPipeEndCallback(Closure $callback)
52+
public function withExceptionCallback(Closure $callback)
5353
{
54-
$this->pipeEndCallback = $callback;
54+
$this->exceptionCallback = $callback;
5555

5656
return $this;
5757
}
@@ -79,10 +79,8 @@ protected function carry()
7979
// execute the pipe function giving in the parameters that are required.
8080
$pipe = $this->getContainer()->make($pipe, ['parameters' => $hookParameters]);
8181

82-
$this->handlePipeEnd(true);
83-
84-
if ($this->pipeStartCallback) {
85-
call_user_func_array($this->pipeStartCallback, [$pipe]);
82+
if ($this->callback) {
83+
call_user_func_array($this->callback, [$pipe]);
8684
}
8785

8886
$parameters = [$passable, $stack];
@@ -94,8 +92,8 @@ protected function carry()
9492
}
9593

9694
$carry = method_exists($pipe, $this->method)
97-
? $pipe->{$this->method}(...$parameters)
98-
: $pipe(...$parameters);
95+
? $pipe->{$this->method}(...$parameters)
96+
: $pipe(...$parameters);
9997

10098
return $this->handleCarry($carry);
10199
} catch (Throwable $e) {
@@ -106,43 +104,13 @@ protected function carry()
106104
}
107105

108106
/**
109-
* Handle the call back call once a specific pipe has finished or errored.
110-
*
111-
* @param bool $success
112-
* @return void
107+
* {@inheritDoc}
113108
*/
114-
protected function handlePipeEnd($success)
109+
protected function handleException($passable, $e)
115110
{
116-
if ($this->pipeEndCallback) {
117-
call_user_func_array($this->pipeEndCallback, [$success]);
111+
if ($this->exceptionCallback) {
112+
return call_user_func_array($this->exceptionCallback, [$e]);
118113
}
119-
}
120-
121-
/**
122-
* Handle the value returned from each pipe before passing it to the next.
123-
*
124-
* @param mixed $carry
125-
* @return mixed
126-
*/
127-
protected function handleCarry($carry)
128-
{
129-
$this->handlePipeEnd(true);
130-
131-
return $carry;
132-
}
133-
134-
/**
135-
* Handle the given exception.
136-
*
137-
* @param mixed $passable
138-
* @param \Throwable $e
139-
* @return mixed
140-
*
141-
* @throws \Throwable
142-
*/
143-
protected function handleException($passable, Throwable $e)
144-
{
145-
$this->handlePipeEnd(false);
146114

147115
throw $e;
148116
}

0 commit comments

Comments
 (0)