NavigationBuilderTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 16
c 1
b 0
f 0
dl 0
loc 44
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A testHandleWithMatchingIntent() 0 12 1
A testHandleWithoutMatchingIntent() 0 10 1
A setUp() 0 5 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace AbterPhp\Contact\Events\Listeners;
6
7
use AbterPhp\Framework\Events\NavigationReady;
8
use AbterPhp\Framework\Html\Component\Button;
9
use AbterPhp\Framework\Html\Component\ButtonFactory;
10
use AbterPhp\Framework\Navigation\Navigation;
11
use PHPUnit\Framework\MockObject\MockObject;
12
use PHPUnit\Framework\TestCase;
13
14
class NavigationBuilderTest extends TestCase
15
{
16
    /** @var NavigationBuilder - System Under Test */
17
    protected $sut;
18
19
    /** @var array */
20
    protected $sessionData = [
21
        'username' => 'jane',
22
    ];
23
24
    /** @var ButtonFactory|MockObject */
25
    protected $buttonFactoryMock;
26
27
    public function setUp(): void
28
    {
29
        $this->buttonFactoryMock = $this->createMock(ButtonFactory::class);
30
31
        $this->sut = new NavigationBuilder($this->buttonFactoryMock);
32
    }
33
34
    public function testHandleWithoutMatchingIntent()
35
    {
36
        /** @var Navigation|MockObject $navigationMock */
37
        $navigationMock = $this->createMock(Navigation::class);
38
39
        $event = new NavigationReady($navigationMock);
40
41
        $navigationMock->expects($this->once())->method('hasIntent')->willReturn(false);
42
43
        $this->sut->handle($event);
44
    }
45
46
    public function testHandleWithMatchingIntent()
47
    {
48
        /** @var Navigation|MockObject $navigationMock */
49
        $navigationMock = $this->createMock(Navigation::class);
50
51
        $event = new NavigationReady($navigationMock);
52
53
        $navigationMock->expects($this->atLeastOnce())->method('hasIntent')->willReturn(true);
54
55
        $this->buttonFactoryMock->expects($this->atLeastOnce())->method('createFromName')->willReturn(new Button());
56
57
        $this->sut->handle($event);
58
    }
59
}
60