Skip to content

Commit

Permalink
Add tooling for integration tests with initial tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ramsey committed May 9, 2021
1 parent 76987f6 commit e2a8cf4
Show file tree
Hide file tree
Showing 16 changed files with 552 additions and 3 deletions.
5 changes: 4 additions & 1 deletion .github/workflows/integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,10 @@ 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

- name: Execute unit tests
run: tools/phpunit --configuration=phpunit.ci.xml
run: tools/phpunit --configuration=phpunit.ci.xml --testsuite CaptainHook

- name: Execute integration tests
run: tools/phpunit --configuration=phpunit.ci.xml --testsuite Integration

- name: Check coding style
run: tools/phpcs --standard=psr12 src tests
Expand Down
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@
},
"autoload-dev": {
"psr-4": {
"CaptainHook\\App\\": "tests/CaptainHook/"
"CaptainHook\\App\\": "tests/CaptainHook/",
"CaptainHook\\App\\Integration\\": "tests/integration/"
}
},
"require": {
Expand Down Expand Up @@ -67,7 +68,8 @@
"post-install-cmd": "tools/phive install --force-accept-unsigned",
"tools": "tools/phive install --force-accept-unsigned",
"compile": "tools/box compile",
"test": "tools/phpunit",
"test": "tools/phpunit --testsuite CaptainHook",
"test:integration": "tools/phpunit --testsuite Integration --no-coverage",
"analyse": "tools/phpstan analyse",
"style": "tools/phpcs --standard=psr12 src tests"
}
Expand Down
3 changes: 3 additions & 0 deletions phpunit.ci.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,8 @@
<testsuite name="CaptainHook">
<directory>tests/CaptainHook</directory>
</testsuite>
<testsuite name="Integration">
<directory>tests/integration</directory>
</testsuite>
</testsuites>
</phpunit>
3 changes: 3 additions & 0 deletions phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
<testsuite name="CaptainHook">
<directory>tests/CaptainHook</directory>
</testsuite>
<testsuite name="Integration">
<directory>tests/integration</directory>
</testsuite>
</testsuites>
<logging>
<junit outputFile="build/logs/junit.xml"/>
Expand Down
1 change: 1 addition & 0 deletions tests/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@
*/

define('CH_PATH_FILES', realpath(__DIR__ . '/files'));
define('CH_PATH_ROOT', realpath(__DIR__ . '/..'));
2 changes: 2 additions & 0 deletions tests/files/template-acceptance/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/composer.lock
/vendor/
3 changes: 3 additions & 0 deletions tests/files/template-acceptance/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# CaptainHook Acceptance Testing

This is a sample project directory to use with acceptance tests.
39 changes: 39 additions & 0 deletions tests/files/template-acceptance/captainhook.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
{
"config": {},
"commit-msg": {
"enabled": false,
"actions": []
},
"pre-push": {
"enabled": false,
"actions": []
},
"pre-commit": {
"enabled": false,
"actions": []
},
"prepare-commit-msg": {
"enabled": false,
"actions": []
},
"post-commit": {
"enabled": false,
"actions": []
},
"post-merge": {
"enabled": false,
"actions": []
},
"post-checkout": {
"enabled": false,
"actions": []
},
"post-rewrite": {
"enabled": false,
"actions": []
},
"post-change": {
"enabled": false,
"actions": []
}
}
13 changes: 13 additions & 0 deletions tests/files/template-acceptance/composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"name": "captainhook/repo-test",
"description": "A sample project to use with CaptainHook acceptance tests.",
"type": "project",
"minimum-stability": "dev",
"prefer-stable": true,
"require-dev": {
"captainhook/captainhook": "*"
},
"scripts": {
"post-autoload-dump": "captainhook install --no-interaction --no-ansi --force"
}
}
23 changes: 23 additions & 0 deletions tests/integration/HookInstallTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace CaptainHook\App\Integration;

class HookInstallTest extends IntegrationTestCase
{
public function testGitHooksSuccessfullyInstallWithComposerUpdate(): void
{
$repoPath = $this->setUpRepository(false);

$result = $this->runInShell(['composer', 'update', '--no-ansi', '--no-interaction'], $repoPath);

$this->assertStringContainsString("'commit-msg' hook installed successfully", $result->getStdout());
$this->assertStringContainsString("'pre-push' hook installed successfully", $result->getStdout());
$this->assertStringContainsString("'pre-commit' hook installed successfully", $result->getStdout());
$this->assertStringContainsString("'prepare-commit-msg' hook installed successfully", $result->getStdout());
$this->assertStringContainsString("'post-commit' hook installed successfully", $result->getStdout());
$this->assertStringContainsString("'post-merge' hook installed successfully", $result->getStdout());
$this->assertStringContainsString("'post-checkout' hook installed successfully", $result->getStdout());
$this->assertStringContainsString("'post-rewrite' hook installed successfully", $result->getStdout());
$this->assertStringContainsString("'post-change' hook installed successfully", $result->getStdout());
}
}
49 changes: 49 additions & 0 deletions tests/integration/HookPluginTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php

namespace CaptainHook\App\Integration;

class HookPluginTest extends IntegrationTestCase
{
public function testHookPluginRunsBeforeAndAfterHookAndActions(): void
{
$repoPath = $this->setUpRepository();

$this->setConfig($repoPath, 'plugins', [
[
'plugin' => '\\CaptainHook\\App\\Integration\\Plugin\\SimplePlugin',
'options' => [
'stuff' => 'cool things',
],
],
]);

$this->enableHook($repoPath, 'pre-commit', [
[
'action' => 'echo "action1"',
],
[
'action' => 'echo "action2"',
],
]);

$this->enableHook($repoPath, 'post-commit');

$this->filesystem()->touch($repoPath . '/foo.txt');
$this->mustRunInShell(['git', 'add', 'foo.txt'], $repoPath);

$result = $this->runInShell(['git', 'commit', '-m', 'Add foo.txt'], $repoPath);

$this->assertStringContainsString('Do cool things before pre-commit runs', $result->getStderr());
$this->assertStringContainsString('Do cool things before action echo "action1" runs', $result->getStderr());
$this->assertStringContainsString('Do cool things after action echo "action1" runs', $result->getStderr());
$this->assertStringContainsString('Do cool things before action echo "action2" runs', $result->getStderr());
$this->assertStringContainsString('Do cool things after action echo "action2" runs', $result->getStderr());
$this->assertStringContainsString('Do cool things after pre-commit runs', $result->getStderr());

$this->assertStringContainsString('Do cool things before post-commit runs', $result->getStderr());
$this->assertStringContainsString('Do cool things after post-commit runs', $result->getStderr());

$this->assertStringNotContainsString('commit-msg', $result->getStderr());
$this->assertStringNotContainsString('prepare-commit-msg', $result->getStderr());
}
}

0 comments on commit e2a8cf4

Please sign in to comment.