Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,24 @@ jobs:
include:
- php: 8.0
buildphar: false
runtests: false
experimental: false
- php: 8.1
buildphar: false
runtests: true
experimental: false
- php: 8.2
buildphar: true
runtests: true
experimental: false
- php: 8.3
buildphar: true
runtests: true
experimental: false
- php: 8.4
buildphar: true
experimental: true
runtests: false
experimental: false
env:
PHAR: build/phar/captainhook.phar

Expand Down Expand Up @@ -54,12 +59,15 @@ jobs:
run: GITHUB_AUTH_TOKEN=${{ secrets.GITHUB_TOKEN }} tools/phive --no-progress --home ./.phive install --force-accept-unsigned --trust-gpg-keys 4AA394086372C20A,31C7E470E2138192,8E730BA25823D8B5,CF1A108D0E7AE720,2DF45277AEF09A2F,51C67305FFC2E5C0

- name: Execute unit tests
if: ${{ matrix.runtests }}
run: tools/phpunit --no-coverage --testsuite UnitTests

- name: Execute integration tests
if: ${{ matrix.runtests }}
run: tools/phpunit --no-coverage --testsuite IntegrationTests

- name: Execute end-to-end tests
if: ${{ matrix.runtests }}
run: tools/phpunit --no-coverage --testsuite EndToEndTests

- name: Execute dummy pre commit
Expand Down
6 changes: 3 additions & 3 deletions phive.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<phive xmlns="https://phar.io/phive">
<phar name="phpunit" version="^9.4" installed="9.6.23" location="./tools/phpunit" copy="true"/>
<phar name="humbug/box" version="^4.0" installed="4.6.6" location="./tools/box" copy="true"/>
<phar name="phpunit" version="^10.0" installed="10.5.58" location="./tools/phpunit" copy="true"/>
<phar name="humbug/box" version="^4.0" installed="4.6.8" location="./tools/box" copy="true"/>
<phar name="phpcs" version="^3.5" installed="3.7.2" location="./tools/phpcs" copy="true"/>
<phar name="phpstan" version="^1.0" installed="1.12.28" location="./tools/phpstan" copy="true"/>
<phar name="phpstan" version="^1.0" installed="1.12.32" location="./tools/phpstan" copy="true"/>
</phive>
16 changes: 10 additions & 6 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
colors="true"
bootstrap="tests/bootstrap.php"
defaultTestSuite="UnitTests">
defaultTestSuite="UnitTests"
displayDetailsOnPhpunitDeprecations="true"
displayDetailsOnTestsThatTriggerDeprecations="true"
displayDetailsOnTestsThatTriggerWarnings="true">
<coverage>
<include>
<directory>src</directory>
</include>
<report>
<clover outputFile="build/logs/clover.xml"/>
<html outputDirectory="build/coverage" lowUpperBound="35" highLowerBound="70"/>
Expand All @@ -27,4 +26,9 @@
<logging>
<junit outputFile="build/logs/junit.xml"/>
</logging>
<source>
<include>
<directory>src</directory>
</include>
</source>
</phpunit>
7 changes: 5 additions & 2 deletions src/Config/Factory.php
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,12 @@ private function loadConfigFromFile(Json $file, array $settings): Config

$this->appendIncludedConfigurations($config, $json);

// fallback to $json->HOOK_NAME if $json->HOOKS->HOOK_NAME does not exist
$hooks = $json['hooks'] ?? $json;

