Completed
Push — dev ( a1297d...02942d )
by Arnaud
03:36
created

DataProviderTest   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 62
Duplicated Lines 70.97 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 4
c 2
b 0
f 1
lcom 1
cbo 2
dl 44
loc 62
rs 10

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 BlueBear\AdminBundle\Tests\AdminBundle\DataProvider;
4
5
use LAG\AdminBundle\DataProvider\DataProvider;
6
use LAG\AdminBundle\Tests\Base;
7
use stdClass;
8
9
/**
10
 * Test the built-in data provider
11
 */
12
class DataProviderTest extends Base
13
{
14
    /**
15
     * Method save SHOULD be called on the entiy repository
16
     */
17
    public function testSave()
18
    {
19
        // repository save method SHOULD be called
20
        $repositoryMock = $this->mockEntityRepository();
21
        $repositoryMock
22
            ->expects($this->once())
23
            ->method('save');
24
25
        $dataProvider = new DataProvider($repositoryMock);
26
        $dataProvider->save(new stdClass());
27
    }
28
29
    /**
30
     * Method delete SHOULD be called on the entity repository
31
     */
32
    public function testDelete()
33
    {
34
        // entity manager delete method SHOULD be called
35
        $repositoryMock = $this->mockEntityRepository();
36
        $repositoryMock
37
            ->expects($this->once())
38
            ->method('delete');
39
40
        $dataProvider = new DataProvider($repositoryMock);
41
        $dataProvider->remove(new stdClass());
42
    }
43
44
    /**
45
     * Method find SHOULD be called on the entity repository
46
     */
47
    public function testFind()
48
    {
49
        // repository find method SHOULD be called
50
        $repositoryMock = $this->mockEntityRepository();
51
        $repositoryMock
52
            ->expects($this->once())
53
            ->method('find');
54
55
        $dataProvider = new DataProvider($repositoryMock);
56
        $dataProvider->find('unique_id');
57
    }
58
59
    /**
60
     * Method findBy SHOULD be called on the entity repository
61
     */
62
    public function testfindBy()
63
    {
64
        // repository findBy method SHOULD be called
65
        $repositoryMock = $this->mockEntityRepository();
66
        $repositoryMock
67
            ->expects($this->once())
68
            ->method('findBy');
69
70
        $dataProvider = new DataProvider($repositoryMock);
71
        $dataProvider->findBy([]);
72
    }
73
}
74