AskConfirmationTest::testHandleYes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 8
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 12
rs 10
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
    public function testHandleYes(): void
29
    {
30
        $dummy   = new DummyRepo();
31
        $config  = $this->createConfigMock();
32
        $io      = $this->createIOMock();
33
        $repo    = $this->createRepositoryMock($dummy->getRoot());
34
        $event   = new HookFailed($io, $config, $repo);
35
36
        $io->expects($this->once())->method('ask')->willReturn('y');
37
38
        $handler = new AskConfirmation('continue?');
39
        $handler->handle($event);
40
    }
41
42
    public function testHandleNo(): void
43
    {
44
        $this->expectException(Exception::class);
45
46
        $dummy   = new DummyRepo();
47
        $config  = $this->createConfigMock();
48
        $io      = $this->createIOMock();
49
        $repo    = $this->createRepositoryMock($dummy->getRoot());
50
        $event   = new HookFailed($io, $config, $repo);
51
52
        $io->expects($this->once())->method('ask')->willReturn('n');
53
54
        $handler = new AskConfirmation('continue?');
55
        $handler->handle($event);
56
    }
57
}
58