FilterManagerTest   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 37
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 0
Metric Value
wmc 3
c 0
b 0
f 0
lcom 1
cbo 6
dl 37
loc 37
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 6 6 1
A testEnabledFilters() 13 13 2

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\FilterManager;
6
7
use Doctrine\ORM\EntityManagerInterface;
8
use Doctrine\ORM\Query\FilterCollection;
9
use PHPUnit\Framework\TestCase;
10
use Zenify\DoctrineFilters\Contract\FilterInterface;
11
use Zenify\DoctrineFilters\Contract\FilterManagerInterface;
12
use Zenify\DoctrineFilters\Tests\ContainerFactory;
13
14
15 View Code Duplication
final class FilterManagerTest extends TestCase
16
{
17
18
	/**
19
	 * @var EntityManagerInterface
20
	 */
21
	private $entityManager;
22
23
	/**
24
	 * @var FilterManagerInterface
25
	 */
26
	private $filterManager;
27
28
29
	protected function setUp()
30
	{
31
		$container = (new ContainerFactory)->create();
32
		$this->entityManager = $container->getByType(EntityManagerInterface::class);
33
		$this->filterManager = $container->getByType(FilterManagerInterface::class);
34
	}
35
36
37
	public function testEnabledFilters()
38
	{
39
		$filterCollection = $this->entityManager->getFilters();
40
		$this->assertInstanceOf(FilterCollection::class, $filterCollection);
41
		$this->assertCount(0, $filterCollection->getEnabledFilters());
42
43
		$this->filterManager->enableFilters();
44
45
		$this->assertCount(2, $filterCollection->getEnabledFilters());
46
		foreach ($filterCollection->getEnabledFilters() as $filter) {
47
			$this->assertInstanceOf(FilterInterface::class, $filter);
48
		}
49
	}
50
51
}
52