EnableFiltersSubscriberTest   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 8

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 1
cbo 8
dl 35
loc 35
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 6 6 1
A testDispatchEvent() 11 11 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
declare(strict_types=1);
4
5
namespace Zenify\DoctrineFilters\Tests\EventSubscriber;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Nette\Application\Application;
9
use Nette\Application\IPresenter;
10
use PHPUnit\Framework\TestCase;
11
use Symfony\Component\EventDispatcher\EventDispatcherInterface;
12
use Symplify\SymfonyEventDispatcher\Adapter\Nette\Event\ApplicationStartupEvent;
13
use Symplify\SymfonyEventDispatcher\Adapter\Nette\Event\PresenterCreatedEvent;
14
use Zenify\DoctrineFilters\Tests\ContainerFactory;
15
16
17 View Code Duplication
final class EnableFiltersSubscriberTest extends TestCase
18
{
19
20
	/**
21
	 * @var EntityManagerInterface
22
	 */
23
	private $entityManager;
24
25
	/**
26
	 * @var EventDispatcherInterface
27
	 */
28
	private $eventDispatcher;
29
30
31
	protected function setUp()
32
	{
33
		$container = (new ContainerFactory)->create();
34
		$this->eventDispatcher = $container->getByType(EventDispatcherInterface::class);
35
		$this->entityManager = $container->getByType(EntityManagerInterface::class);
36
	}
37
38
39
	public function testDispatchEvent()
40
	{
41
		$filters = $this->entityManager->getFilters();
42
		$this->assertCount(0, $filters->getEnabledFilters());
43
44
		$applicationMock = $this->prophesize(Application::class);
45
		$applicationStartupEvent = new ApplicationStartupEvent($applicationMock->reveal());
46
		$this->eventDispatcher->dispatch(ApplicationStartupEvent::NAME, $applicationStartupEvent);
47
48
		$this->assertCount(2, $filters->getEnabledFilters());
49
	}
50
51
}
52