|
| 1 | +<?php |
| 2 | + |
| 3 | +use Igorsgm\GitHooks\Traits\GitHelper; |
| 4 | +use Symfony\Component\Process\Exception\ProcessFailedException; |
| 5 | + |
| 6 | +uses(GitHelper::class); |
| 7 | +beforeEach(function () { |
| 8 | + $this->initializeGitAsTempDirectory(); |
| 9 | +}); |
| 10 | + |
| 11 | +test('Gets list of changed files', function () { |
| 12 | + chdir(__DIR__); |
| 13 | + |
| 14 | + expect($this->getListOfChangedFiles())->toBe( |
| 15 | + shell_exec('git status --short') |
| 16 | + ); |
| 17 | +}); |
| 18 | + |
| 19 | +test('Gets last commit text from git log', function () { |
| 20 | + chdir(__DIR__); |
| 21 | + |
| 22 | + expect($this->getLastCommitFromLog())->toBe( |
| 23 | + shell_exec('git log -1 HEAD') |
| 24 | + ); |
| 25 | +}); |
| 26 | + |
| 27 | +test('Throws ProcessFailedException on errored git command', function () { |
| 28 | + expect(fn () => $this->runCommandAndGetOutput('git --wrong')) |
| 29 | + ->toThrow(ProcessFailedException::class); |
| 30 | +}); |
| 31 | + |
| 32 | +test('Gets Commit message content from .git file', function () { |
| 33 | + $gitFileName = 'COMMIT_MESSAGE'; |
| 34 | + $messageText = 'test message'; |
| 35 | + |
| 36 | + $this->makeTempFile($gitFileName, $messageText); |
| 37 | + $gitFilePath = $this->getTempFilePath($gitFileName); |
| 38 | + |
| 39 | + expect($this->getCommitMessageContentFromFile($gitFilePath)) |
| 40 | + ->toBe($messageText); |
| 41 | +}); |
| 42 | + |
| 43 | +test('Updates Commit message content in .git file', function () { |
| 44 | + $gitFileName = 'COMMIT_MESSAGE'; |
| 45 | + $messageText = 'test message'; |
| 46 | + |
| 47 | + $this->makeTempFile($gitFileName, $messageText); |
| 48 | + $gitFilePath = $this->getTempFilePath($gitFileName); |
| 49 | + |
| 50 | + $newMessage = 'new message 1'; |
| 51 | + $this->updateCommitMessageContentInFile($gitFilePath, $newMessage); |
| 52 | + expect(file_get_contents($gitFilePath))->toBe($newMessage); |
| 53 | +}); |
0 commit comments