@@ -209,4 +209,171 @@ public function testInstallMultipleHooksWithMultipleWrong(): void
209
209
$ install = new Install (new Resolver (CH_PATH_FILES . '/bin/captainhook ' ));
210
210
$ install ->run ($ input , $ output );
211
211
}
212
+
213
+ /**
214
+ * Tests Install::run
215
+ *
216
+ * @throws \Exception
217
+ */
218
+ public function testInstallOnlyEnabled (): void
219
+ {
220
+ $ repo = new DummyRepo ();
221
+ $ output = new NullOutput ();
222
+ $ input = new ArrayInput (
223
+ [
224
+ '--only-enabled ' => true ,
225
+ '--force ' => true ,
226
+ '--configuration ' => CH_PATH_FILES . '/template/captainhook.json ' ,
227
+ '--git-directory ' => $ repo ->getGitDir ()
228
+ ]
229
+ );
230
+
231
+ $ install = new Install (new Resolver (CH_PATH_FILES . '/bin/captainhook ' ));
232
+ $ install ->run ($ input , $ output );
233
+
234
+ $ this ->assertTrue ($ repo ->hookExists ('prepare-commit-msg ' ));
235
+ $ this ->assertTrue ($ repo ->hookExists ('commit-msg ' ));
236
+ $ this ->assertTrue ($ repo ->hookExists ('pre-commit ' ));
237
+ $ this ->assertFalse ($ repo ->hookExists ('pre-push ' ));
238
+ $ this ->assertFalse ($ repo ->hookExists ('post-commit ' ));
239
+ }
240
+
241
+ /**
242
+ * Tests Install::run
243
+ *
244
+ * @throws \Exception
245
+ */
246
+ public function testInstallOnlyEnabledOnlyVirtual (): void
247
+ {
248
+ $ repo = new DummyRepo ();
249
+ $ output = new NullOutput ();
250
+ $ input = new ArrayInput (
251
+ [
252
+ '--only-enabled ' => true ,
253
+ '--force ' => true ,
254
+ '--configuration ' => CH_PATH_FILES . '/template/captainhook-post-change.json ' ,
255
+ '--git-directory ' => $ repo ->getGitDir ()
256
+ ]
257
+ );
258
+
259
+ $ install = new Install (new Resolver (CH_PATH_FILES . '/bin/captainhook ' ));
260
+ $ install ->run ($ input , $ output );
261
+
262
+ $ this ->assertTrue ($ repo ->hookExists ('post-checkout ' ));
263
+ $ this ->assertTrue ($ repo ->hookExists ('post-merge ' ));
264
+ $ this ->assertTrue ($ repo ->hookExists ('post-rewrite ' ));
265
+ $ this ->assertFalse ($ repo ->hookExists ('pre-commit ' ));
266
+ $ this ->assertFalse ($ repo ->hookExists ('pre-push ' ));
267
+ $ this ->assertFalse ($ repo ->hookExists ('post-commit ' ));
268
+ }
269
+
270
+ /**
271
+ * Tests Install::run
272
+ *
273
+ * @throws \Exception
274
+ */
275
+ public function testInstallOnlyEnabledNotOnlyVirtual (): void
276
+ {
277
+ $ repo = new DummyRepo ();
278
+ $ output = new NullOutput ();
279
+ $ input = new ArrayInput (
280
+ [
281
+ '--only-enabled ' => true ,
282
+ '--force ' => true ,
283
+ '--configuration ' => CH_PATH_FILES . '/template/captainhook-post-change-pre-commit.json ' ,
284
+ '--git-directory ' => $ repo ->getGitDir ()
285
+ ]
286
+ );
287
+
288
+ $ install = new Install (new Resolver (CH_PATH_FILES . '/bin/captainhook ' ));
289
+ $ install ->run ($ input , $ output );
290
+
291
+ $ this ->assertTrue ($ repo ->hookExists ('post-checkout ' ));
292
+ $ this ->assertTrue ($ repo ->hookExists ('post-merge ' ));
293
+ $ this ->assertTrue ($ repo ->hookExists ('post-rewrite ' ));
294
+ $ this ->assertTrue ($ repo ->hookExists ('pre-commit ' ));
295
+ $ this ->assertFalse ($ repo ->hookExists ('pre-push ' ));
296
+ $ this ->assertFalse ($ repo ->hookExists ('post-commit ' ));
297
+ }
298
+
299
+ /**
300
+ * Tests Install::run
301
+ *
302
+ * @throws \Exception
303
+ */
304
+ public function testInstallOnlyEnabledNotOnlyVirtualOverlaps (): void
305
+ {
306
+ $ repo = new DummyRepo ();
307
+ $ output = new NullOutput ();
308
+ $ input = new ArrayInput (
309
+ [
310
+ '--only-enabled ' => true ,
311
+ '--force ' => true ,
312
+ '--configuration ' => CH_PATH_FILES . '/template/captainhook-post-change-post-merge.json ' ,
313
+ '--git-directory ' => $ repo ->getGitDir ()
314
+ ]
315
+ );
316
+
317
+ $ install = new Install (new Resolver (CH_PATH_FILES . '/bin/captainhook ' ));
318
+ $ install ->run ($ input , $ output );
319
+
320
+ $ this ->assertTrue ($ repo ->hookExists ('post-checkout ' ));
321
+ $ this ->assertTrue ($ repo ->hookExists ('post-merge ' ));
322
+ $ this ->assertTrue ($ repo ->hookExists ('post-rewrite ' ));
323
+ $ this ->assertFalse ($ repo ->hookExists ('pre-commit ' ));
324
+ $ this ->assertFalse ($ repo ->hookExists ('pre-push ' ));
325
+ $ this ->assertFalse ($ repo ->hookExists ('post-commit ' ));
326
+ }
327
+
328
+ /**
329
+ * Tests Install::run
330
+ *
331
+ * @throws \Exception
332
+ */
333
+ public function testInstallOnlyEnabledNotOnlyVirtualOverlapsDisabled (): void
334
+ {
335
+ $ repo = new DummyRepo ();
336
+ $ output = new NullOutput ();
337
+ $ input = new ArrayInput (
338
+ [
339
+ '--only-enabled ' => true ,
340
+ '--force ' => true ,
341
+ '--configuration ' => CH_PATH_FILES . '/template/captainhook-post-change-post-merge-disabled.json ' ,
342
+ '--git-directory ' => $ repo ->getGitDir ()
343
+ ]
344
+ );
345
+
346
+ $ install = new Install (new Resolver (CH_PATH_FILES . '/bin/captainhook ' ));
347
+ $ install ->run ($ input , $ output );
348
+
349
+ $ this ->assertTrue ($ repo ->hookExists ('post-checkout ' ));
350
+ $ this ->assertTrue ($ repo ->hookExists ('post-merge ' ));
351
+ $ this ->assertTrue ($ repo ->hookExists ('post-rewrite ' ));
352
+ $ this ->assertFalse ($ repo ->hookExists ('pre-commit ' ));
353
+ $ this ->assertFalse ($ repo ->hookExists ('pre-push ' ));
354
+ $ this ->assertFalse ($ repo ->hookExists ('post-commit ' ));
355
+ }
356
+
357
+ /**
358
+ * Tests Install::run
359
+ *
360
+ * @throws \Exception
361
+ */
362
+ public function testInstallOnlyEnabledAndHook (): void
363
+ {
364
+ $ this ->expectException (\RuntimeException::class);
365
+ $ repo = new DummyRepo ();
366
+ $ output = new NullOutput ();
367
+ $ input = new ArrayInput (
368
+ [
369
+ 'hook ' => 'pre-commit ' ,
370
+ '--only-enabled ' => true ,
371
+ '--configuration ' => CH_PATH_FILES . '/template/captainhook.json ' ,
372
+ '--git-directory ' => $ repo ->getGitDir (),
373
+ ]
374
+ );
375
+
376
+ $ install = new Install (new Resolver (CH_PATH_FILES . '/bin/captainhook ' ));
377
+ $ install ->run ($ input , $ output );
378
+ }
212
379
}
0 commit comments