Completed
Push — update_composer ( cce160 )
by amaury
09:32 queued 03:35
created

WorkflowProfileRepositoryTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 140
Duplicated Lines 25.71 %

Coupling/Cohesion

Components 1
Dependencies 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 9
lcom 1
cbo 5
dl 36
loc 140
rs 10
c 1
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setUp() 8 8 1
A testHasTransition() 0 7 1
A provideTransitions() 0 7 1
A testFindForPaginate() 0 5 1
A providePaginateAndSearch() 14 14 1
A testCount() 0 5 1
A testCountWithFilter() 0 5 1
A provideCountWithFilter() 14 14 1
A testRemoveWorkflowProfile() 0 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\ModelInterface\Repository\WorkflowProfileRepositoryInterface;
7
use OpenOrchestra\Pagination\Configuration\PaginateFinderConfiguration;
8
9
/**
10
 * Class WorkflowProfileRepositoryTest
11
 *
12
 * @group integrationTest
13
 */
14
class WorkflowProfileRepositoryTest extends AbstractKernelTestCase
15
{
16
    /**
17
     * @var WorkflowProfileRepositoryInterface
18
     */
19
    protected $repository;
20
21
    protected $statusRepository;
22
23
    /**
24
     * Set up test
25
     */
26 View Code Duplication
    protected function setUp()
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...
27
    {
28
        parent::setUp();
29
30
        static::bootKernel();
31
        $this->repository = static::$kernel->getContainer()->get('open_orchestra_model.repository.workflow_profile');
32
        $this->statusRepository = static::$kernel->getContainer()->get('open_orchestra_model.repository.status');
33
    }
34
35
    /**
36
     * Test hasTransition
37
     *
38
     * @param string  $fromStatusName
39
     * @param string  $toStatusName
40
     * @param boolean $expectedBool
41
     *
42
     * @dataProvider provideTransitions
43
     */
44
    public function testHasTransition($fromStatusName, $toStatusName, $expectedBool)
45
    {
46
        $statusFrom = $this->statusRepository->findOneByName($fromStatusName);
47
        $statusTo = $this->statusRepository->findOneByName($toStatusName);
48
49
        $this->assertSame($expectedBool, $this->repository->hasTransition($statusFrom, $statusTo));
50
    }
51
52
    /**
53
     * Provide transition status
54
     *
55
     * @return array
56
     */
57
    public function provideTransitions()
58
    {
59
        return array(
60
            array('draft', 'toTranslate', false),
61
            array('draft', 'published'  , true),
62
        );
63
    }
64
65
    /**
66
     * @param PaginateFinderConfiguration  $configuration
67
     * @param int                          $count
68
     *
69
     * @dataProvider providePaginateAndSearch
70
     */
71
    public function testFindForPaginate(PaginateFinderConfiguration $configuration, $count)
72
    {
73
        $workflowProfiles = $this->repository->findForPaginate($configuration);
74
        $this->assertCount($count, $workflowProfiles);
75
    }
76
77
    /**
78
     * @return array
79
     */
80 View Code Duplication
    public function providePaginateAndSearch()
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...
81
    {
82
        $configurationAll = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array());
83
        $configurationLimit = PaginateFinderConfiguration::generateFromVariable(array(), 0, 1, array());
84
        $configurationSearch = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('label' => 'Contributor', 'language' => 'en'));
85
        $configurationAllOrder = PaginateFinderConfiguration::generateFromVariable(array('label' => 'desc'), 0, 100, array());
86
87
        return array(
88
            'all' => array($configurationAll, 2),
89
            'limit' => array($configurationLimit, 1),
90
            'search' => array($configurationSearch, 1),
91
            'order' => array($configurationAllOrder, 2),
92
        );
93
    }
94
95
    /**
96
     * test count all workflow profile
97
     */
98
    public function testCount()
99
    {
100
        $workflowProfiles = $this->repository->count();
101
        $this->assertEquals(2, $workflowProfiles);
102
    }
103
104
    /**
105
     * @param PaginateFinderConfiguration $configuration
106
     * @param int                         $count
107
     *
108
     * @dataProvider provideCountWithFilter
109
     */
110
    public function testCountWithFilter($configuration, $count)
111
    {
112
        $workflowProfiles = $this->repository->countWithFilter($configuration);
113
        $this->assertEquals($count, $workflowProfiles);
114
    }
115
116
    /**
117
     * @return array
118
     */
119 View Code Duplication
    public function provideCountWithFilter()
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...
120
    {
121
        $configurationAll = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array());
122
        $configurationLimit = PaginateFinderConfiguration::generateFromVariable(array(), 0, 1, array());
123
        $configurationSearch = PaginateFinderConfiguration::generateFromVariable(array(), 0, 100, array(), array('label' => 'Contributor', 'language' => 'en'));
124
        $configurationAllOrder = PaginateFinderConfiguration::generateFromVariable(array('label' => 'desc'), 0, 100, array());
125
126
        return array(
127
            'all' => array($configurationAll, 2),
128
            'limit' => array($configurationLimit, 2),
129
            'search' => array($configurationSearch, 1),
130
            'order' => array($configurationAllOrder, 2),
131
        );
132
    }
133
134
    /**
135
     * Test remove workflow profile
136
     */
137
    public function testRemoveWorkflowProfile()
138
    {
139
        $dm = static::$kernel->getContainer()->get('object_manager');
140
        $validator = $this->repository->findOneBy(array('labels.en' => 'Validator'));
141
        $contributor = $this->repository->findOneBy(array('labels.en' => 'Contributor'));
142
143
        $workflowProfileIds = array($validator->geTId(), $contributor->getId());
144
145
        $this->repository->removeWorkflowProfiles($workflowProfileIds);
146
        $this->assertNull($this->repository->findOneBy(array('labels.en' => 'Validator')));
147
        $this->assertNull($this->repository->findOneBy(array('labels.en' => 'Contributor')));
148
149
        $dm->persist(clone $validator);
150
        $dm->persist(clone $contributor);
151
        $dm->flush();
152
    }
153
}
154