StatusRepositoryTest   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 114
Duplicated Lines 14.04 %

Coupling/Cohesion

Components 1
Dependencies 6

Importance

Changes 4
Bugs 1 Features 1
Metric Value
wmc 9
c 4
b 1
f 1
lcom 1
cbo 6
dl 16
loc 114
rs 10

8 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 0 7 1
A testFindNotOutOfWorkflow() 0 8 2
A testFindOneByTranslationState() 0 5 1
A testFindForPaginate() 0 4 1
A testCountNotOutOfWorkflow() 0 4 1
A testCountWithFilter() 0 4 1
A providePaginateConfiguration() 0 13 1
A testRemoveStatuses() 16 16 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
namespace OpenOrchestra\FunctionalTests\ModelBundle\Repository;
4
5
use OpenOrchestra\BaseBundle\Tests\AbstractTest\AbstractKernelTestCase;
6
use OpenOrchestra\ModelBundle\Repository\StatusRepository;
7
use OpenOrchestra\Pagination\Configuration\PaginateFinderConfiguration;
8
9
/**
10
 * Test StatusRepositoryTest
11
 *
12
 * @group integrationTest
13
 */
14
class StatusRepositoryTest extends AbstractKernelTestCase
15
{
16
    /**
17
     * @var StatusRepository
18
     */
19
    protected $repository;
20
21
    /**
22
     * Set up the test
23
     */
24
    public function setUp()
25
    {
26
        parent::setUp();
27
28
        static::bootKernel();
29
        $this->repository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status');
30
    }
31
32
    /**
33
     * test find not out of workflow
34
     */
35
    public function testFindNotOutOfWorkflow()
36
    {
37
        $statuses = $this->repository->findNotOutOfWorkflow();
38
        $this->assertCount(5, $statuses);
39
        foreach ($statuses as $status) {
40
            $this->assertFalse($status->isOutOfWorkflow());
41
        }
42
    }
43
44
    /**
45
     * test find one by translation state
46
     */
47
    public function testFindOneByTranslationState()
48
    {
49
        $status = $this->repository->findOneByTranslationState();
50
        $this->assertTrue($status->isTranslationState());
51
    }
52
53
    /**
54
     * test findForPaginate
55
     *
56
     * @param PaginateFinderConfiguration $configuration
57
     * @param int                         $expectedCount
58
     * @param int                         $expectedFilteredCount
59
     *
60
     * @dataProvider providePaginateConfiguration
61
     */
62
    public function testFindForPaginate(PaginateFinderConfiguration $configuration, $expectedCount, $expectedFilteredCount)
0 ignored issues
show
Unused Code introduced by
The parameter $expectedFilteredCount is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
63
    {
64
        $this->assertCount($expectedCount, $this->repository->findForPaginate($configuration));
65
    }
66
67
    /**
68
     * test count
69
     */
70
    public function testCountNotOutOfWorkflow()
71
    {
72
        $this->assertSame(5, $this->repository->CountNotOutOfWorkflow());
73
    }
74
75
    /**
76
     * test countWithFilter
77
     *
78
     * @param PaginateFinderConfiguration $configuration
79
     * @param int                         $expectedCount
80
     * @param int                         $expectedFilteredCount
81
     *
82
     * @dataProvider providePaginateConfiguration
83
     */
84
    public function testCountWithFilter(PaginateFinderConfiguration $configuration, $expectedCount, $expectedFilteredCount)
0 ignored issues
show
Unused Code introduced by
The parameter $expectedCount is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
85
    {
86
        $this->assertSame($expectedFilteredCount, $this->repository->countWithFilter($configuration));
87
    }
88
89
    /**
90
     * Provide PaginateFinderConfiguration
91
     *
92
     * @return array
93
     */
94
    public function providePaginateConfiguration()
95
    {
96
        $mapping =  array('label' => 'labels');
97
        $conf1 = PaginateFinderConfiguration::generateFromVariable(null , null, null, $mapping, null);
98
        $conf2 = PaginateFinderConfiguration::generateFromVariable(null , null, null, $mapping, array('label' => 'o', 'language' => 'en'));
99
        $conf3 = PaginateFinderConfiguration::generateFromVariable(null , 2   , 4   , $mapping, array('label' => 'r', 'language' => 'en'));
100
101
        return array(
102
            'No criteria'                => array($conf1, 5, 5),
103
            'Filtering "o"'              => array($conf2, 2, 2),
104
            'Filtering 2 items with "r"' => array($conf3, 0, 2),
105
        );
106
    }
107
108
    /**
109
     * Test remove statuses
110
     */
111 View Code Duplication
    public function testRemoveStatuses()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
112
    {
113
        $dm = static::$kernel->getContainer()->get('object_manager');
114
        $statusPending = $this->repository->findOneByName('pending');
115
        $statusPublished = $this->repository->findOneByName('published');
116
117
        $statusIds = array($statusPending->getId(), $statusPublished->getId());
118
119
        $this->repository->removeStatuses($statusIds);
120
        $this->assertNull($this->repository->findOneByName('pending'));
121
        $this->assertNull($this->repository->findOneByName('published'));
122
123
        $dm->persist(clone $statusPending);
124
        $dm->persist(clone $statusPublished);
125
        $dm->flush();
126
    }
127
 }
128