Completed
Pull Request — master (#1052)
by
unknown
07:01
created

RepositoryTest   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 94
Duplicated Lines 59.57 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 9
c 2
b 0
f 1
lcom 1
cbo 3
dl 56
loc 94
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A testThatCreatePaginatorCreatesAPaginatorViaFinder() 8 8 1
A testThatFindCallsFindOnFinder() 8 8 1
A testThatFindCallsFindOnFinderWithLimit() 0 9 1
A testThatFindPaginatedCallsFindPaginatedOnFinder() 8 8 1
A testThatFindHybridCallsFindHybridOnFinder() 8 8 1
A testThatFindRawResultCallsFindRawResultOnFinder() 8 8 1
A testThatFindRawPaginatedCallsFindRawPaginatedOnFinder() 8 8 1
A testThatCreateRawPaginatorCreatesAPaginatorViaFinder() 8 8 1
A getFinderMock() 0 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
namespace FOS\ElasticaBundle\Tests;
4
5
use FOS\ElasticaBundle\Repository;
6
7
/**
8
 * @author Richard Miller <[email protected]>
9
 */
10
class RepositoryTest extends \PHPUnit_Framework_TestCase
11
{
12 View Code Duplication
    public function testThatFindCallsFindOnFinder()
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...
13
    {
14
        $testQuery = 'Test Query';
15
16
        $finderMock = $this->getFinderMock($testQuery);
17
        $repository = new Repository($finderMock);
18
        $repository->find($testQuery);
19
    }
20
21
    public function testThatFindCallsFindOnFinderWithLimit()
22
    {
23
        $testQuery = 'Test Query';
24
        $testLimit = 20;
25
26
        $finderMock = $this->getFinderMock($testQuery, $testLimit);
27
        $repository = new Repository($finderMock);
28
        $repository->find($testQuery, $testLimit);
29
    }
30
31 View Code Duplication
    public function testThatFindPaginatedCallsFindPaginatedOnFinder()
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...
32
    {
33
        $testQuery = 'Test Query';
34
35
        $finderMock = $this->getFinderMock($testQuery, array(), 'findPaginated');
36
        $repository = new Repository($finderMock);
37
        $repository->findPaginated($testQuery);
38
    }
39
40 View Code Duplication
    public function testThatCreatePaginatorCreatesAPaginatorViaFinder()
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...
41
    {
42
        $testQuery = 'Test Query';
43
44
        $finderMock = $this->getFinderMock($testQuery, array(), 'createPaginatorAdapter');
45
        $repository = new Repository($finderMock);
46
        $repository->createPaginatorAdapter($testQuery);
47
    }
48
49 View Code Duplication
    public function testThatFindHybridCallsFindHybridOnFinder()
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...
50
    {
51
        $testQuery = 'Test Query';
52
53
        $finderMock = $this->getFinderMock($testQuery, null, 'findHybrid');
54
        $repository = new Repository($finderMock);
55
        $repository->findHybrid($testQuery);
56
    }
57
58 View Code Duplication
    public function testThatFindRawResultCallsFindRawResultOnFinder()
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...
59
    {
60
        $testQuery = 'Test Query';
61
62
        $finderMock = $this->getFinderMock($testQuery, null, 'findRawResult');
63
        $repository = new Repository($finderMock);
64
        $repository->findRawResult($testQuery);
65
    }
66
    
67 View Code Duplication
    public function testThatFindRawPaginatedCallsFindRawPaginatedOnFinder()
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...
68
    {
69
        $testQuery = 'Test Query';
70
71
        $finderMock = $this->getFinderMock($testQuery, array(), 'findRawPaginated');
72
        $repository = new Repository($finderMock);
73
        $repository->findRawPaginated($testQuery);
74
    }
75
76 View Code Duplication
    public function testThatCreateRawPaginatorCreatesAPaginatorViaFinder()
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...
77
    {
78
        $testQuery = 'Test Query';
79
80
        $finderMock = $this->getFinderMock($testQuery, array(), 'createRawPaginatorAdapter');
81
        $repository = new Repository($finderMock);
82
        $repository->createRawPaginatorAdapter($testQuery);
83
    }
84
85
    /**
86
     * @param string $testQuery
87
     * @param mixed $testLimit
88
     * @param string $method
89
     *
90
     * @return \FOS\ElasticaBundle\Finder\TransformedFinder
91
     */
92
    private function getFinderMock($testQuery, $testLimit = null, $method = 'find')
93
    {
94
        $finderMock = $this->getMockBuilder('FOS\ElasticaBundle\Finder\TransformedFinder')
95
            ->disableOriginalConstructor()
96
            ->getMock();
97
        $finderMock->expects($this->once())
98
            ->method($method)
99
            ->with($this->equalTo($testQuery), $this->equalTo($testLimit));
100
101
        return $finderMock;
102
    }
103
}
104