Skip to content

Commit c0d64ef

Browse files
Check for local actions only
Fixes issue #305
1 parent 2a7316b commit c0d64ef

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

src/Config.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ public function getJsonData(): array
398398
}
399399

400400
foreach (Hooks::getValidHooks() as $hook => $value) {
401-
if ($this->hooks[$hook]->hasActions()) {
401+
if ($this->hooks[$hook]->hasLocalActions()) {
402402
$data[$hook] = $this->hooks[$hook]->getJsonData();
403403
}
404404
}

src/Config/Hook.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,24 @@ public function hasActions(): bool
9696
return !empty($this->actions);
9797
}
9898

99+
/**
100+
* Check if a hook config has local actions that were not loaded from other config files
101+
*
102+
* @return bool
103+
*/
104+
public function hasLocalActions(): bool
105+
{
106+
if (!$this->hasActions()) {
107+
return false;
108+
}
109+
foreach ($this->actions as $action) {
110+
if (!$action->isIncluded()) {
111+
return true;
112+
}
113+
}
114+
return false;
115+
}
116+
99117
/**
100118
* Add an action to the list
101119
*

tests/unit/Config/HookTest.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,27 @@ public function testAddAction(): void
5353
$this->assertCount(1, $config['actions']);
5454
}
5555

56+
public function testCanDetermineIfItHasActionsThatWereNotIncluded(): void
57+
{
58+
$localAction = new Action('\\Foo\\Bar');
59+
$includedAction = new Action('\\Foo\\Bar');
60+
$includedAction->markIncluded();
61+
62+
$hook = new Hook('pre-commit');
63+
$hook->addAction($localAction, $includedAction);
64+
$this->assertTrue($hook->hasLocalActions());
65+
}
66+
67+
public function testCanDetermineIfItHasIncludedActionsOnly(): void
68+
{
69+
$includedAction = new Action('\\Foo\\Bar');
70+
$includedAction->markIncluded();
71+
72+
$hook = new Hook('pre-commit');
73+
$hook->addAction($includedAction);
74+
$this->assertFalse($hook->hasLocalActions());
75+
}
76+
5677
public function testAddMultiAction(): void
5778
{
5879
$hook = new Hook('pre-commit');

0 commit comments

Comments
 (0)