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