Skip to content

Commit

Permalink
fill in tests, fix skipped test
Browse files Browse the repository at this point in the history
  • Loading branch information
ProjektGopher committed Sep 6, 2024
1 parent 4c1ecf0 commit 0cae091
Showing 1 changed file with 111 additions and 3 deletions.
114 changes: 111 additions & 3 deletions tests/Feature/RunTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use Illuminate\Support\Facades\File;
use ProjektGopher\Whisky\Platform;

it('deletes skip-once file if exists as long as whisky.json exists', function () {
it('deletes skip-once file if exists as long as whisky.json exists and does not run the hook', function () {
File::shouldReceive('missing')
->once()
->with(Platform::cwd('whisky.json'))
Expand All @@ -19,7 +19,115 @@
->with(Platform::cwd('.git/hooks/skip-once'))
->andReturnTrue();

File::shouldReceive('get')
->with(Platform::cwd('whisky.json'))
->andReturn(<<<'JSON'
{
"disabled": [],
"hooks": {
"pre-commit": [
"echo \"poop\" > /tmp/whisky_test_commit_msg"
]
}
}
JSON);

$this->artisan('run pre-commit')
->assertExitCode(0);

expect(file_exists('/tmp/whisky_test_commit_msg'))
->toBeFalse();
});

it('accepts an optional argument and the argument is correct', function () {
File::shouldReceive('missing')
->with(Platform::cwd('whisky.json'))
->andReturnFalse();

File::shouldReceive('exists')
->with(Platform::cwd('.git/hooks/skip-once'))
->andReturnFalse();

/**
* We need to send the output to the disk
* otherwise the output is sent to the
* test output and we can't check it.
*/
File::shouldReceive('get')
->with(Platform::cwd('whisky.json'))
->andReturn(<<<'JSON'
{
"disabled": [],
"hooks": {
"commit-msg": [
"echo \"$1\" > /tmp/whisky_test_commit_msg"
]
}
}
JSON);

$this->artisan('run commit-msg ".git/COMMIT_EDITMSG"')
->assertExitCode(0);

expect(file_get_contents('/tmp/whisky_test_commit_msg'))
->toContain('.git/COMMIT_EDITMSG');

unlink('/tmp/whisky_test_commit_msg');
});

it('still works if no arguments are passed to run command', function () {
File::shouldReceive('missing')
->with(Platform::cwd('whisky.json'))
->andReturnFalse();

File::shouldReceive('exists')
->with(Platform::cwd('.git/hooks/skip-once'))
->andReturnFalse();

File::shouldReceive('get')
->with(Platform::cwd('whisky.json'))
->andReturn(<<<'JSON'
{
"disabled": [],
"hooks": {
"pre-commit": [
"echo \"pre-commit\" > /dev/null"
]
}
}
JSON);

$this->artisan('run pre-commit')
->doesntExpectOutputToContain('run-hook')
->assertExitCode(0);
})->skip('Needs to be refactored so that the hooks don\'t actually run');
});

it('handles a missing expected argument gracefully', function () {
File::shouldReceive('missing')
->with(Platform::cwd('whisky.json'))
->andReturnFalse();

File::shouldReceive('exists')
->with(Platform::cwd('.git/hooks/skip-once'))
->andReturnFalse();

File::shouldReceive('get')
->with(Platform::cwd('whisky.json'))
->andReturn(<<<'JSON'
{
"disabled": [],
"hooks": {
"commit-msg": [
"echo \"$1\" > /tmp/whisky_test_commit_msg"
]
}
}
JSON);

$this->artisan('run commit-msg')
->assertExitCode(0);

expect(file_get_contents('/tmp/whisky_test_commit_msg'))
->toBe("\n");

unlink('/tmp/whisky_test_commit_msg');
});

0 comments on commit 0cae091

Please sign in to comment.