Conditions | 1 |
Paths | 1 |
Total Lines | 87 |
Code Lines | 72 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 2 |
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 |
||
46 | public function testGetFixedQueryBuilder($class, $alias, $id, $expectedId, $value, $identifierType) |
||
47 | { |
||
48 | $meta = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadataInfo') |
||
49 | ->disableOriginalConstructor() |
||
50 | ->getMock(); |
||
51 | $meta->expects($this->any()) |
||
52 | ->method('getIdentifierFieldNames') |
||
53 | ->willReturn(array($id)); |
||
54 | $meta->expects($this->any()) |
||
55 | ->method('getTypeOfField') |
||
56 | ->willReturn($identifierType); |
||
57 | |||
58 | $mf = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadataFactory') |
||
59 | ->disableOriginalConstructor() |
||
60 | ->getMock(); |
||
61 | $mf->expects($this->any()) |
||
62 | ->method('getMetadataFor') |
||
63 | ->with($this->equalTo($class)) |
||
64 | ->willReturn($meta); |
||
65 | |||
66 | $platform = $this->getMockBuilder('Doctrine\DBAL\Platforms\PostgreSqlPlatform') |
||
67 | ->disableOriginalConstructor() |
||
68 | ->getMock(); |
||
69 | |||
70 | $conn = $this->getMockBuilder('Doctrine\DBAL\Connection') |
||
71 | ->disableOriginalConstructor() |
||
72 | ->getMock(); |
||
73 | $conn->expects($this->any()) |
||
74 | ->method('getDatabasePlatform') |
||
75 | ->willReturn($platform); |
||
76 | |||
77 | $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') |
||
78 | ->disableOriginalConstructor() |
||
79 | ->getMock(); |
||
80 | $em->expects($this->any()) |
||
81 | ->method('getMetadataFactory') |
||
82 | ->willReturn($mf); |
||
83 | $em->expects($this->any()) |
||
84 | ->method('getConnection') |
||
85 | ->willReturn($conn); |
||
86 | |||
87 | $q = $this->getMock('PDOStatement'); |
||
88 | $q->expects($this->any()) |
||
89 | ->method('execute') |
||
90 | ->willReturn(array(array($id => $value))); |
||
91 | |||
92 | $qb = $this->getMockBuilder('Doctrine\ORM\QueryBuilder') |
||
93 | ->setConstructorArgs(array($em)) |
||
94 | ->getMock(); |
||
95 | $qb->expects($this->any()) |
||
96 | ->method('getEntityManager') |
||
97 | ->willReturn($em); |
||
98 | $qb->expects($this->any()) |
||
99 | ->method('getQuery') |
||
100 | ->willReturn($q); |
||
101 | $qb->expects($this->once()) |
||
102 | ->method('setParameter') |
||
103 | ->with($this->equalTo($expectedId), $this->equalTo(array($value))); |
||
104 | $qb->expects($this->any()) |
||
105 | ->method('getDQLPart') |
||
106 | ->will($this->returnCallBack(function ($part) use ($class, $alias) { |
||
107 | $parts = array( |
||
108 | 'from' => array(new From($class, $alias)), |
||
109 | 'orderBy' => array(new OrderBy('whatever', 'DESC')), |
||
110 | ); |
||
111 | |||
112 | return $parts[$part]; |
||
113 | })); |
||
114 | $qb->expects($this->once()) |
||
115 | ->method('addOrderBy') |
||
116 | ->with("$alias.$id", null); |
||
117 | $qb->expects($this->once()) |
||
118 | ->method('getRootEntities') |
||
119 | ->willReturn(array($class)); |
||
120 | $qb->expects($this->exactly(2)) |
||
121 | ->method('getRootAliases') |
||
122 | ->willReturn(array($alias)); |
||
123 | |||
124 | $pq = $this->getMockBuilder('Sonata\DoctrineORMAdminBundle\Datagrid\ProxyQuery') |
||
125 | ->setConstructorArgs(array($qb)) |
||
126 | ->setMethods(array('a')) |
||
127 | ->getMock(); |
||
128 | |||
129 | /* Work */ |
||
130 | |||
131 | $pq->execute(); |
||
132 | } |
||
133 | } |
||
134 |