| Conditions | 1 |
| Paths | 1 |
| Total Lines | 68 |
| 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 |
||
| 134 | public function testInjectAdmin() |
||
| 135 | { |
||
| 136 | $request = new Request(); |
||
| 137 | $adminConfiguration = [ |
||
| 138 | 'my_admin' => [ |
||
| 139 | 'entity' => 'TestClass' |
||
| 140 | ], |
||
| 141 | ]; |
||
| 142 | $eventDispatcher = $this->getMockWithoutConstructor(EventDispatcher::class); |
||
| 143 | $eventDispatcher |
||
| 144 | ->expects($this->once()) |
||
| 145 | ->method('dispatch') |
||
| 146 | ->willReturnCallback(function($name, $event) { |
||
| 147 | $this->assertEquals(AdminEvents::ADMIN_INJECTED, $name); |
||
| 148 | $this->assertInstanceOf(AdminInjectedEvent::class, $event); |
||
| 149 | }) |
||
| 150 | ; |
||
| 151 | $configurationFactory = $this->getMockWithoutConstructor(ConfigurationFactory::class); |
||
| 152 | |||
| 153 | $actionFactory = $this->getMockWithoutConstructor(ActionFactory::class); |
||
| 154 | |||
| 155 | $messageHandler = $this->getMockWithoutConstructor(MessageHandlerInterface::class); |
||
| 156 | |||
| 157 | $registry = $this->getMockWithoutConstructor(Registry::class); |
||
| 158 | |||
| 159 | $dataProviderFactory = $this->getMockWithoutConstructor(DataProviderFactory::class); |
||
| 160 | |||
| 161 | $admin = $this->getMockWithoutConstructor(AdminInterface::class); |
||
| 162 | |||
| 163 | $requestHandler = $this->getMockWithoutConstructor(RequestHandler::class); |
||
| 164 | $requestHandler |
||
| 165 | ->expects($this->once()) |
||
| 166 | ->method('handle') |
||
| 167 | ->with($request) |
||
| 168 | ->willReturn($admin) |
||
| 169 | ; |
||
| 170 | |||
| 171 | $authorizationChecker = $this->getMockWithoutConstructor(AuthorizationCheckerInterface::class); |
||
| 172 | $tokenStorage = $this->getMockWithoutConstructor(TokenStorageInterface::class); |
||
| 173 | $actionRegistry = $this->getMockWithoutConstructor(\LAG\AdminBundle\Action\Registry\Registry::class); |
||
| 174 | $viewFactory = $this->getMockWithoutConstructor(ViewFactory::class); |
||
| 175 | $applicationConfigurationStorage = $this->getMockWithoutConstructor(ApplicationConfigurationStorage::class); |
||
| 176 | |||
| 177 | $factory = new AdminFactory( |
||
| 178 | $adminConfiguration, |
||
| 179 | $eventDispatcher, |
||
| 180 | $messageHandler, |
||
| 181 | $registry, |
||
| 182 | $actionRegistry, |
||
| 183 | $actionFactory, |
||
| 184 | $configurationFactory, |
||
| 185 | $dataProviderFactory, |
||
| 186 | $viewFactory, |
||
| 187 | $requestHandler, |
||
| 188 | $authorizationChecker, |
||
| 189 | $tokenStorage, |
||
| 190 | $applicationConfigurationStorage |
||
| 191 | ); |
||
| 192 | |||
| 193 | $controller = $this->getMockWithoutConstructor(ListAction::class); |
||
| 194 | |||
| 195 | // injectAdmin should inject an Admin in Twig global parameters and dispatch an event |
||
| 196 | $factory->injectAdmin($controller, $request); |
||
| 197 | |||
| 198 | // with a non AdminAware controller, it should do nothing |
||
| 199 | $controller = $this->getMockWithoutConstructor(Controller::class); |
||
| 200 | $factory->injectAdmin($controller, $request); |
||
| 201 | } |
||
| 202 | } |
||
| 203 |