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