Conditions | 1 |
Paths | 1 |
Total Lines | 56 |
Code Lines | 45 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
33 | public function testGetFixedQueryBuilder($class, $alias, $id, $expectedId, $value) |
||
34 | { |
||
35 | $meta = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadataInfo') |
||
36 | ->disableOriginalConstructor() |
||
37 | ->getMock(); |
||
38 | $meta->expects($this->any()) |
||
39 | ->method('getIdentifierFieldNames') |
||
40 | ->willReturn(array($id)); |
||
41 | |||
42 | $mf = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadataFactory') |
||
43 | ->disableOriginalConstructor() |
||
44 | ->getMock(); |
||
45 | $mf->expects($this->any()) |
||
46 | ->method('getMetadataFor') |
||
47 | ->with($this->equalTo($class)) |
||
48 | ->willReturn($meta); |
||
49 | |||
50 | $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') |
||
51 | ->disableOriginalConstructor() |
||
52 | ->getMock(); |
||
53 | $em->expects($this->any()) |
||
54 | ->method('getMetadataFactory') |
||
55 | ->willReturn($mf); |
||
56 | |||
57 | $q = $this->getMock('PDOStatement'); |
||
58 | $q->expects($this->any()) |
||
59 | ->method('execute') |
||
60 | ->willReturn(array(array($id => $value))); |
||
61 | |||
62 | $qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder') |
||
63 | ->setConstructorArgs(array($em)) |
||
64 | ->getMock(); |
||
65 | $qb->expects($this->any()) |
||
66 | ->method('getEntityManager') |
||
67 | ->willReturn($em); |
||
68 | $qb->expects($this->any()) |
||
69 | ->method('getQuery') |
||
70 | ->willReturn($q); |
||
71 | $qb->expects($this->once()) |
||
72 | ->method('setParameter') |
||
73 | ->with($this->equalTo($expectedId), $this->equalTo(array($value))); |
||
74 | $qb->expects($this->once()) |
||
75 | ->method('getDQLPart') |
||
76 | ->with($this->equalTo('from')) |
||
77 | ->willReturn(array(new From($class, $alias))); |
||
78 | |||
79 | $pq = $this->getMockBuilder('Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery') |
||
80 | ->setConstructorArgs(array($qb)) |
||
81 | ->setMethods(array('a')) |
||
82 | ->getMock(); |
||
83 | |||
84 | |||
85 | /* Work */ |
||
86 | |||
87 | $pq->execute(); |
||
88 | } |
||
89 | } |
||
90 |