Passed
Push — main ( f0911f...cd99fe )
by Sebastian
05:24
created

AskConfirmationTest   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 40
rs 10
wmc 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A testHandleYes() 0 12 1
A testHandleNo() 0 14 1
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\UserInput\EventHandler;
13
14
use CaptainHook\App\Config\Mockery as ConfigMockery;
15
use CaptainHook\App\Console\IO\Mockery as IOMockery;
16
use CaptainHook\App\Event\HookFailed;
17
use CaptainHook\App\Git\DummyRepo;
18
use CaptainHook\App\Mockery as CHMockery;
19
use Exception;
20
use PHPUnit\Framework\TestCase;
21
22
class AskConfirmationTest extends TestCase
23
{
24
    use ConfigMockery;
25
    use IOMockery;
26
    use CHMockery;
27
28
    /**
29
     * Tests AskConfirmation::handle
30
     */
31
    public function testHandleYes(): void
32
    {
33
        $dummy   = new DummyRepo();
34
        $config  = $this->createConfigMock();
35
        $io      = $this->createIOMock();
36
        $repo    = $this->createRepositoryMock($dummy->getRoot());
37
        $event   = new HookFailed($io, $config, $repo);
38
39
        $io->expects($this->once())->method('ask')->willReturn('y');
40
41
        $handler = new AskConfirmation('continue?');
42
        $handler->handle($event);
43
    }
44
45
    /**
46
     * Tests AskConfirmation::handle
47
     */
48
    public function testHandleNo(): void
49
    {
50
        $this->expectException(Exception::class);
51
52
        $dummy   = new DummyRepo();
53
        $config  = $this->createConfigMock();
54
        $io      = $this->createIOMock();
55
        $repo    = $this->createRepositoryMock($dummy->getRoot());
56
        $event   = new HookFailed($io, $config, $repo);
57
58
        $io->expects($this->once())->method('ask')->willReturn('n');
59
60
        $handler = new AskConfirmation('continue?');
61
        $handler->handle($event);
62
    }
63
}
64