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