NavigationBuilderTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Importance

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

3 Methods

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