Skip to content

Commit

Permalink
Allow range of phpunit and fix grep issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Tofandel committed Jun 20, 2024
1 parent c9d2707 commit d743fbe
Show file tree
Hide file tree
Showing 9 changed files with 75 additions and 16 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"symfony/console": "^5.0|^6.0|^7.0"
},
"require-dev": {
"phpunit/phpunit": "^11",
"phpunit/phpunit": "^9|^10|^11",
"friendsofphp/php-cs-fixer": "^3.0",
"ext-json": "*"
},
Expand Down Expand Up @@ -57,7 +57,7 @@
"pre-commit": "composer check-style",
"pre-push": [
"composer test",
"appver=$(grep -o -E '\\d.\\d.\\d(-alpha.\\d)?' cghooks)",
"appver=$(grep -o -P '\\d+\\.\\d+\\.\\d+(-alpha\\.\\d+)?' cghooks)",
"tag=$(git tag | tail -n 1)",
"if [ \"$tag\" != \"v$appver\" ]; then",
"echo \"The most recent tag $tag does not match the application version $appver\\n\"",
Expand Down
20 changes: 6 additions & 14 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit backupGlobals="false"
backupStaticAttributes="false"
bootstrap="vendor/autoload.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" backupGlobals="false" bootstrap="vendor/autoload.php" colors="true" processIsolation="false" stopOnFailure="false" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/11.2/phpunit.xsd" cacheDirectory=".phpunit.cache" backupStaticProperties="false">
<testsuites>
<testsuite name="Application Test Suite">
<directory>./tests/</directory>
</testsuite>
</testsuites>
</phpunit>
27 changes: 27 additions & 0 deletions tests/AddCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use BrainMaestro\GitHooks\Commands\AddCommand;
use BrainMaestro\GitHooks\Hook;
use PHPUnit\Framework\Attributes\Group;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Console\Output\OutputInterface;
use PHPUnit\Framework\Attributes\Test;
Expand All @@ -17,6 +18,7 @@ public function init()
$this->commandTester = new CommandTester(new AddCommand());
}

/** @test */
#[Test]
public function it_adds_hooks_that_do_not_already_exist()
{
Expand All @@ -27,6 +29,7 @@ public function it_adds_hooks_that_do_not_already_exist()
}
}

/** @test */
#[Test]
public function it_doesnt_allow_to_add_custom_hooks_by_default()
{
Expand All @@ -44,6 +47,7 @@ public function it_doesnt_allow_to_add_custom_hooks_by_default()
);
}

/** @test */
#[Test]
public function it_allows_to_add_custom_hooks_specified_in_config_section()
{
Expand All @@ -69,6 +73,7 @@ public function it_allows_to_add_custom_hooks_specified_in_config_section()
);
}

/** @test */
#[Test]
public function it_adds_shebang_to_hooks_on_windows()
{
Expand All @@ -87,6 +92,7 @@ public function it_adds_shebang_to_hooks_on_windows()
}
}

/** @test */
#[Test]
public function it_does_not_add_hooks_that_already_exist()
{
Expand All @@ -100,6 +106,7 @@ public function it_does_not_add_hooks_that_already_exist()
$this->assertStringContainsString('No hooks were added. Try updating', $this->commandTester->getDisplay());
}

/** @test */
#[Test]
public function it_detects_existing_correct_hooks()
{
Expand All @@ -120,6 +127,7 @@ public function it_detects_existing_correct_hooks()
self::$hooks = $originalHooks;
}

/** @test */
#[Test]
public function it_overrides_hooks_that_already_exist()
{
Expand All @@ -131,6 +139,7 @@ public function it_overrides_hooks_that_already_exist()
}
}

