captainhook-git /
captainhook
| 1 | <?php |
||
| 2 | |||
| 3 | /** |
||
| 4 | * This file is part of CaptainHook |
||
| 5 | * |
||
| 6 | * (c) Sebastian Feldmann <[email protected]> |
||
| 7 | * |
||
| 8 | * For the full copyright and license information, please view the LICENSE |
||
| 9 | * file that was distributed with this source code. |
||
| 10 | */ |
||
| 11 | |||
| 12 | namespace CaptainHook\App\Hook; |
||
| 13 | |||
| 14 | use PHPUnit\Framework\Attributes\DataProvider; |
||
|
0 ignored issues
–
show
|
|||
| 15 | use PHPUnit\Framework\TestCase; |
||
| 16 | use RuntimeException; |
||
| 17 | use CaptainHook\App\Console\IO\Mockery; |
||
|
0 ignored issues
–
show
This use statement conflicts with another class in this namespace,
CaptainHook\App\Hook\Mockery. Consider defining an alias.
Let?s assume that you have a directory layout like this: .
|-- OtherDir
| |-- Bar.php
| `-- Foo.php
`-- SomeDir
`-- Foo.php
and let?s assume the following content of // Bar.php
namespace OtherDir;
use SomeDir\Foo; // This now conflicts the class OtherDir\Foo
If both files PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as // Bar.php
namespace OtherDir;
use SomeDir\Foo as SomeDirFoo; // There is no conflict anymore.
Loading history...
|
|||
| 18 | |||
| 19 | class UtilTest extends TestCase |
||
| 20 | { |
||
| 21 | use Mockery; |
||
| 22 | |||
| 23 | public function testIsValid(): void |
||
| 24 | { |
||
| 25 | $this->assertTrue(Util::isValid('pre-commit')); |
||
| 26 | $this->assertTrue(Util::isValid('pre-push')); |
||
| 27 | $this->assertTrue(Util::isValid('commit-msg')); |
||
| 28 | $this->assertFalse(Util::isValid('foo')); |
||
| 29 | } |
||
| 30 | |||
| 31 | public function testIsInstallable(): void |
||
| 32 | { |
||
| 33 | $this->assertTrue(Util::isInstallable('pre-commit')); |
||
| 34 | $this->assertTrue(Util::isInstallable('pre-push')); |
||
| 35 | $this->assertTrue(Util::isValid('post-change')); |
||
| 36 | $this->assertFalse(Util::isInstallable('post-change')); |
||
| 37 | } |
||
| 38 | |||
| 39 | public function testGetValidHooks(): void |
||
| 40 | { |
||
| 41 | $this->assertArrayHasKey('pre-commit', Util::getValidHooks()); |
||
| 42 | $this->assertArrayHasKey('pre-push', Util::getValidHooks()); |
||
| 43 | $this->assertArrayHasKey('commit-msg', Util::getValidHooks()); |
||
| 44 | } |
||
| 45 | |||
| 46 | #[DataProvider('providerValidCommands')] |
||
| 47 | public function testGetHookCommandValid(string $class, string $hook): void |
||
| 48 | { |
||
| 49 | $this->assertEquals($class, Util::getHookCommand($hook)); |
||
| 50 | $this->assertEquals('PreCommit', Util::getHookCommand('pre-commit')); |
||
| 51 | $this->assertEquals('PrepareCommitMsg', Util::getHookCommand('prepare-commit-msg')); |
||
| 52 | $this->assertEquals('PrePush', Util::getHookCommand('pre-push')); |
||
| 53 | } |
||
| 54 | |||
| 55 | public static function providerValidCommands(): array |
||
| 56 | { |
||
| 57 | return [ |
||
| 58 | ['CommitMsg', 'commit-msg'], |
||
| 59 | ['PreCommit', 'pre-commit'], |
||
| 60 | ['PrepareCommitMsg', 'prepare-commit-msg'], |
||
| 61 | ['PrePush', 'pre-push'], |
||
| 62 | ]; |
||
| 63 | } |
||
| 64 | |||
| 65 | #[DataProvider('providerInvalidCommands')] |
||
| 66 | public function testGetHookCommandInvalid(string $hook): void |
||
| 67 | { |
||
| 68 | $this->expectException(RuntimeException::class); |
||
| 69 | |||
| 70 | $this->assertEquals('', Util::getHookCommand($hook)); |
||
| 71 | } |
||
| 72 | |||
| 73 | public static function providerInvalidCommands(): array |
||
| 74 | { |
||
| 75 | return [ |
||
| 76 | [''], |
||
| 77 | ['foo'], |
||
| 78 | ]; |
||
| 79 | } |
||
| 80 | |||
| 81 | public function testGetHooks(): void |
||
| 82 | { |
||
| 83 | $this->assertContains('pre-commit', Util::getHooks()); |
||
| 84 | $this->assertContains('pre-push', Util::getHooks()); |
||
| 85 | $this->assertContains('commit-msg', Util::getHooks()); |
||
| 86 | } |
||
| 87 | |||
| 88 | public function testFindPreviousHeadFallback(): void |
||
| 89 | { |
||
| 90 | $io = $this->createIOMock(); |
||
| 91 | $io->method('getStandardInput')->willReturn([]); |
||
| 92 | $io->method('getArgument')->willReturn('HEAD@{1}'); |
||
| 93 | |||
| 94 | $prev = Util::findPreviousHead($io); |
||
| 95 | |||
| 96 | $this->assertEquals('HEAD@{1}', $prev); |
||
| 97 | } |
||
| 98 | |||
| 99 | public function testFindPreviousHeadFromStdIn(): void |
||
| 100 | { |
||
| 101 | $io = $this->createIOMock(); |
||
| 102 | $io->method('getStandardInput')->willReturn(['foo a1a1a1a1 Something', 'bar b2b2b2b2 Something else']); |
||
| 103 | |||
| 104 | $prev = Util::findPreviousHead($io); |
||
| 105 | |||
| 106 | $this->assertEquals('a1a1a1a1^', $prev); |
||
| 107 | } |
||
| 108 | } |
||
| 109 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths