Conditions | 1 |
Paths | 1 |
Total Lines | 81 |
Code Lines | 64 |
Lines | 0 |
Ratio | 0 % |
Changes | 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 |
||
95 | public function testGetFixedQueryBuilder($class, $alias, $id, $expectedId, $value, $identifierType): void |
||
96 | { |
||
97 | $meta = $this->createMock(ClassMetadataInfo::class); |
||
98 | $meta->expects($this->any()) |
||
99 | ->method('getIdentifierFieldNames') |
||
100 | ->willReturn([$id]); |
||
101 | $meta->expects($this->any()) |
||
102 | ->method('getTypeOfField') |
||
103 | ->willReturn($identifierType); |
||
104 | |||
105 | $mf = $this->createMock(ClassMetadataFactory::class); |
||
106 | $mf->expects($this->any()) |
||
107 | ->method('getMetadataFor') |
||
108 | ->with($this->equalTo($class)) |
||
109 | ->willReturn($meta); |
||
110 | |||
111 | $platform = $this->createMock(PostgreSqlPlatform::class); |
||
112 | |||
113 | $conn = $this->createMock(Connection::class); |
||
114 | $conn->expects($this->any()) |
||
115 | ->method('getDatabasePlatform') |
||
116 | ->willReturn($platform); |
||
117 | |||
118 | $em = $this->createMock(EntityManager::class); |
||
119 | $em->expects($this->any()) |
||
120 | ->method('getMetadataFactory') |
||
121 | ->willReturn($mf); |
||
122 | $em->expects($this->any()) |
||
123 | ->method('getConnection') |
||
124 | ->willReturn($conn); |
||
125 | |||
126 | // NEXT MAJOR: Replace this when dropping PHP < 5.6 |
||
127 | // $q = $this->createMock('PDOStatement'); |
||
128 | $q = $this->getMockBuilder('stdClass') |
||
129 | ->setMethods(['execute']) |
||
130 | ->getMock(); |
||
131 | $q->expects($this->any()) |
||
132 | ->method('execute') |
||
133 | ->willReturn([[$id => $value]]); |
||
134 | |||
135 | $qb = $this->getMockBuilder(QueryBuilder::class) |
||
136 | ->setConstructorArgs([$em]) |
||
137 | ->getMock(); |
||
138 | $qb->expects($this->any()) |
||
139 | ->method('getEntityManager') |
||
140 | ->willReturn($em); |
||
141 | $qb->expects($this->any()) |
||
142 | ->method('getQuery') |
||
143 | ->willReturn($q); |
||
144 | $qb->expects($this->once()) |
||
145 | ->method('setParameter') |
||
146 | ->with($this->equalTo($expectedId), $this->equalTo([$value])); |
||
147 | $qb->expects($this->any()) |
||
148 | ->method('getDQLPart') |
||
149 | ->will($this->returnCallBack(function ($part) use ($class, $alias) { |
||
150 | $parts = [ |
||
151 | 'from' => [new From($class, $alias)], |
||
152 | 'orderBy' => [new OrderBy('whatever', 'DESC')], |
||
153 | ]; |
||
154 | |||
155 | return $parts[$part]; |
||
156 | })); |
||
157 | $qb->expects($this->once()) |
||
158 | ->method('addOrderBy') |
||
159 | ->with("$alias.$id", null); |
||
160 | $qb->expects($this->once()) |
||
161 | ->method('getRootEntities') |
||
162 | ->willReturn([$class]); |
||
163 | $qb->expects($this->exactly(2)) |
||
164 | ->method('getRootAliases') |
||
165 | ->willReturn([$alias]); |
||
166 | |||
167 | $pq = $this->getMockBuilder(ProxyQuery::class) |
||
168 | ->setConstructorArgs([$qb]) |
||
169 | ->setMethods(['a']) |
||
170 | ->getMock(); |
||
171 | |||
172 | /* Work */ |
||
173 | |||
174 | $pq->execute(); |
||
175 | } |
||
176 | |||
251 |