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