foreach (HookUtil::getValidHooks() as $hook => $class) {
if (isset($json[$hook])) {
$this->configureHook($config->getHookConfig($hook), $json[$hook]);
if (isset($hooks[$hook])) {
$this->configureHook($config->getHookConfig($hook), $hooks[$hook]);
}
}

Expand Down
3 changes: 2 additions & 1 deletion tests/_files/bootstrap/crash.php
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<?php

require 'foo.txt';
// I know ugly but I want this to crash
@require 'foo.txt';
6 changes: 0 additions & 6 deletions tests/unit/Config/ConditionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,13 @@

class ConditionTest extends TestCase
{
/**
* Tests Condition::getExec
*/
public function testGetExec(): void
{
$config = new Condition('\\Foo\\Bar');

$this->assertEquals('\\Foo\\Bar', $config->getExec());
}

/**
* Tests Condition::getArgs
*/
public function testGetEmptyArgs(): void
{
$config = new Condition('\\Foo\\Bar');
Expand Down
91 changes: 0 additions & 91 deletions tests/unit/Config/FactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@

class FactoryTest extends TestCase
{
/**
* Tests Factory::create
*
* @throws \Exception
*/
public function testCreate(): void
{
$config = Factory::create(realpath(CH_PATH_FILES . '/config/valid.json'));
Expand All @@ -29,23 +24,13 @@ public function testCreate(): void
$this->assertCount(1, $config->getHookConfig('pre-commit')->getActions());
}

/**
* Tests Factory::create
*
* @throws \Exception
*/
public function testOverwriteConfigSettingsBySettingsConfigFile(): void
{
$config = Factory::create(realpath(CH_PATH_FILES . '/config/config-file/captainhook.json'));

$this->assertEquals('quiet', $config->getVerbosity());
}

/**
* Tests Factory::create
*
* @throws \Exception
*/
public function testCreateWithAbsoluteGitDir(): void
{
$config = Factory::create(
Expand All @@ -58,11 +43,6 @@ public function testCreateWithAbsoluteGitDir(): void
$this->assertEquals('/foo', $config->getGitDirectory());
}

/**
* Tests Factory::create
*
* @throws \Exception
*/
public function testCreateWithInvalidPhpPath(): void
{
$this->expectException(Exception::class);
Expand All @@ -73,11 +53,6 @@ public function testCreateWithInvalidPhpPath(): void
);
}

/**
* Tests Factory::create
*
* @throws \Exception
*/
public function testCreateWithRelativeGitDir(): void
{
$path = realpath(CH_PATH_FILES . '/config/valid.json');
Expand All @@ -88,9 +63,6 @@ public function testCreateWithRelativeGitDir(): void
$this->assertEquals(dirname($path) . DIRECTORY_SEPARATOR . '../.git', $config->getGitDirectory());
}

/**
* Tests Factory::create
*/
public function testCreateWithRunConfig(): void
{
$path = realpath(CH_PATH_FILES . '/config/valid-run-config-nested.json');
Expand All @@ -101,9 +73,6 @@ public function testCreateWithRunConfig(): void
$this->assertEquals('/docker/.git', $config->getRunConfig()->getGitPath());
}

/**
* Tests Factory::create
*/
public function testCreateWithRunConfigLegacy(): void
{
$path = realpath(CH_PATH_FILES . '/config/valid-run-config-legacy.json');
Expand All @@ -114,11 +83,6 @@ public function testCreateWithRunConfigLegacy(): void
$this->assertEquals('/docker/.git', $config->getRunConfig()->getGitPath());
}

/**
* Tests Factory::create
*
* @throws \Exception
*/
public function testCreateWithConditions(): void
{
$config = Factory::create(realpath(CH_PATH_FILES . '/config/valid-with-conditions.json'));
Expand All @@ -127,35 +91,20 @@ public function testCreateWithConditions(): void
$this->assertCount(1, $config->getHookConfig('pre-commit')->getActions());
}

/**
* Tests Factory::create
*
* @throws \Exception
*/
public function testCreateWithSettings(): void
{
$config = Factory::create(realpath(CH_PATH_FILES . '/config/valid-with-conditions.json'));

$this->assertTrue($config->getHookConfig('pre-commit')->getActions()[0]->isFailureAllowed());
}

/**
* Tests Factory::create
*
* @throws \Exception
*/
public function testCreateWithCrazyPHPPath(): void
{
$config = Factory::create(realpath(CH_PATH_FILES . '/config/valid-with-strange-settings.json'));

$this->assertEquals("tests/_files/bin/success foo", $config->getPhpPath());
}

/**
* Tests Factory::create
*
* @throws \Exception
*/
public function testCreateWithAllSetting(): void
{
$path = realpath(CH_PATH_FILES . '/config/valid-with-all-settings.json');
Expand All @@ -172,11 +121,6 @@ public function testCreateWithAllSetting(): void
$this->assertEquals(false, $config->failOnFirstError());
}

/**
* Tests Factory::create
*
* @throws \Exception
*/
public function testCreateWithIncludes(): void
{
$config = Factory::create(realpath(CH_PATH_FILES . '/config/valid-with-includes.json'));
Expand All @@ -185,11 +129,6 @@ public function testCreateWithIncludes(): void
$this->assertCount(2, $config->getHookConfig('pre-commit')->getActions());
}

/**
* Tests Factory::create
*
* @throws \Exception
*/
public function testCreateWithValidNestedIncludes(): void
{
$config = Factory::create(realpath(CH_PATH_FILES . '/config/valid-with-nested-includes.json'));
Expand All @@ -200,11 +139,6 @@ public function testCreateWithValidNestedIncludes(): void
$this->assertCount(2, $config->getHookConfig('pre-push')->getActions());
}

/**
* Tests Factory::create
*
* @throws \Exception
*/
public function testCreateWithInvalidNestedIncludes(): void
{
$config = Factory::create(realpath(CH_PATH_FILES . '/config/invalid-with-nested-includes.json'));
Expand All @@ -213,22 +147,12 @@ public function testCreateWithInvalidNestedIncludes(): void
$this->assertCount(2, $config->getHookConfig('pre-commit')->getActions());
}

/**
* Tests Factory::create
*
* @throws \Exception
*/
public function testCreateWithInvalidIncludes(): void
{
$this->expectException(Exception::class);
Factory::create(realpath(CH_PATH_FILES . '/config/valid-with-invalid-includes.json'));
}

/**
* Tests Factory::create
*
* @throws \Exception
*/
public function testCreateEmptyWithIncludes(): void
{
$config = Factory::create(realpath(CH_PATH_FILES . '/config/empty-with-includes.json'));
Expand All @@ -237,11 +161,6 @@ public function testCreateEmptyWithIncludes(): void
$this->assertCount(1, $config->getHookConfig('pre-commit')->getActions());
}

/**
* Tests Factory::create
*
* @throws \Exception
*/
public function testCreateWithNestedAndConditions(): void
{
$config = Factory::create(realpath(CH_PATH_FILES . '/config/valid-with-nested-and-conditions.json'));
Expand All @@ -250,23 +169,13 @@ public function testCreateWithNestedAndConditions(): void
$this->assertCount(1, $config->getHookConfig('pre-commit')->getActions());
}

/**
* Tests Factory::create
*
* @throws \Exception
*/
public function testWithMainConfigurationOverridingInclude(): void
{
$config = Factory::create(realpath(CH_PATH_FILES . '/config/valid-with-disabled-action.json'));

$this->assertFalse($config->getHookConfig('pre-commit')->isEnabled());
}

/**
* Tests Factory::create
*
* @throws \Exception
*/
public function testMaxIncludeLevel(): void
{
// one of the included files will not be loaded because of the includes-level value of 2
Expand Down
15 changes: 0 additions & 15 deletions tests/unit/Config/HookTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@

class HookTest extends TestCase
{
/**
* Tests Hook::__construct
*/
public function testDisabledByDefault(): void
{
$hook = new Hook('pre-commit');
Expand All @@ -27,9 +24,6 @@ public function testDisabledByDefault(): void
$this->assertFalse($config['enabled']);
}

/**
* Tests Hook::setEnabled
*/
public function testSetEnabled(): void
{
$hook = new Hook('pre-commit');
Expand All @@ -40,9 +34,6 @@ public function testSetEnabled(): void
$this->assertTrue($config['enabled']);
}

/**
* Tests Hook::__construct
*/
public function testEmptyActions(): void
{
$hook = new Hook('pre-commit');
Expand All @@ -52,9 +43,6 @@ public function testEmptyActions(): void
$this->assertCount(0, $config['actions']);
}

/**
* Tests Hook::addAction
*/
public function testAddAction(): void
{
$hook = new Hook('pre-commit');
Expand All @@ -65,9 +53,6 @@ public function testAddAction(): void
$this->assertCount(1, $config['actions']);
}

/**
* Tests Hook::addAction
*/
public function testAddMultiAction(): void
{
$hook = new Hook('pre-commit');
Expand Down
Loading