| Conditions | 1 |
| Paths | 1 |
| Total Lines | 78 |
| Code Lines | 54 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 28 | public function testAdminCreate() |
||
| 29 | { |
||
| 30 | // with extra configuration disabled, adminCreate method SHOULD not modifiy the configuration |
||
| 31 | $subscriber = new ExtraConfigurationSubscriber( |
||
| 32 | false, |
||
| 33 | $this->mockEntityManager(), |
||
| 34 | new ApplicationConfiguration([], 'fr') |
||
| 35 | ); |
||
| 36 | $event = new AdminEvent(); |
||
| 37 | $event->setConfiguration([]); |
||
| 38 | $subscriber->adminCreate($event); |
||
| 39 | $this->assertEquals([], $event->getConfiguration()); |
||
| 40 | |||
| 41 | // with extra configuration enabled, adminCreate method SHOULD fill action configuration if it is empty |
||
| 42 | $subscriber = new ExtraConfigurationSubscriber( |
||
| 43 | true, |
||
| 44 | $this->mockEntityManager(), |
||
| 45 | new ApplicationConfiguration([], 'fr') |
||
| 46 | ); |
||
| 47 | $event = new AdminEvent(); |
||
| 48 | $event->setConfiguration([]); |
||
| 49 | $subscriber->adminCreate($event); |
||
| 50 | $this->assertEquals([ |
||
| 51 | 'actions' => [ |
||
| 52 | 'create' => [], |
||
| 53 | 'list' => [], |
||
| 54 | 'edit' => [], |
||
| 55 | 'delete' => [], |
||
| 56 | 'batch' => [], |
||
| 57 | ] |
||
| 58 | ], $event->getConfiguration()); |
||
| 59 | |||
| 60 | // adminCreate method SHOULD not modified actual configuration |
||
| 61 | $event = new AdminEvent(); |
||
| 62 | $event->setConfiguration([ |
||
| 63 | 'actions' => [ |
||
| 64 | 'myAction' => [] |
||
| 65 | ] |
||
| 66 | ]); |
||
| 67 | $subscriber->adminCreate($event); |
||
| 68 | $this->assertEquals([ |
||
| 69 | 'actions' => [ |
||
| 70 | 'myAction' => [] |
||
| 71 | ] |
||
| 72 | ], $event->getConfiguration()); |
||
| 73 | |||
| 74 | // adminCreate method SHOULD add batch for list actions if not defined |
||
| 75 | $event = new AdminEvent(); |
||
| 76 | $event->setConfiguration([ |
||
| 77 | 'actions' => [ |
||
| 78 | 'list' => [] |
||
| 79 | ] |
||
| 80 | ]); |
||
| 81 | $subscriber->adminCreate($event); |
||
| 82 | $this->assertEquals([ |
||
| 83 | 'actions' => [ |
||
| 84 | 'list' => [], |
||
| 85 | 'batch' => [], |
||
| 86 | ] |
||
| 87 | ], $event->getConfiguration()); |
||
| 88 | |||
| 89 | $event = new AdminEvent(); |
||
| 90 | $event->setConfiguration([ |
||
| 91 | 'actions' => [ |
||
| 92 | 'list' => [ |
||
| 93 | 'batch' => false |
||
| 94 | ] |
||
| 95 | ] |
||
| 96 | ]); |
||
| 97 | $subscriber->adminCreate($event); |
||
| 98 | $this->assertEquals([ |
||
| 99 | 'actions' => [ |
||
| 100 | 'list' => [ |
||
| 101 | 'batch' => false |
||
| 102 | ] |
||
| 103 | ] |
||
| 104 | ], $event->getConfiguration()); |
||
| 105 | } |
||
| 106 | } |
||
| 107 |