|
12 | 12 | namespace CaptainHook\App\Runner; |
13 | 13 |
|
14 | 14 | use CaptainHook\App\Config\Mockery as ConfigMockery; |
| 15 | +use CaptainHook\App\Console\IO\DefaultIO; |
15 | 16 | use CaptainHook\App\Console\IO\Mockery as IOMockery; |
16 | 17 | use CaptainHook\App\Exception\InvalidHookName; |
17 | 18 | use CaptainHook\App\Git\DummyRepo; |
18 | 19 | use CaptainHook\App\Hook\Mockery as HookMockery; |
19 | 20 | use CaptainHook\App\Mockery as CHMockery; |
| 21 | +use CaptainHook\App\Storage\File; |
20 | 22 | use Exception; |
21 | 23 | use org\bovigo\vfs\vfsStream; |
22 | 24 | use PHPUnit\Framework\TestCase; |
@@ -171,6 +173,51 @@ public function testWriteHook(): void |
171 | 173 | $this->assertFileExists($fakeRepo->getHookDir() . '/pre-commit'); |
172 | 174 | } |
173 | 175 |
|
| 176 | + /** |
| 177 | + * Tests Installer::checkForBrokenSymlinks |
| 178 | + */ |
| 179 | + public function testBrokenSymlinkDetectionOnExistingFile(): void |
| 180 | + { |
| 181 | + $io = $this->createIOMock(); |
| 182 | + $config = $this->createConfigMock(); |
| 183 | + $repo = $this->createRepositoryMock(); |
| 184 | + $template = $this->createTemplateMock(); |
| 185 | + |
| 186 | + $file = $this->getMockBuilder(File::class) |
| 187 | + ->disableOriginalConstructor() |
| 188 | + ->getMock(); |
| 189 | + |
| 190 | + $runner = new FakeInstaller($io, $config, $repo, $template); |
| 191 | + $file->method('isLink')->willReturn(true); |
| 192 | + $file->method('linkTarget')->willReturn(__FILE__); |
| 193 | + |
| 194 | + $runner->checkSymlink($file); |
| 195 | + $this->assertTrue(true); |
| 196 | + } |
| 197 | + |
| 198 | + /** |
| 199 | + * Tests Installer::checkForBrokenSymlinks |
| 200 | + */ |
| 201 | + public function testBrokenSymlinkDetectionOnBrokenSymlink(): void |
| 202 | + { |
| 203 | + $this->expectException(Exception::class); |
| 204 | + |
| 205 | + $io = $this->createIOMock(); |
| 206 | + $config = $this->createConfigMock(); |
| 207 | + $repo = $this->createRepositoryMock(); |
| 208 | + $template = $this->createTemplateMock(); |
| 209 | + |
| 210 | + $file = $this->getMockBuilder(File::class) |
| 211 | + ->disableOriginalConstructor() |
| 212 | + ->getMock(); |
| 213 | + |
| 214 | + $runner = new FakeInstaller($io, $config, $repo, $template); |
| 215 | + $file->method('isLink')->willReturn(true); |
| 216 | + $file->method('linkTarget')->willReturn('./foo/bar/baz'); |
| 217 | + |
| 218 | + $runner->checkSymlink($file); |
| 219 | + } |
| 220 | + |
174 | 221 | /** |
175 | 222 | * Tests Installer::run |
176 | 223 | */ |
|
0 commit comments