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
|
|
|
|