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