Conditions | 1 |
Paths | 1 |
Total Lines | 98 |
Code Lines | 75 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
Bugs | 1 | Features | 3 |
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 |
||
34 | public function testApplyBusinessUnitAcl() |
||
35 | { |
||
36 | $actualElements = [ |
||
37 | new SearchElement(1), |
||
38 | new SearchElement(2), |
||
39 | new SearchElement(3) |
||
40 | ]; |
||
41 | $expectedIds = [1, 2]; |
||
42 | |||
43 | $query = $this |
||
44 | ->getMockBuilder('Oro\Bundle\SearchBundle\Query\Query') |
||
45 | ->setMethods(['getElements']) |
||
46 | ->disableOriginalConstructor() |
||
47 | ->getMock(); |
||
48 | |||
49 | $query->expects($this->once()) |
||
50 | ->method('getElements') |
||
51 | ->will($this->returnValue($actualElements)); |
||
52 | |||
53 | $this->businessAclProvider |
||
54 | ->expects($this->exactly(1)) |
||
55 | ->method('getBusinessUnitIds') |
||
56 | ->will($this->returnValue($expectedIds)); |
||
57 | |||
58 | $indexer = $this->getMockBuilder('Oro\Bundle\SearchBundle\Engine\Indexer') |
||
59 | ->setMethods(['query', 'select', 'simpleSearch']) |
||
60 | ->disableOriginalConstructor()->getMock(); |
||
61 | |||
62 | $indexer->expects($this->once()) |
||
63 | ->method('simpleSearch') |
||
64 | ->will($this->returnValue($query)); |
||
65 | |||
66 | $expr = $this->getMockBuilder('Doctrine\ORM\Query\Expr') |
||
67 | ->setMethods(['in']) |
||
68 | ->disableOriginalConstructor() |
||
69 | ->getMock(); |
||
70 | |||
71 | $queryBuilder = $this->getMockBuilder('Doctrine\ORM\QueryBuilder') |
||
72 | ->setMethods(['getQuery', 'getResult', 'where', 'expr']) |
||
73 | ->disableOriginalConstructor() |
||
74 | ->getMock(); |
||
75 | |||
76 | $queryBuilder |
||
77 | ->expects($this->exactly(1)) |
||
78 | ->method('expr') |
||
79 | ->will($this->returnValue($expr)); |
||
80 | |||
81 | $queryBuilder->expects($this->any()) |
||
82 | ->method('getQuery') |
||
83 | ->will($this->returnValue($queryBuilder)); |
||
84 | |||
85 | $queryBuilder->expects($this->any()) |
||
86 | ->method('getResult') |
||
87 | ->will($this->returnValue([])); |
||
88 | |||
89 | $entityRepository = $this |
||
90 | ->getMockBuilder('Doctrine\ORM\EntityRepository') |
||
91 | ->setMethods(['createQueryBuilder']) |
||
92 | ->disableOriginalConstructor() |
||
93 | ->getMock(); |
||
94 | |||
95 | $entityRepository->expects($this->any()) |
||
96 | ->method('createQueryBuilder') |
||
97 | ->will($this->returnValue($queryBuilder)); |
||
98 | |||
99 | $metadata = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadata') |
||
100 | ->disableOriginalConstructor()->getMock(); |
||
101 | $metadata->expects($this->once())->method('getSingleIdentifierFieldName') |
||
102 | ->will($this->returnValue(self::TEST_ID_FIELD)); |
||
103 | |||
104 | $metadataFactory = $this->getMockBuilder('Doctrine\ORM\Mapping\ClassMetadataFactory') |
||
105 | ->disableOriginalConstructor()->getMock(); |
||
106 | $metadataFactory->expects($this->once()) |
||
107 | ->method('getMetadataFor')->with(self::TEST_ENTITY_NAME) |
||
108 | ->will($this->returnValue($metadata)); |
||
109 | |||
110 | $em = $this->getMockBuilder('Doctrine\ORM\EntityManager') |
||
111 | ->disableOriginalConstructor()->getMock(); |
||
112 | $em->expects($this->once())->method('getRepository') |
||
113 | ->will($this->returnValue($entityRepository)); |
||
114 | $em->expects($this->once())->method('getMetadataFactory') |
||
115 | ->will($this->returnValue($metadataFactory)); |
||
116 | |||
117 | $managerRegistry = $this->getMock('Doctrine\Common\Persistence\ManagerRegistry'); |
||
118 | $managerRegistry->expects($this->once())->method('getManagerForClass')->with(self::TEST_ENTITY_NAME) |
||
119 | ->will($this->returnValue($em)); |
||
120 | |||
121 | $this->handler->initSearchIndexer($indexer, [self::TEST_ENTITY_NAME => ['alias' => self::TEST_ENTITY_ALIAS]]); |
||
122 | $this->handler->initDoctrinePropertiesByManagerRegistry($managerRegistry); |
||
123 | |||
124 | //the main filter check |
||
125 | $expr |
||
126 | ->expects($this->once()) |
||
127 | ->method('in') |
||
128 | ->with('e.'.self::TEST_ID_FIELD, $expectedIds); |
||
129 | |||
130 | $this->handler->search('query', 0, 10); |
||
131 | } |
||
132 | } |
||
133 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..