1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Symnedi\EventDispatcher\Tests\NetteEvent; |
4
|
|
|
|
5
|
|
|
use Nette\Application\Application; |
6
|
|
|
use Nette\Application\Request; |
7
|
|
|
use Nette\Application\UI\Presenter; |
8
|
|
|
use PHPUnit_Framework_TestCase; |
9
|
|
|
use Symnedi\EventDispatcher\Event\ApplicationEvent; |
10
|
|
|
use Symnedi\EventDispatcher\Event\ApplicationExceptionEvent; |
11
|
|
|
use Symnedi\EventDispatcher\Event\ApplicationPresenterEvent; |
12
|
|
|
use Symnedi\EventDispatcher\Event\ApplicationRequestEvent; |
13
|
|
|
use Symnedi\EventDispatcher\NetteApplicationEvents; |
14
|
|
|
use Symnedi\EventDispatcher\Tests\ContainerFactory; |
15
|
|
|
|
16
|
|
|
|
17
|
|
|
final class DispatchApplicationTest extends PHPUnit_Framework_TestCase |
18
|
|
|
{ |
19
|
|
|
|
20
|
|
|
/** |
21
|
|
|
* @var Application |
22
|
|
|
*/ |
23
|
|
|
private $application; |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var EventStateStorage |
27
|
|
|
*/ |
28
|
|
|
private $eventStateStorage; |
29
|
|
|
|
30
|
|
|
|
31
|
|
|
protected function setUp() |
32
|
|
|
{ |
33
|
|
|
$containerFactory = (new ContainerFactory)->create(); |
34
|
|
|
$this->application = $containerFactory->getByType(Application::class); |
35
|
|
|
$this->eventStateStorage = $containerFactory->getByType(EventStateStorage::class); |
36
|
|
|
} |
37
|
|
|
|
38
|
|
|
|
39
|
|
|
public function testOnRequest() |
40
|
|
|
{ |
41
|
|
|
$this->application->run(); |
42
|
|
|
|
43
|
|
|
/** @var ApplicationRequestEvent $applicationRequestEvent */ |
44
|
|
|
$applicationRequestEvent = $this->eventStateStorage->getEventState(NetteApplicationEvents::ON_REQUEST); |
45
|
|
|
$this->assertInstanceOf(ApplicationRequestEvent::class, $applicationRequestEvent); |
46
|
|
|
$this->assertInstanceOf(Application::class, $applicationRequestEvent->getApplication()); |
47
|
|
|
$this->assertInstanceOf(Request::class, $applicationRequestEvent->getRequest()); |
48
|
|
|
} |
49
|
|
|
|
50
|
|
|
|
51
|
|
View Code Duplication |
public function testOnStartup() |
|
|
|
|
52
|
|
|
{ |
53
|
|
|
$this->application->run(); |
54
|
|
|
|
55
|
|
|
/** @var ApplicationEvent $applicationEvent */ |
56
|
|
|
$applicationEvent = $this->eventStateStorage->getEventState(NetteApplicationEvents::ON_STARTUP); |
57
|
|
|
$this->assertInstanceOf(Application::class, $applicationEvent->getApplication()); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
View Code Duplication |
public function testOnPresenter() |
|
|
|
|
62
|
|
|
{ |
63
|
|
|
$this->application->run(); |
64
|
|
|
|
65
|
|
|
/** @var ApplicationPresenterEvent $applicationPresenterEvent */ |
66
|
|
|
$applicationPresenterEvent = $this->eventStateStorage->getEventState(NetteApplicationEvents::ON_PRESENTER); |
67
|
|
|
$this->assertInstanceOf(Application::class, $applicationPresenterEvent->getApplication()); |
68
|
|
|
$this->assertInstanceOf(Presenter::class, $applicationPresenterEvent->getPresenter()); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
|
72
|
|
View Code Duplication |
public function testOnShutdown() |
|
|
|
|
73
|
|
|
{ |
74
|
|
|
$this->application->run(); |
75
|
|
|
|
76
|
|
|
/** @var ApplicationExceptionEvent $applicationExceptionEvent */ |
77
|
|
|
$applicationExceptionEvent = $this->eventStateStorage->getEventState(NetteApplicationEvents::ON_SHUTDOWN); |
78
|
|
|
$this->assertInstanceOf(Application::class, $applicationExceptionEvent->getApplication()); |
79
|
|
|
$this->assertNull($applicationExceptionEvent->getException()); |
80
|
|
|
} |
81
|
|
|
|
82
|
|
|
} |
83
|
|
|
|
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.