/** @test */
#[Test]
public function it_correctly_creates_the_hook_lock_file()
{
Expand All @@ -146,6 +155,8 @@ public function it_correctly_creates_the_hook_lock_file()
* @test
* @group lock-dir
*/
#[Test]
#[Group('lock-dir')]
public function it_correctly_creates_the_hook_lock_file_in_lock_dir()
{
$lockDir = 'lock-dir';
Expand All @@ -163,6 +174,7 @@ public function it_correctly_creates_the_hook_lock_file_in_lock_dir()
self::rmdir('../' . $lockDir);
}

/** @test */
#[Test]
public function it_does_not_create_the_hook_lock_file_if_the_no_lock_option_is_passed()
{
Expand All @@ -173,6 +185,7 @@ public function it_does_not_create_the_hook_lock_file_if_the_no_lock_option_is_p
$this->assertFileDoesNotExist(Hook::LOCK_FILE);
}

/** @test */
#[Test]
public function it_does_not_ignore_the_hook_lock_file()
{
Expand All @@ -183,6 +196,7 @@ public function it_does_not_ignore_the_hook_lock_file()
$this->assertFalse(strpos(file_get_contents('.gitignore'), Hook::LOCK_FILE));
}

/** @test */
#[Test]
public function it_ignores_the_hook_lock_file_if_the_ignore_lock_option_is_passed()
{
Expand All @@ -192,6 +206,7 @@ public function it_ignores_the_hook_lock_file_if_the_ignore_lock_option_is_passe
$this->assertTrue(strpos(file_get_contents('.gitignore'), Hook::LOCK_FILE) !== false);
}

/** @test */
#[Test]
public function it_does_not_ignore_the_hook_lock_file_if_it_is_already_ignored()
{
Expand All @@ -202,6 +217,7 @@ public function it_does_not_ignore_the_hook_lock_file_if_it_is_already_ignored()
$this->assertTrue(strpos(file_get_contents('.gitignore'), Hook::LOCK_FILE) !== false);
}

/** @test */
#[Test]
public function it_uses_a_different_git_path_if_specified()
{
Expand All @@ -217,6 +233,7 @@ public function it_uses_a_different_git_path_if_specified()
}
}

/** @test */
#[Test]
public function it_does_not_create_a_lock_file_when_no_hooks_were_added()
{
Expand All @@ -229,6 +246,7 @@ public function it_does_not_create_a_lock_file_when_no_hooks_were_added()
}
}

/** @test */
#[Test]
public function it_create_git_hooks_path_when_hooks_dir_not_exists()
{
Expand All @@ -243,6 +261,7 @@ public function it_create_git_hooks_path_when_hooks_dir_not_exists()
}
}

/** @test */
#[Test]
public function it_adds_win_bash_compat_if_the_force_windows_option_is_passed()
{
Expand All @@ -257,6 +276,7 @@ public function it_adds_win_bash_compat_if_the_force_windows_option_is_passed()
}
}

/** @test */
#[Test]
public function it_handles_commands_defined_in_an_array()
{
Expand All @@ -280,6 +300,7 @@ public function it_handles_commands_defined_in_an_array()
}


/** @test */
#[Test]
public function it_uses_commands_sequence_for_configured_hooks_only()
{
Expand Down Expand Up @@ -315,6 +336,7 @@ public function it_uses_commands_sequence_for_configured_hooks_only()
$this->assertStringContainsString($expected, $content);
}

/** @test */
#[Test]
public function it_adds_global_git_hooks()
{
Expand Down Expand Up @@ -342,6 +364,7 @@ public function it_adds_global_git_hooks()
$this->assertEquals($hookDir, global_hook_dir());
}

/** @test */
#[Test]
public function it_adds_global_git_hooks_and_shows_previous_global_dir()
{
Expand Down Expand Up @@ -371,6 +394,7 @@ public function it_adds_global_git_hooks_and_shows_previous_global_dir()
$this->assertEquals($hookDir, global_hook_dir());
}

/** @test */
#[Test]
public function it_adds_global_git_hooks_and_does_not_change_global_dir_if_it_matches_new_value()
{
Expand Down Expand Up @@ -399,6 +423,7 @@ public function it_adds_global_git_hooks_and_does_not_change_global_dir_if_it_ma
$this->assertEquals($hookDir, global_hook_dir());
}

/** @test */
#[Test]
public function it_falls_back_to_composer_home_if_no_global_hook_dir_is_provided()
{
Expand Down Expand Up @@ -431,6 +456,7 @@ public function it_falls_back_to_composer_home_if_no_global_hook_dir_is_provided
$this->assertEquals($hookDir, global_hook_dir());
}

/** @test */
#[Test]
public function it_fails_if_global_hook_dir_is_missing()
{
Expand All @@ -450,6 +476,7 @@ public function it_fails_if_global_hook_dir_is_missing()
);
}

/** @test */
#[Test]
public function it_adds_hooks_correctly_in_a_git_worktree()
{
Expand Down
1 change: 1 addition & 0 deletions tests/HelpersTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

class HelpersTest extends PHPUnitTestCase
{
/** @test */
#[Test]
public function it_checks_os()
{
Expand Down
2 changes: 2 additions & 0 deletions tests/HookCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class HookCommandTest extends TestCase
{
/** @test */
#[Test]
public function it_tests_hooks_that_exist()
{
Expand All @@ -20,6 +21,7 @@ public function it_tests_hooks_that_exist()
}
}

/** @test */
#[Test]
public function it_terminates_if_previous_hook_fails()
{
Expand Down
4 changes: 4 additions & 0 deletions tests/ListCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public function init()
$this->commandTester = new CommandTester(new ListCommand());
}

/** @test */
#[Test]
public function it_lists_hooks_that_exist()
{
Expand All @@ -28,6 +29,7 @@ public function it_lists_hooks_that_exist()
}
}

/** @test */
#[Test]
public function it_lists_custom_hooks_that_exist()
{
Expand All @@ -47,6 +49,7 @@ public function it_lists_custom_hooks_that_exist()
$this->assertStringContainsString('pre-flow-feature-start', $this->commandTester->getDisplay());
}

/** @test */
#[Test]
public function it_uses_a_different_git_path_if_specified()
{
Expand All @@ -60,6 +63,7 @@ public function it_uses_a_different_git_path_if_specified()
}
}

/** @test */
#[Test]
public function it_lists_global_git_hooks()
{
Expand Down
12 changes: 12 additions & 0 deletions tests/RemoveCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@

use BrainMaestro\GitHooks\Commands\RemoveCommand;
use BrainMaestro\GitHooks\Hook;
use PHPUnit\Framework\Attributes\Group;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\Console\Output\OutputInterface;
use PHPUnit\Framework\Attributes\Test;

/**
* @group remove
*/
#[Group('remove')]
class RemoveCommandTest extends TestCase
{
/** @var CommandTester */
Expand All @@ -22,6 +24,7 @@ public function init()
$this->commandTester = new CommandTester(new RemoveCommand());
}

/** @test */
#[Test]
public function it_removes_hooks_that_were_added()
{
Expand All @@ -32,6 +35,7 @@ public function it_removes_hooks_that_were_added()
}
}

/** @test */
#[Test]
public function it_removes_custom_hooks_that_were_added()
{
Expand All @@ -50,6 +54,7 @@ public function it_removes_custom_hooks_that_were_added()
$this->assertStringContainsString("Removed pre-flow-feature-start hook", $this->commandTester->getDisplay());
}

/** @test */
#[Test]
public function it_removes_removed_hooks_from_the_lock_file()
{
Expand All @@ -68,6 +73,7 @@ public function it_removes_removed_hooks_from_the_lock_file()
}
}

/** @test */
#[Test]
public function it_removes_individual_hooks()
{
Expand All @@ -77,6 +83,7 @@ public function it_removes_individual_hooks()
}
}

/** @test */
#[Test]
public function it_does_not_remove_hooks_not_present_in_the_lock_file()
{
Expand All @@ -90,6 +97,7 @@ public function it_does_not_remove_hooks_not_present_in_the_lock_file()
);
}

/** @test */
#[Test]
public function it_removes_hooks_not_present_in_the_lock_file_if_forced_to()
{
Expand All @@ -101,6 +109,7 @@ public function it_removes_hooks_not_present_in_the_lock_file_if_forced_to()
$this->assertStringContainsString("Removed {$hook} hook", $this->commandTester->getDisplay());
}

/** @test */
#[Test]
public function it_uses_a_different_git_path_if_specified()
{
Expand All @@ -117,6 +126,7 @@ public function it_uses_a_different_git_path_if_specified()
$this->assertTrue(self::isDirEmpty("{$gitDir}/hooks"));
}

/** @test */
#[Test]
public function it_removes_global_git_hooks()
{
Expand All @@ -140,6 +150,8 @@ public function it_removes_global_git_hooks()
* @test
* @group lock-dir
*/
#[Test]
#[Group('lock-dir')]
public function it_removes_git_hooks_with_lock_dir()
{
$lockDir = realpath(getcwd()) . '/../lock-dir';
Expand Down
Loading

0 comments on commit d743fbe

Please sign in to comment.